1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
7 
8 #include "base/macros.h"
9 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
10 
11 // A minimalistic and configurable ToolbarActionViewController for use in
12 // testing.
13 class TestToolbarActionViewController : public ToolbarActionViewController {
14  public:
15   explicit TestToolbarActionViewController(const std::string& id);
16   ~TestToolbarActionViewController() override;
17 
18   // ToolbarActionViewController:
19   std::string GetId() const override;
20   void SetDelegate(ToolbarActionViewDelegate* delegate) override;
21   gfx::Image GetIcon(content::WebContents* web_contents,
22                      const gfx::Size& size) override;
23   base::string16 GetActionName() const override;
24   base::string16 GetAccessibleName(content::WebContents* web_contents)
25       const override;
26   base::string16 GetTooltip(content::WebContents* web_contents)
27       const override;
28   bool IsEnabled(content::WebContents* web_contents) const override;
29   bool HasPopup(content::WebContents* web_contents) const override;
30   bool IsShowingPopup() const override;
31   void HidePopup() override;
32   gfx::NativeView GetPopupNativeView() override;
33   ui::MenuModel* GetContextMenu() override;
34   bool ExecuteAction(bool by_user, InvocationSource source) override;
35   void UpdateState() override;
36   bool DisabledClickOpensMenu() const override;
37   PageInteractionStatus GetPageInteractionStatus(
38       content::WebContents* web_contents) const override;
39 
40   // Instruct the controller to fake showing a popup.
41   void ShowPopup(bool by_user);
42 
43   // Configure the test controller. These also call UpdateDelegate().
44   void SetActionName(const base::string16& name);
45   void SetAccessibleName(const base::string16& name);
46   void SetTooltip(const base::string16& tooltip);
47   void SetEnabled(bool is_enabled);
48   void SetDisabledClickOpensMenu(bool disabled_click_opens_menu);
49 
execute_action_count()50   int execute_action_count() const { return execute_action_count_; }
51 
52  private:
53   // Updates the delegate, if one exists.
54   void UpdateDelegate();
55 
56   // The id of the controller.
57   std::string id_;
58 
59   // The delegate of the controller, if one exists.
60   ToolbarActionViewDelegate* delegate_ = nullptr;
61 
62   // Action name for the controller.
63   base::string16 action_name_;
64 
65   // The optional accessible name and tooltip; by default these are empty.
66   base::string16 accessible_name_;
67   base::string16 tooltip_;
68 
69   // Whether or not the action is enabled.
70   bool is_enabled_ = true;
71 
72   // Whether or not a click on a disabled action should open the context menu.
73   bool disabled_click_opens_menu_ = false;
74 
75   // The number of times the action would have been executed.
76   int execute_action_count_ = 0;
77 
78   // True if a popup is (supposedly) currently showing.
79   bool popup_showing_ = false;
80 
81   DISALLOW_COPY_AND_ASSIGN(TestToolbarActionViewController);
82 };
83 
84 #endif  // CHROME_BROWSER_UI_TOOLBAR_TEST_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
85