OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/macros.h" | 5 #include "base/macros.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
11 #include "chrome/browser/ui/views/frame/browser_view.h" | 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" | 12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
16 #include "extensions/common/feature_switch.h" | 16 #include "extensions/common/feature_switch.h" |
17 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kMockId[] = "mock_action"; | 22 const char kMockId[] = "mock_action"; |
23 | 23 |
24 class MockComponentAction : public ToolbarActionViewController { | 24 class MockComponentAction : public ToolbarActionViewController { |
25 public: | 25 public: |
26 MockComponentAction() : click_count_(0u), id_(kMockId) {} | 26 MockComponentAction() : click_count_(0u), id_(kMockId) {} |
27 virtual ~MockComponentAction() {} | 27 ~MockComponentAction() override {} |
28 | 28 |
29 // ToolbarActionButtonController: | 29 // ToolbarActionButtonController: |
30 virtual const std::string& GetId() const override { return id_; } | 30 const std::string& GetId() const override { return id_; } |
31 virtual void SetDelegate(ToolbarActionViewDelegate* delegate) override {} | 31 void SetDelegate(ToolbarActionViewDelegate* delegate) override {} |
32 virtual gfx::Image GetIcon(content::WebContents* web_contents) override { | 32 gfx::Image GetIcon(content::WebContents* web_contents) override { |
33 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 33 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
34 IDR_BROWSER_ACTION); | 34 IDR_BROWSER_ACTION); |
35 } | 35 } |
36 virtual gfx::ImageSkia GetIconWithBadge() override { | 36 gfx::ImageSkia GetIconWithBadge() override { |
37 return *GetIcon(nullptr).ToImageSkia(); | 37 return *GetIcon(nullptr).ToImageSkia(); |
38 } | 38 } |
39 virtual base::string16 GetAccessibleName(content::WebContents* web_contents) | 39 base::string16 GetAccessibleName( |
40 const override { | 40 content::WebContents* web_contents) const override { |
41 return base::ASCIIToUTF16("Component Action"); | 41 return base::ASCIIToUTF16("Component Action"); |
42 } | 42 } |
43 virtual base::string16 GetTooltip(content::WebContents* web_contents) | 43 base::string16 GetTooltip(content::WebContents* web_contents) const override { |
44 const override { | |
45 return GetAccessibleName(web_contents); | 44 return GetAccessibleName(web_contents); |
46 } | 45 } |
47 virtual bool IsEnabled(content::WebContents* web_contents) const override { | 46 bool IsEnabled(content::WebContents* web_contents) const override { |
48 return true; | 47 return true; |
49 } | 48 } |
50 virtual bool HasPopup(content::WebContents* web_contents) const override { | 49 bool HasPopup(content::WebContents* web_contents) const override { |
51 return true; | 50 return true; |
52 } | 51 } |
53 virtual void HidePopup() override {} | 52 void HidePopup() override {} |
54 virtual gfx::NativeView GetPopupNativeView() override { return nullptr; } | 53 gfx::NativeView GetPopupNativeView() override { return nullptr; } |
55 virtual bool CanDrag() const override { return false; } | 54 bool CanDrag() const override { return false; } |
56 virtual bool IsMenuRunning() const override { return false; } | 55 bool IsMenuRunning() const override { return false; } |
57 virtual bool ExecuteAction(bool by_user) override { | 56 bool ExecuteAction(bool by_user) override { |
58 ++click_count_; | 57 ++click_count_; |
59 return false; | 58 return false; |
60 } | 59 } |
61 | 60 |
62 size_t click_count() const { return click_count_; } | 61 size_t click_count() const { return click_count_; } |
63 | 62 |
64 private: | 63 private: |
65 size_t click_count_; | 64 size_t click_count_; |
66 std::string id_; | 65 std::string id_; |
67 | 66 |
68 DISALLOW_COPY_AND_ASSIGN(MockComponentAction); | 67 DISALLOW_COPY_AND_ASSIGN(MockComponentAction); |
69 }; | 68 }; |
70 | 69 |
71 class MockComponentToolbarActionsFactory | 70 class MockComponentToolbarActionsFactory |
72 : public ComponentToolbarActionsFactory { | 71 : public ComponentToolbarActionsFactory { |
73 public: | 72 public: |
74 MockComponentToolbarActionsFactory(); | 73 MockComponentToolbarActionsFactory(); |
75 virtual ~MockComponentToolbarActionsFactory(); | 74 virtual ~MockComponentToolbarActionsFactory(); |
76 | 75 |
77 // ComponentToolbarActionsFactory: | 76 // ComponentToolbarActionsFactory: |
78 virtual ScopedVector<ToolbarActionViewController> | 77 ScopedVector<ToolbarActionViewController> GetComponentToolbarActions() |
79 GetComponentToolbarActions() override; | 78 override; |
80 | 79 |
81 private: | 80 private: |
82 DISALLOW_COPY_AND_ASSIGN(MockComponentToolbarActionsFactory); | 81 DISALLOW_COPY_AND_ASSIGN(MockComponentToolbarActionsFactory); |
83 }; | 82 }; |
84 | 83 |
85 MockComponentToolbarActionsFactory::MockComponentToolbarActionsFactory() { | 84 MockComponentToolbarActionsFactory::MockComponentToolbarActionsFactory() { |
86 ComponentToolbarActionsFactory::SetTestingFactory(this); | 85 ComponentToolbarActionsFactory::SetTestingFactory(this); |
87 } | 86 } |
88 | 87 |
89 MockComponentToolbarActionsFactory::~MockComponentToolbarActionsFactory() { | 88 MockComponentToolbarActionsFactory::~MockComponentToolbarActionsFactory() { |
90 ComponentToolbarActionsFactory::SetTestingFactory(nullptr); | 89 ComponentToolbarActionsFactory::SetTestingFactory(nullptr); |
91 } | 90 } |
92 | 91 |
93 ScopedVector<ToolbarActionViewController> | 92 ScopedVector<ToolbarActionViewController> |
94 MockComponentToolbarActionsFactory::GetComponentToolbarActions() { | 93 MockComponentToolbarActionsFactory::GetComponentToolbarActions() { |
95 ScopedVector<ToolbarActionViewController> component_actions; | 94 ScopedVector<ToolbarActionViewController> component_actions; |
96 component_actions.push_back(new MockComponentAction()); | 95 component_actions.push_back(new MockComponentAction()); |
97 return component_actions.Pass(); | 96 return component_actions.Pass(); |
98 } | 97 } |
99 | 98 |
100 } // namespace | 99 } // namespace |
101 | 100 |
102 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { | 101 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { |
103 protected: | 102 protected: |
104 ComponentToolbarActionsBrowserTest() {} | 103 ComponentToolbarActionsBrowserTest() {} |
105 virtual ~ComponentToolbarActionsBrowserTest() {} | 104 ~ComponentToolbarActionsBrowserTest() override {} |
106 | 105 |
107 virtual void SetUpCommandLine(base::CommandLine* command_line) override { | 106 void SetUpCommandLine(base::CommandLine* command_line) override { |
108 InProcessBrowserTest::SetUpCommandLine(command_line); | 107 InProcessBrowserTest::SetUpCommandLine(command_line); |
109 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( | 108 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( |
110 extensions::FeatureSwitch::extension_action_redesign(), true)); | 109 extensions::FeatureSwitch::extension_action_redesign(), true)); |
111 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory()); | 110 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory()); |
112 } | 111 } |
113 | 112 |
114 private: | 113 private: |
115 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; | 114 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; |
116 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_; | 115 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_; |
117 | 116 |
(...skipping 15 matching lines...) Expand all Loading... |
133 browser_actions_container->GetBrowserActionViewAt(0u); | 132 browser_actions_container->GetBrowserActionViewAt(0u); |
134 ASSERT_EQ(kMockId, view->view_controller()->GetId()); | 133 ASSERT_EQ(kMockId, view->view_controller()->GetId()); |
135 MockComponentAction* mock_component_action = | 134 MockComponentAction* mock_component_action = |
136 static_cast<MockComponentAction*>(view->view_controller()); | 135 static_cast<MockComponentAction*>(view->view_controller()); |
137 | 136 |
138 // Test that clicking on the component action works. | 137 // Test that clicking on the component action works. |
139 EXPECT_EQ(0u, mock_component_action->click_count()); | 138 EXPECT_EQ(0u, mock_component_action->click_count()); |
140 view->Activate(); | 139 view->Activate(); |
141 EXPECT_EQ(1u, mock_component_action->click_count()); | 140 EXPECT_EQ(1u, mock_component_action->click_count()); |
142 } | 141 } |
OLD | NEW |