Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: chrome/browser/ui/toolbar/component_toolbar_actions_browsertest.cc

Issue 2613713005: Make ToolbarActionsModel own ComponentToolbarActionsFactory (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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(
26 extensions::FeatureSwitch::extension_action_redesign(), true));
27 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory(
28 browser()));
29 }
30 25
31 MockComponentToolbarActionsFactory* mock_factory() { 26 // Swap out the actions factory for a mock one.
32 return mock_actions_factory_.get(); 27 ToolbarActionsModel::Get(browser()->profile())
msw 2017/01/10 23:23:59 optional nit: cache a local profile pointer
takumif 2017/02/17 03:22:51 Done.
28 ->SetMockActionsFactory(new MockComponentToolbarActionsFactory(
29 browser()->profile(),
30 ToolbarActionsModel::Get(browser()->profile())));
33 } 31 }
34 32
35 private: 33 private:
36 std::unique_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
msw 2017/01/10 23:23:59 Is this no longer needed?
takumif 2017/02/17 03:22:51 No, removing.
37 std::unique_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_;
38
39 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest); 34 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest);
40 }; 35 };
41 36
42 // Test that Component Toolbar Actions appear in the browser actions container 37 // Test that Component Toolbar Actions appear in the browser actions container
43 // and can receive click events properly. 38 // and can receive click events properly.
44 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest, 39 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest,
45 ComponentToolbarActionsShowUpAndRespondToClicks) { 40 ComponentToolbarActionsShowUpAndRespondToClicks) {
46 BrowserActionTestUtil browser_actions_bar(browser()); 41 BrowserActionTestUtil browser_actions_bar(browser());
47 42
43 ToolbarActionsModel::Get(browser()->profile())
44 ->AddComponentAction(
45 MockComponentToolbarActionsFactory::kActionIdForTesting);
46
48 // There should be only one component action view. 47 // There should be only one component action view.
49 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions()); 48 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions());
50 49
51 // 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
52 // for the action. 51 // for the action.
53 EXPECT_EQ(MockComponentToolbarActionsFactory::kActionIdForTesting, 52 EXPECT_EQ(MockComponentToolbarActionsFactory::kActionIdForTesting,
54 browser_actions_bar.GetExtensionId(0)); 53 browser_actions_bar.GetExtensionId(0));
55 54
56 // There should only have been one created component action.
57 EXPECT_EQ(1u, ComponentToolbarActionsFactory::GetInstance()
msw 2017/01/10 23:23:59 Should GetInitialComponentIds still be checked in
takumif 2017/02/17 03:22:51 This was just to make sure that the MockComponentT
58 ->GetInitialComponentIds(browser()->profile())
59 .size());
60
61 const std::vector<ToolbarActionViewController*>& actions = 55 const std::vector<ToolbarActionViewController*>& actions =
62 browser_actions_bar.GetToolbarActionsBar()->GetActions(); 56 browser_actions_bar.GetToolbarActionsBar()->GetActions();
63 TestToolbarActionViewController* mock_component_action = 57 TestToolbarActionViewController* mock_component_action =
64 static_cast<TestToolbarActionViewController* const>(actions[0]); 58 static_cast<TestToolbarActionViewController* const>(actions[0]);
65 ASSERT_TRUE(mock_component_action); 59 ASSERT_TRUE(mock_component_action);
66 60
67 // Test that clicking on the component action works. 61 // Test that clicking on the component action works.
68 EXPECT_EQ(0, mock_component_action->execute_action_count()); 62 EXPECT_EQ(0, mock_component_action->execute_action_count());
69 browser_actions_bar.Press(0); 63 browser_actions_bar.Press(0);
70 EXPECT_EQ(1, mock_component_action->execute_action_count()); 64 EXPECT_EQ(1, mock_component_action->execute_action_count());
71 } 65 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698