Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / component_toolbar_actions_browsertest.cc
blob51d882bb0ace1187cf5e3446219d8cec262b43c6
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.
5 #include "base/macros.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/extensions/browser_action_test_util.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/mock_component_toolbar_actions_factory.h"
11 #include "chrome/browser/ui/toolbar/test_toolbar_action_view_controller.h"
12 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
13 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
14 #include "chrome/test/base/in_process_browser_test.h"
15 #include "extensions/common/feature_switch.h"
17 class ComponentToolbarActionsBrowserTest : public InProcessBrowserTest {
18 protected:
19 ComponentToolbarActionsBrowserTest() {}
20 ~ComponentToolbarActionsBrowserTest() override {}
22 void SetUpCommandLine(base::CommandLine* command_line) override {
23 InProcessBrowserTest::SetUpCommandLine(command_line);
24 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
25 extensions::FeatureSwitch::extension_action_redesign(), true));
26 mock_actions_factory_.reset(new MockComponentToolbarActionsFactory(
27 browser()));
30 MockComponentToolbarActionsFactory* mock_factory() {
31 return mock_actions_factory_.get();
34 private:
35 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
36 scoped_ptr<MockComponentToolbarActionsFactory> mock_actions_factory_;
38 DISALLOW_COPY_AND_ASSIGN(ComponentToolbarActionsBrowserTest);
41 // Test that Component Toolbar Actions appear in the browser actions container
42 // and can receive click events properly.
43 IN_PROC_BROWSER_TEST_F(ComponentToolbarActionsBrowserTest,
44 ComponentToolbarActionsShowUpAndRespondToClicks) {
45 BrowserActionTestUtil browser_actions_bar(browser());
47 // There should be only one component action view.
48 ASSERT_EQ(1, browser_actions_bar.NumberOfBrowserActions());
50 // Even though the method says "ExtensionId", this actually refers to any id
51 // for the action.
52 EXPECT_EQ(ComponentToolbarActionsFactory::kActionIdForTesting,
53 browser_actions_bar.GetExtensionId(0));
55 // There should only have been one created component action.
56 const std::vector<std::string>& action_ids = mock_factory()->action_ids();
57 ASSERT_EQ(1u, action_ids.size());
59 const std::vector<ToolbarActionViewController*>& actions =
60 browser_actions_bar.GetToolbarActionsBar()->GetActions();
61 TestToolbarActionViewController* mock_component_action =
62 static_cast<TestToolbarActionViewController* const>(actions[0]);
63 ASSERT_TRUE(mock_component_action);
65 // Test that clicking on the component action works.
66 EXPECT_EQ(0, mock_component_action->execute_action_count());
67 browser_actions_bar.Press(0);
68 EXPECT_EQ(1, mock_component_action->execute_action_count());