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

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

Issue 661493004: Add infrastructure for Chrome Actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #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/views/frame/browser_view.h"
12 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
14 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "extensions/common/feature_switch.h"
17 #include "grit/theme_resources.h"
18 #include "ui/base/resource/resource_bundle.h"
19
20 namespace {
21
22 const char kMockId[] = "mock_action";
23
24 class MockComponentAction : public ToolbarActionViewController {
25 public:
26 MockComponentAction() : click_count_(0u), id_(kMockId) {}
27 virtual ~MockComponentAction() {}
28
29 // ToolbarActionButtonController:
30 virtual const std::string& GetId() const override { return id_; }
31 virtual void SetDelegate(ToolbarActionViewDelegate* delegate) override {}
32 virtual gfx::Image GetIcon(content::WebContents* web_contents) override {
33 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
34 IDR_BROWSER_ACTION);
35 }
36 virtual gfx::ImageSkia GetIconWithBadge() override {
37 return *GetIcon(nullptr).ToImageSkia();
38 }
39 virtual base::string16 GetAccessibleName(content::WebContents* web_contents)
40 const override {
41 return base::ASCIIToUTF16("Component Action");
42 }
43 virtual base::string16 GetTooltip(content::WebContents* web_contents)
44 const override {
45 return GetAccessibleName(web_contents);
46 }
47 virtual bool IsEnabled(content::WebContents* web_contents) const override {
48 return true;
49 }
50 virtual bool HasPopup(content::WebContents* web_contents) const override {
51 return true;
52 }
53 virtual void HidePopup() override {}
54 virtual gfx::NativeView GetPopupNativeView() override { return nullptr; }
55 virtual bool CanDrag() const override { return false; }
56 virtual bool IsMenuRunning() const override { return false; }
57 virtual bool ExecuteAction(bool by_user) override {
58 ++click_count_;
59 return false;
60 }
61
62 size_t click_count() const { return click_count_; }
63
64 private:
65 size_t click_count_;
66 std::string id_;
67
68 DISALLOW_COPY_AND_ASSIGN(MockComponentAction);
69 };
70
71 class MockComponentToolbarActionsFactory
72 : public ComponentToolbarActionsFactory {
73 public:
74 MockComponentToolbarActionsFactory();
75 virtual ~MockComponentToolbarActionsFactory();
76
77 // ComponentToolbarActionsFactory:
78 virtual ScopedVector<ToolbarActionViewController>
79 GetComponentToolbarActions() override;
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(MockComponentToolbarActionsFactory);
83 };
84
85 MockComponentToolbarActionsFactory::MockComponentToolbarActionsFactory() {
86 ComponentToolbarActionsFactory::SetTestingFactory(this);
87 }
88
89 MockComponentToolbarActionsFactory::~MockComponentToolbarActionsFactory() {
90 ComponentToolbarActionsFactory::SetTestingFactory(nullptr);
91 }
92
93 ScopedVector<ToolbarActionViewController>
94 MockComponentToolbarActionsFactory::GetComponentToolbarActions() {
95 ScopedVector<ToolbarActionViewController> component_actions;
96 component_actions.push_back(new MockComponentAction());
97 return component_actions.Pass();
98 }
99
100 } // namespace
101
102 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest {
103 protected:
104 ComponentToolbarActionsBrowserTest() {}
105 virtual ~ComponentToolbarActionsBrowserTest() {}
106
107 virtual void SetUpCommandLine(base::CommandLine* command_line) override {
108 InProcessBrowserTest::SetUpCommandLine(command_line);
109 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
110 extensions::FeatureSwitch::extension_action_redesign(), true));
111 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory());
112 }
113
114 private:
115 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
116 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_;
117
118 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest);
119 };
120
121 // Test that Component Toolbar Actions appear in the browser actions container
122 // and can receive click events properly.
123 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest,
124 ComponentToolbarActionsShowUpAndRespondToClicks) {
125 BrowserActionsContainer* browser_actions_container =
126 BrowserView::GetBrowserViewForBrowser(browser())
127 ->toolbar()->browser_actions();
128
129 // There should be only one component action view.
130 ASSERT_EQ(1u, browser_actions_container->num_browser_actions());
131
132 BrowserActionView* view =
133 browser_actions_container->GetBrowserActionViewAt(0u);
134 ASSERT_EQ(kMockId, view->view_controller()->GetId());
135 MockComponentAction* mock_component_action =
136 static_cast<MockComponentAction*>(view->view_controller());
137
138 // Test that clicking on the component action works.
139 EXPECT_EQ(0u, mock_component_action->click_count());
140 view->Activate();
141 EXPECT_EQ(1u, mock_component_action->click_count());
142 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/chevron_menu_button.cc ('k') | chrome/browser/ui/views/toolbar/toolbar_action_view_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698