1 // Copyright 2015 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/run_loop.h"
6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h"
8 #include "chrome/browser/ui/views/frame/browser_view.h"
9 #include "chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.h"
10 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
11 #include "chrome/browser/ui/views/toolbar/extension_toolbar_menu_view.h"
12 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
13 #include "chrome/browser/ui/views/toolbar/wrench_menu.h"
14 #include "chrome/browser/ui/views/toolbar/wrench_toolbar_button.h"
15 #include "chrome/test/base/interactive_test_utils.h"
16 #include "extensions/common/feature_switch.h"
17 #include "extensions/test/extension_test_message_listener.h"
21 // Tests clicking on an overflowed toolbar action. This is called when the
22 // wrench menu is open, and handles actually clicking on the action.
23 void TestOverflowedToolbarAction(Browser
* browser
,
24 const base::Closure
& quit_closure
) {
25 // A bunch of plumbing to safely get at the overflowed toolbar action.
26 ToolbarView
* toolbar
=
27 BrowserView::GetBrowserViewForBrowser(browser
)->toolbar();
28 EXPECT_TRUE(toolbar
->IsWrenchMenuShowing());
29 WrenchMenu
* wrench_menu
= toolbar
->wrench_menu_for_testing();
30 ASSERT_TRUE(wrench_menu
);
31 ExtensionToolbarMenuView
* menu_view
=
32 wrench_menu
->extension_toolbar_for_testing();
33 ASSERT_TRUE(menu_view
);
34 BrowserActionsContainer
* overflow_container
=
35 menu_view
->container_for_testing();
36 ASSERT_TRUE(overflow_container
);
37 ToolbarActionView
* action_view
=
38 overflow_container
->GetToolbarActionViewAt(0);
39 EXPECT_TRUE(action_view
->visible());
41 // Left click on the toolbar action to activate it.
42 gfx::Point action_view_loc
=
43 test::GetCenterInScreenCoordinates(action_view
);
44 ui_controls::SendMouseMove(action_view_loc
.x(), action_view_loc
.y());
45 ui_controls::SendMouseEventsNotifyWhenDone(
46 ui_controls::LEFT
, ui_controls::DOWN
| ui_controls::UP
, quit_closure
);
51 class ToolbarActionViewInteractiveUITest
: public ExtensionBrowserTest
{
53 ToolbarActionViewInteractiveUITest();
54 ~ToolbarActionViewInteractiveUITest() override
;
56 // ExtensionBrowserTest:
57 void SetUpCommandLine(base::CommandLine
* command_line
) override
;
58 void TearDownOnMainThread() override
;
61 // Override the extensions-action-redesign switch.
62 scoped_ptr
<extensions::FeatureSwitch::ScopedOverride
> feature_override_
;
64 DISALLOW_COPY_AND_ASSIGN(ToolbarActionViewInteractiveUITest
);
67 ToolbarActionViewInteractiveUITest::ToolbarActionViewInteractiveUITest() {}
68 ToolbarActionViewInteractiveUITest::~ToolbarActionViewInteractiveUITest() {}
70 void ToolbarActionViewInteractiveUITest::SetUpCommandLine(
71 base::CommandLine
* command_line
) {
72 ExtensionBrowserTest::SetUpCommandLine(command_line
);
73 // We do this before the rest of the setup because it can affect how the views
75 feature_override_
.reset(new extensions::FeatureSwitch::ScopedOverride(
76 extensions::FeatureSwitch::extension_action_redesign(), true));
77 ToolbarActionsBar::disable_animations_for_testing_
= true;
80 void ToolbarActionViewInteractiveUITest::TearDownOnMainThread() {
81 ToolbarActionsBar::disable_animations_for_testing_
= false;
84 #if defined(USE_OZONE)
85 // ozone bringup - http://crbug.com/401304
86 #define MAYBE_TestClickingOnOverflowedAction DISABLED_TestClickingOnOverflowedAction
88 #define MAYBE_TestClickingOnOverflowedAction TestClickingOnOverflowedAction
90 // Tests clicking on an overflowed extension action.
91 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest
,
92 MAYBE_TestClickingOnOverflowedAction
) {
94 ASSERT_TRUE(LoadExtension(
95 test_data_dir_
.AppendASCII("ui").AppendASCII("browser_action_popup")));
96 base::RunLoop().RunUntilIdle(); // Ensure the extension is fully loaded.
98 // Reduce visible count to 0 so that the action is overflowed.
99 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0);
101 // When the extension is activated, it will send a message that its popup
102 // opened. Listen for the message.
103 ExtensionTestMessageListener
listener("Popup opened", false);
105 ToolbarView
* toolbar_view
=
106 BrowserView::GetBrowserViewForBrowser(browser())->toolbar();
108 // Click on the wrench.
109 gfx::Point wrench_button_loc
=
110 test::GetCenterInScreenCoordinates(toolbar_view
->app_menu());
112 ui_controls::SendMouseMove(wrench_button_loc
.x(), wrench_button_loc
.y());
113 ui_controls::SendMouseEventsNotifyWhenDone(
115 ui_controls::DOWN
| ui_controls::UP
,
116 base::Bind(&TestOverflowedToolbarAction
, browser(), loop
.QuitClosure()));
118 // The wrench menu should no longer me showing.
119 EXPECT_FALSE(toolbar_view
->IsWrenchMenuShowing());
121 // And the extension should have been activated.
122 listener
.WaitUntilSatisfied();