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 "chrome/browser/extensions/browser_action_test_util.h" | 7 #include "chrome/browser/extensions/browser_action_test_util.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/mock_component_toolbar_actions_factory.h" | |
10 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" | 11 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h" |
11 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | 12 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" |
12 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "extensions/common/feature_switch.h" | 15 #include "extensions/common/feature_switch.h" |
15 | 16 |
16 namespace { | |
17 | |
18 const char kMockId[] = "mock_action"; | |
19 | |
20 class MockComponentToolbarActionsFactory | |
21 : public ComponentToolbarActionsFactory { | |
22 public: | |
23 explicit MockComponentToolbarActionsFactory(Browser* browser); | |
24 virtual ~MockComponentToolbarActionsFactory(); | |
25 | |
26 // ComponentToolbarActionsFactory: | |
27 ScopedVector<ToolbarActionViewController> | |
28 GetComponentToolbarActions(Browser* browser) override; | |
29 | |
30 const std::vector<std::string> action_ids() const { | |
31 return action_ids_; | |
32 } | |
33 | |
34 private: | |
35 // A set of all action ids of created actions. | |
36 std::vector<std::string> action_ids_; | |
37 | |
38 DISALLOW_COPY_AND_ASSIGN(MockComponentToolbarActionsFactory); | |
39 }; | |
40 | |
41 MockComponentToolbarActionsFactory::MockComponentToolbarActionsFactory( | |
42 Browser* browser) { | |
43 ComponentToolbarActionsFactory::SetTestingFactory(this); | |
44 | |
45 ScopedVector<ToolbarActionViewController> actions = | |
46 GetComponentToolbarActions(browser); | |
47 for (auto it = actions.begin(); it != actions.end(); ++it) { | |
48 action_ids_.push_back((*it)->GetId()); | |
49 } | |
50 } | |
51 | |
52 MockComponentToolbarActionsFactory::~MockComponentToolbarActionsFactory() { | |
53 ComponentToolbarActionsFactory::SetTestingFactory(nullptr); | |
54 } | |
55 | |
56 ScopedVector<ToolbarActionViewController> | |
57 MockComponentToolbarActionsFactory::GetComponentToolbarActions( | |
58 Browser* browser) { | |
59 ScopedVector<ToolbarActionViewController> component_actions; | |
60 TestToolbarActionViewController* action = | |
61 new TestToolbarActionViewController(kMockId); | |
62 component_actions.push_back(action); | |
63 return component_actions.Pass(); | |
64 } | |
65 | |
66 } // namespace | |
67 | |
68 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { | 17 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest { |
69 protected: | 18 protected: |
70 ComponentToolbarActionsBrowserTest() {} | 19 ComponentToolbarActionsBrowserTest() {} |
71 ~ComponentToolbarActionsBrowserTest() override {} | 20 ~ComponentToolbarActionsBrowserTest() override {} |
72 | 21 |
73 void SetUpCommandLine(base::CommandLine* command_line) override { | 22 void SetUpCommandLine(base::CommandLine* command_line) override { |
74 InProcessBrowserTest::SetUpCommandLine(command_line); | 23 InProcessBrowserTest::SetUpCommandLine(command_line); |
75 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( | 24 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( |
76 extensions::FeatureSwitch::extension_action_redesign(), true)); | 25 extensions::FeatureSwitch::extension_action_redesign(), true)); |
77 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory( | 26 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory( |
(...skipping 15 matching lines...) Expand all Loading... | |
93 // and can receive click events properly. | 42 // and can receive click events properly. |
94 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, | 43 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, |
95 ComponentToolbarActionsShowUpAndRespondToClicks) { | 44 ComponentToolbarActionsShowUpAndRespondToClicks) { |
96 BrowserActionTestUtil browser_actions_bar(browser()); | 45 BrowserActionTestUtil browser_actions_bar(browser()); |
97 | 46 |
98 // There should be only one component action view. | 47 // There should be only one component action view. |
99 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions()); | 48 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions()); |
100 | 49 |
101 // Even though the method says "ExtensionId", this actually refers to any id | 50 // Even though the method says "ExtensionId", this actually refers to any id |
102 // for the action. | 51 // for the action. |
103 EXPECT_EQ(kMockId, browser_actions_bar.GetExtensionId(0)); | 52 EXPECT_EQ(ComponentToolbarActionsFactory::kActionIdForTest, |
53 browser_actions_bar.GetExtensionId(0)); | |
Peter Kasting
2015/08/06 20:15:17
Nit: Indent even
apacible
2015/08/10 22:38:11
Done.
| |
104 | 54 |
105 // There should only have been one created component action. | 55 // There should only have been one created component action. |
106 const std::vector<std::string> action_ids = mock_factory()->action_ids(); | 56 const std::vector<std::string> action_ids = mock_factory()->action_ids(); |
107 ASSERT_EQ(1u, action_ids.size()); | 57 ASSERT_EQ(1u, action_ids.size()); |
108 | 58 |
109 const std::vector<ToolbarActionViewController*>& actions = | 59 const std::vector<ToolbarActionViewController*>& actions = |
110 browser_actions_bar.GetToolbarActionsBar()->GetActions(); | 60 browser_actions_bar.GetToolbarActionsBar()->GetActions(); |
111 TestToolbarActionViewController* mock_component_action = | 61 TestToolbarActionViewController* mock_component_action = |
112 static_cast<TestToolbarActionViewController* const>(actions[0]); | 62 static_cast<TestToolbarActionViewController* const>(actions[0]); |
113 ASSERT_TRUE(mock_component_action); | 63 ASSERT_TRUE(mock_component_action); |
114 | 64 |
115 // Test that clicking on the component action works. | 65 // Test that clicking on the component action works. |
116 EXPECT_EQ(0, mock_component_action->execute_action_count()); | 66 EXPECT_EQ(0, mock_component_action->execute_action_count()); |
117 browser_actions_bar.Press(0); | 67 browser_actions_bar.Press(0); |
118 EXPECT_EQ(1, mock_component_action->execute_action_count()); | 68 EXPECT_EQ(1, mock_component_action->execute_action_count()); |
119 } | 69 } |
OLD | NEW |