| 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 <memory> | 5 #include <memory> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "chrome/browser/extensions/browser_action_test_util.h" | 8 #include "chrome/browser/extensions/browser_action_test_util.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" | 10 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" |
| 11 #include "chrome/browser/ui/toolbar/mock_component_toolbar_actions_factory.h" | 11 #include "chrome/browser/ui/toolbar/mock_component_toolbar_actions_factory.h" |
| 12 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" | 12 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" |
| 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
| 14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 14 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.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 | 17 |
| 18 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { | 18 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { |
| 19 protected: | 19 protected: |
| 20 ComponentToolbarActionsBrowserTest() {} | 20 ComponentToolbarActionsBrowserTest() {} |
| 21 ~ComponentToolbarActionsBrowserTest() override {} | 21 ~ComponentToolbarActionsBrowserTest() override {} |
| 22 | 22 |
| 23 void SetUpCommandLine(base::CommandLine* command_line) override { | 23 void SetUpOnMainThread() override { |
| 24 InProcessBrowserTest::SetUpCommandLine(command_line); | 24 InProcessBrowserTest::SetUpOnMainThread(); |
| 25 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( | 25 |
| 26 extensions::FeatureSwitch::extension_action_redesign(), true)); | 26 // Replace the actions factory with a mock one. |
| 27 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory( | 27 toolbar_model_ = ToolbarActionsModel::Get(browser()->profile()); |
| 28 browser())); | 28 toolbar_model_->SetMockActionsFactoryForTest( |
| 29 base::MakeUnique<MockComponentToolbarActionsFactory>( |
| 30 browser()->profile())); |
| 29 } | 31 } |
| 30 | 32 |
| 31 MockComponentToolbarActionsFactory* mock_factory() { | 33 protected: |
| 32 return mock_actions_factory_.get(); | 34 ToolbarActionsModel* toolbar_model_ = nullptr; |
| 33 } | |
| 34 | 35 |
| 35 private: | 36 private: |
| 36 std::unique_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; | |
| 37 std::unique_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_; | |
| 38 | |
| 39 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest); | 37 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest); |
| 40 }; | 38 }; |
| 41 | 39 |
| 42 // Test that Component Toolbar Actions appear in the browser actions container | 40 // Test that Component Toolbar Actions appear in the browser actions container |
| 43 // and can receive click events properly. | 41 // and can receive click events properly. |
| 44 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, | 42 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, |
| 45 ComponentToolbarActionsShowUpAndRespondToClicks) { | 43 ComponentToolbarActionsShowUpAndRespondToClicks) { |
| 46 BrowserActionTestUtil browser_actions_bar(browser()); | 44 BrowserActionTestUtil browser_actions_bar(browser()); |
| 45 toolbar_model_->AddComponentAction( |
| 46 MockComponentToolbarActionsFactory::kActionIdForTesting); |
| 47 | 47 |
| 48 // There should be only one component action view. | 48 // There should be only one component action view. |
| 49 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions()); | 49 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions()); |
| 50 | 50 |
| 51 // Even though the method says "ExtensionId", this actually refers to any id | 51 // Even though the method says "ExtensionId", this actually refers to any id |
| 52 // for the action. | 52 // for the action. |
| 53 EXPECT_EQ(MockComponentToolbarActionsFactory::kActionIdForTesting, | 53 EXPECT_EQ(MockComponentToolbarActionsFactory::kActionIdForTesting, |
| 54 browser_actions_bar.GetExtensionId(0)); | 54 browser_actions_bar.GetExtensionId(0)); |
| 55 | 55 |
| 56 // There should only have been one created component action. | |
| 57 EXPECT_EQ(1u, ComponentToolbarActionsFactory::GetInstance() | |
| 58 ->GetInitialComponentIds(browser()->profile()) | |
| 59 .size()); | |
| 60 | |
| 61 const std::vector<ToolbarActionViewController*>& actions = | 56 const std::vector<ToolbarActionViewController*>& actions = |
| 62 browser_actions_bar.GetToolbarActionsBar()->GetActions(); | 57 browser_actions_bar.GetToolbarActionsBar()->GetActions(); |
| 63 TestToolbarActionViewController* mock_component_action = | 58 TestToolbarActionViewController* mock_component_action = |
| 64 static_cast<TestToolbarActionViewController* const>(actions[0]); | 59 static_cast<TestToolbarActionViewController* const>(actions[0]); |
| 65 ASSERT_TRUE(mock_component_action); | 60 ASSERT_TRUE(mock_component_action); |
| 66 | 61 |
| 67 // Test that clicking on the component action works. | 62 // Test that clicking on the component action works. |
| 68 EXPECT_EQ(0, mock_component_action->execute_action_count()); | 63 EXPECT_EQ(0, mock_component_action->execute_action_count()); |
| 69 browser_actions_bar.Press(0); | 64 browser_actions_bar.Press(0); |
| 70 EXPECT_EQ(1, mock_component_action->execute_action_count()); | 65 EXPECT_EQ(1, mock_component_action->execute_action_count()); |
| 71 } | 66 } |
| OLD | NEW |