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

Side by Side Diff: chrome/browser/ui/views/toolbar/chrome_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/views/frame/browser_view.h"
10 #include "chrome/browser/ui/views/toolbar/browser_action_view.h"
11 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
12 #include "chrome/browser/ui/views/toolbar/chrome_actions_registry.h"
13 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_controller.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 class MockChromeAction : public ToolbarActionViewController {
23 public:
24 MockChromeAction() : click_count_(0u) {}
25 virtual ~MockChromeAction() {}
26
27 // ToolbarActionButtonController:
28 virtual void SetDelegate(ToolbarActionViewDelegate* delegate) override {}
29 virtual gfx::Image GetIcon(int tab_id) override {
30 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
31 IDR_BROWSER_ACTION);
32 }
33 virtual base::string16 GetAccessibleName(int tab_id) const override {
34 return base::ASCIIToUTF16("Chrome Action");
35 }
36 virtual base::string16 GetTooltip(int tab_id) const override {
37 return GetAccessibleName(tab_id);
38 }
39 virtual bool IsEnabled(int tab_id) const override { return true; }
40 virtual bool HasPopup(int tab_id) const override { return true; }
41 virtual void HidePopup() override {}
42 virtual bool IsMenuRunning() const override { return false; }
43 virtual void ExecuteActionByUser() override { ++click_count_; }
44
45 size_t click_count() const { return click_count_; }
46
47 private:
48 size_t click_count_;
49
50 DISALLOW_COPY_AND_ASSIGN(MockChromeAction);
51 };
52
53 ScopedVector<ToolbarActionViewController> GetChromeActions() {
54 ScopedVector<ToolbarActionViewController> chrome_actions;
55 chrome_actions.push_back(new MockChromeAction());
56 return chrome_actions.Pass();
57 }
58
59 } // namespace
60
61 class ChromeActionsBrowserTest : public InProcessBrowserTest {
62 protected:
63 ChromeActionsBrowserTest() {}
64 virtual ~ChromeActionsBrowserTest() {}
65
66 virtual void SetUpCommandLine(base::CommandLine* command_line) override {
67 InProcessBrowserTest::SetUpCommandLine(command_line);
68 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
69 extensions::FeatureSwitch::extension_action_redesign(), true));
70 ChromeActionsRegistry::SetTestingChromeActionsFunction(&GetChromeActions);
71 }
72
73 private:
74 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
75
76 DISALLOW_COPY_AND_ASSIGN(ChromeActionsBrowserTest);
77 };
78
79 // Test that Chrome Actions appear in the browser actions container and can
80 // receive click events properly.
81 IN_PROC_BROWSER_TEST_F(ChromeActionsBrowserTest,
82 ChromeActionsShowUpAndRespondToClicks) {
83 BrowserActionsContainer* browser_actions_container =
84 BrowserView::GetBrowserViewForBrowser(browser())
85 ->toolbar()->browser_actions();
86
87 // There should be only one chrome action view.
88 ASSERT_EQ(1u, browser_actions_container->num_chrome_actions());
89
90 BrowserActionView* view =
91 browser_actions_container->GetChromeActionViewAt(0u);
92 ASSERT_EQ(BrowserActionView::TYPE_CHROME_ACTION, view->type());
93 MockChromeAction* mock_chrome_action =
94 static_cast<MockChromeAction*>(view->view_controller());
95
96 // Test that clicking on the chrome action works.
97 EXPECT_EQ(0u, mock_chrome_action->click_count());
98 view->Activate();
99 EXPECT_EQ(1u, mock_chrome_action->click_count());
100 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698