| Index: chrome/browser/ui/views/toolbar/chrome_actions_browsertest.cc
|
| diff --git a/chrome/browser/ui/views/toolbar/chrome_actions_browsertest.cc b/chrome/browser/ui/views/toolbar/chrome_actions_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..52d69853041c4a86cd53e3d6648d29dae3325ba7
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/toolbar/chrome_actions_browsertest.cc
|
| @@ -0,0 +1,100 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/macros.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/views/frame/browser_view.h"
|
| +#include "chrome/browser/ui/views/toolbar/browser_action_view.h"
|
| +#include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
|
| +#include "chrome/browser/ui/views/toolbar/chrome_actions_registry.h"
|
| +#include "chrome/browser/ui/views/toolbar/toolbar_action_view_controller.h"
|
| +#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "extensions/common/feature_switch.h"
|
| +#include "grit/theme_resources.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +
|
| +namespace {
|
| +
|
| +class MockChromeAction : public ToolbarActionViewController {
|
| + public:
|
| + MockChromeAction() : click_count_(0u) {}
|
| + virtual ~MockChromeAction() {}
|
| +
|
| + // ToolbarActionButtonController:
|
| + virtual void SetDelegate(ToolbarActionViewDelegate* delegate) override {}
|
| + virtual gfx::Image GetIcon(int tab_id) override {
|
| + return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
|
| + IDR_BROWSER_ACTION);
|
| + }
|
| + virtual base::string16 GetAccessibleName(int tab_id) const override {
|
| + return base::ASCIIToUTF16("Chrome Action");
|
| + }
|
| + virtual base::string16 GetTooltip(int tab_id) const override {
|
| + return GetAccessibleName(tab_id);
|
| + }
|
| + virtual bool IsEnabled(int tab_id) const override { return true; }
|
| + virtual bool HasPopup(int tab_id) const override { return true; }
|
| + virtual void HidePopup() override {}
|
| + virtual bool IsMenuRunning() const override { return false; }
|
| + virtual void ExecuteActionByUser() override { ++click_count_; }
|
| +
|
| + size_t click_count() const { return click_count_; }
|
| +
|
| + private:
|
| + size_t click_count_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MockChromeAction);
|
| +};
|
| +
|
| +ScopedVector<ToolbarActionViewController> GetChromeActions() {
|
| + ScopedVector<ToolbarActionViewController> chrome_actions;
|
| + chrome_actions.push_back(new MockChromeAction());
|
| + return chrome_actions.Pass();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +class ChromeActionsBrowserTest : public InProcessBrowserTest {
|
| + protected:
|
| + ChromeActionsBrowserTest() {}
|
| + virtual ~ChromeActionsBrowserTest() {}
|
| +
|
| + virtual void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + InProcessBrowserTest::SetUpCommandLine(command_line);
|
| + enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
|
| + extensions::FeatureSwitch::extension_action_redesign(), true));
|
| + ChromeActionsRegistry::SetTestingChromeActionsFunction(&GetChromeActions);
|
| + }
|
| +
|
| + private:
|
| + scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ChromeActionsBrowserTest);
|
| +};
|
| +
|
| +// Test that Chrome Actions appear in the browser actions container and can
|
| +// receive click events properly.
|
| +IN_PROC_BROWSER_TEST_F(ChromeActionsBrowserTest,
|
| + ChromeActionsShowUpAndRespondToClicks) {
|
| + BrowserActionsContainer* browser_actions_container =
|
| + BrowserView::GetBrowserViewForBrowser(browser())
|
| + ->toolbar()->browser_actions();
|
| +
|
| + // There should be only one chrome action view.
|
| + ASSERT_EQ(1u, browser_actions_container->num_chrome_actions());
|
| +
|
| + BrowserActionView* view =
|
| + browser_actions_container->GetChromeActionViewAt(0u);
|
| + ASSERT_EQ(BrowserActionView::TYPE_CHROME_ACTION, view->type());
|
| + MockChromeAction* mock_chrome_action =
|
| + static_cast<MockChromeAction*>(view->view_controller());
|
| +
|
| + // Test that clicking on the chrome action works.
|
| + EXPECT_EQ(0u, mock_chrome_action->click_count());
|
| + view->Activate();
|
| + EXPECT_EQ(1u, mock_chrome_action->click_count());
|
| +}
|
|
|