Chromium Code Reviews| 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/extensions/browser_action_test_util.h" | |
| 8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 10 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 11 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 12 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | |
| 13 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h" | |
| 14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "extensions/common/feature_switch.h" | 13 #include "extensions/common/feature_switch.h" |
| 17 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/image/image.h" | |
| 17 #include "ui/gfx/image/image_skia.h" | |
|
Finnur
2015/01/29 09:42:54
nit: Is this required?
Devlin
2015/01/29 18:18:37
Yeah. I think before it was transitively included,
| |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 | 20 |
| 22 const char kMockId[] = "mock_action"; | 21 const char kMockId[] = "mock_action"; |
| 23 | 22 |
| 24 class MockComponentAction : public ToolbarActionViewController { | 23 class MockComponentAction : public ToolbarActionViewController { |
| 25 public: | 24 public: |
| 26 MockComponentAction() : click_count_(0u), id_(kMockId) {} | 25 MockComponentAction() : click_count_(0u), id_(kMockId) {} |
| 27 ~MockComponentAction() override {} | 26 ~MockComponentAction() override {} |
| 28 | 27 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 class MockComponentToolbarActionsFactory | 78 class MockComponentToolbarActionsFactory |
| 80 : public ComponentToolbarActionsFactory { | 79 : public ComponentToolbarActionsFactory { |
| 81 public: | 80 public: |
| 82 MockComponentToolbarActionsFactory(); | 81 MockComponentToolbarActionsFactory(); |
| 83 virtual ~MockComponentToolbarActionsFactory(); | 82 virtual ~MockComponentToolbarActionsFactory(); |
| 84 | 83 |
| 85 // ComponentToolbarActionsFactory: | 84 // ComponentToolbarActionsFactory: |
| 86 ScopedVector<ToolbarActionViewController> GetComponentToolbarActions() | 85 ScopedVector<ToolbarActionViewController> GetComponentToolbarActions() |
| 87 override; | 86 override; |
| 88 | 87 |
| 88 const std::vector<MockComponentAction*>& weak_actions() const { | |
| 89 return weak_actions_; | |
| 90 } | |
| 91 | |
| 89 private: | 92 private: |
| 93 // A (weak) set of all created actions. | |
| 94 std::vector<MockComponentAction*> weak_actions_; | |
| 95 | |
| 90 DISALLOW_COPY_AND_ASSIGN(MockComponentToolbarActionsFactory); | 96 DISALLOW_COPY_AND_ASSIGN(MockComponentToolbarActionsFactory); |
| 91 }; | 97 }; |
| 92 | 98 |
| 93 MockComponentToolbarActionsFactory::MockComponentToolbarActionsFactory() { | 99 MockComponentToolbarActionsFactory::MockComponentToolbarActionsFactory() { |
| 94 ComponentToolbarActionsFactory::SetTestingFactory(this); | 100 ComponentToolbarActionsFactory::SetTestingFactory(this); |
| 95 } | 101 } |
| 96 | 102 |
| 97 MockComponentToolbarActionsFactory::~MockComponentToolbarActionsFactory() { | 103 MockComponentToolbarActionsFactory::~MockComponentToolbarActionsFactory() { |
| 98 ComponentToolbarActionsFactory::SetTestingFactory(nullptr); | 104 ComponentToolbarActionsFactory::SetTestingFactory(nullptr); |
| 99 } | 105 } |
| 100 | 106 |
| 101 ScopedVector<ToolbarActionViewController> | 107 ScopedVector<ToolbarActionViewController> |
| 102 MockComponentToolbarActionsFactory::GetComponentToolbarActions() { | 108 MockComponentToolbarActionsFactory::GetComponentToolbarActions() { |
| 103 ScopedVector<ToolbarActionViewController> component_actions; | 109 ScopedVector<ToolbarActionViewController> component_actions; |
| 104 component_actions.push_back(new MockComponentAction()); | 110 MockComponentAction* action = new MockComponentAction(); |
| 111 component_actions.push_back(action); | |
| 112 weak_actions_.push_back(action); | |
| 105 return component_actions.Pass(); | 113 return component_actions.Pass(); |
| 106 } | 114 } |
| 107 | 115 |
| 108 } // namespace | 116 } // namespace |
| 109 | 117 |
| 110 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { | 118 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { |
| 111 protected: | 119 protected: |
| 112 ComponentToolbarActionsBrowserTest() {} | 120 ComponentToolbarActionsBrowserTest() {} |
| 113 ~ComponentToolbarActionsBrowserTest() override {} | 121 ~ComponentToolbarActionsBrowserTest() override {} |
| 114 | 122 |
| 115 void SetUpCommandLine(base::CommandLine* command_line) override { | 123 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 116 InProcessBrowserTest::SetUpCommandLine(command_line); | 124 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 117 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( | 125 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( |
| 118 extensions::FeatureSwitch::extension_action_redesign(), true)); | 126 extensions::FeatureSwitch::extension_action_redesign(), true)); |
| 119 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory()); | 127 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory()); |
| 120 } | 128 } |
| 121 | 129 |
| 130 MockComponentToolbarActionsFactory* mock_factory() { | |
| 131 return mock_actions_factory_.get(); | |
| 132 } | |
| 133 | |
| 122 private: | 134 private: |
| 123 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; | 135 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; |
| 124 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_; | 136 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_; |
| 125 | 137 |
| 126 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest); | 138 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest); |
| 127 }; | 139 }; |
| 128 | 140 |
| 129 // Test that Component Toolbar Actions appear in the browser actions container | 141 // Test that Component Toolbar Actions appear in the browser actions container |
| 130 // and can receive click events properly. | 142 // and can receive click events properly. |
| 131 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, |
| 132 ComponentToolbarActionsShowUpAndRespondToClicks) { | 144 ComponentToolbarActionsShowUpAndRespondToClicks) { |
| 133 BrowserActionsContainer* browser_actions_container = | 145 BrowserActionTestUtil browser_actions_bar(browser()); |
| 134 BrowserView::GetBrowserViewForBrowser(browser()) | |
| 135 ->toolbar()->browser_actions(); | |
| 136 | 146 |
| 137 // There should be only one component action view. | 147 // There should be only one component action view. |
| 138 ASSERT_EQ(1u, browser_actions_container->num_toolbar_actions()); | 148 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions()); |
| 139 | 149 |
| 140 ToolbarActionView* view = | 150 // Even though the method says "ExtensionId", this actually refers to any id |
| 141 browser_actions_container->GetToolbarActionViewAt(0u); | 151 // for the action. |
| 142 ASSERT_EQ(kMockId, view->view_controller()->GetId()); | 152 EXPECT_EQ(kMockId, browser_actions_bar.GetExtensionId(0)); |
| 143 MockComponentAction* mock_component_action = | 153 |
| 144 static_cast<MockComponentAction*>(view->view_controller()); | 154 // There should only have been one created component action. |
| 155 const std::vector<MockComponentAction*> weak_actions = | |
| 156 mock_factory()->weak_actions(); | |
| 157 ASSERT_EQ(1u, weak_actions.size()); | |
| 158 MockComponentAction* mock_component_action = weak_actions[0]; | |
| 159 ASSERT_TRUE(mock_component_action); | |
| 145 | 160 |
| 146 // Test that clicking on the component action works. | 161 // Test that clicking on the component action works. |
| 147 EXPECT_EQ(0u, mock_component_action->click_count()); | 162 EXPECT_EQ(0u, mock_component_action->click_count()); |
| 148 view->Activate(); | 163 browser_actions_bar.Press(0); |
| 149 EXPECT_EQ(1u, mock_component_action->click_count()); | 164 EXPECT_EQ(1u, mock_component_action->click_count()); |
| 150 } | 165 } |
| OLD | NEW |