OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/location.h" | 5 #include "base/location.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 namespace { | 32 namespace { |
33 | 33 |
34 AppMenuButton* GetAppButtonFromBrowser(Browser* browser) { | 34 AppMenuButton* GetAppButtonFromBrowser(Browser* browser) { |
35 return BrowserView::GetBrowserViewForBrowser(browser) | 35 return BrowserView::GetBrowserViewForBrowser(browser) |
36 ->toolbar() | 36 ->toolbar() |
37 ->app_menu_button(); | 37 ->app_menu_button(); |
38 } | 38 } |
39 | 39 |
40 // Tests clicking on an overflowed toolbar action. This is called when the app | 40 // Tests clicking on an overflowed toolbar action. This is called when the app |
41 // menu is open, and handles actually clicking on the action. | 41 // menu is open, and handles actually clicking on the action. |
42 // |button| specifies the mouse button to click with. | 42 // |button| specifies the mouse button to click with. Optionally |
| 43 // |toolbar_action_view| can be provided to receive the targeted |
| 44 // ToolbarActionView. |
43 void TestOverflowedToolbarAction(Browser* browser, | 45 void TestOverflowedToolbarAction(Browser* browser, |
44 ui_controls::MouseButton button) { | 46 ui_controls::MouseButton button, |
| 47 ToolbarActionView** toolbar_action_view) { |
45 // A bunch of plumbing to safely get at the overflowed toolbar action. | 48 // A bunch of plumbing to safely get at the overflowed toolbar action. |
46 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser); | 49 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser); |
47 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 50 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
48 AppMenu* app_menu = app_menu_button->app_menu_for_testing(); | 51 AppMenu* app_menu = app_menu_button->app_menu_for_testing(); |
49 ASSERT_TRUE(app_menu); | 52 ASSERT_TRUE(app_menu); |
50 ExtensionToolbarMenuView* menu_view = | 53 ExtensionToolbarMenuView* menu_view = |
51 app_menu->extension_toolbar_for_testing(); | 54 app_menu->extension_toolbar_for_testing(); |
52 ASSERT_TRUE(menu_view); | 55 ASSERT_TRUE(menu_view); |
53 BrowserActionsContainer* overflow_container = | 56 BrowserActionsContainer* overflow_container = |
54 menu_view->container_for_testing(); | 57 menu_view->container_for_testing(); |
55 ASSERT_TRUE(overflow_container); | 58 ASSERT_TRUE(overflow_container); |
56 ToolbarActionView* action_view = | 59 ToolbarActionView* action_view = |
57 overflow_container->GetToolbarActionViewAt(0); | 60 overflow_container->GetToolbarActionViewAt(0); |
58 EXPECT_TRUE(action_view->visible()); | 61 EXPECT_TRUE(action_view->visible()); |
59 | 62 |
60 // Click on the toolbar action to activate it. | 63 // Click on the toolbar action to activate it. |
61 gfx::Point action_view_loc = | 64 gfx::Point action_view_loc = |
62 ui_test_utils::GetCenterInScreenCoordinates(action_view); | 65 ui_test_utils::GetCenterInScreenCoordinates(action_view); |
63 ui_controls::SendMouseMove(action_view_loc.x(), action_view_loc.y()); | 66 ui_controls::SendMouseMove(action_view_loc.x(), action_view_loc.y()); |
64 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( | 67 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( |
65 button, ui_controls::DOWN | ui_controls::UP)); | 68 button, ui_controls::DOWN | ui_controls::UP)); |
| 69 |
| 70 if (toolbar_action_view) |
| 71 *toolbar_action_view = action_view; |
66 } | 72 } |
67 | 73 |
68 // Tests the context menu of an overflowed action. | 74 // Tests the context menu of an overflowed action. |
69 void TestWhileContextMenuOpen(bool* did_test_while_menu_open, | 75 void TestWhileContextMenuOpen(Browser* browser, |
70 Browser* browser, | |
71 ToolbarActionView* context_menu_action) { | 76 ToolbarActionView* context_menu_action) { |
72 *did_test_while_menu_open = true; | |
73 | |
74 views::MenuItemView* menu_root = context_menu_action->menu_for_testing(); | 77 views::MenuItemView* menu_root = context_menu_action->menu_for_testing(); |
75 ASSERT_TRUE(menu_root); | 78 ASSERT_TRUE(menu_root); |
76 ASSERT_TRUE(menu_root->GetSubmenu()); | 79 ASSERT_TRUE(menu_root->GetSubmenu()); |
77 EXPECT_TRUE(menu_root->GetSubmenu()->IsShowing()); | 80 EXPECT_TRUE(menu_root->GetSubmenu()->IsShowing()); |
78 views::MenuItemView* first_menu_item = | 81 views::MenuItemView* first_menu_item = |
79 menu_root->GetSubmenu()->GetMenuItemAt(0); | 82 menu_root->GetSubmenu()->GetMenuItemAt(0); |
80 ASSERT_TRUE(first_menu_item); | 83 ASSERT_TRUE(first_menu_item); |
81 | 84 |
82 // Make sure we're showing the right context menu. | 85 // Make sure we're showing the right context menu. |
83 EXPECT_EQ(base::UTF8ToUTF16("Browser Action Popup"), | 86 EXPECT_EQ(base::UTF8ToUTF16("Browser Action Popup"), |
(...skipping 28 matching lines...) Expand all Loading... |
112 &action_view_loc_in_menu_item_bounds); | 115 &action_view_loc_in_menu_item_bounds); |
113 // Regression test for crbug.com/538414: The first menu item is overlapping | 116 // Regression test for crbug.com/538414: The first menu item is overlapping |
114 // the second row action button. With crbug.com/538414, the click would go to | 117 // the second row action button. With crbug.com/538414, the click would go to |
115 // the menu button, instead of the menu item. | 118 // the menu button, instead of the menu item. |
116 EXPECT_TRUE( | 119 EXPECT_TRUE( |
117 first_menu_item->HitTestPoint(action_view_loc_in_menu_item_bounds)); | 120 first_menu_item->HitTestPoint(action_view_loc_in_menu_item_bounds)); |
118 | 121 |
119 // Click on the first menu item (which shares bounds, but overlaps, the second | 122 // Click on the first menu item (which shares bounds, but overlaps, the second |
120 // row action). | 123 // row action). |
121 ui_controls::SendMouseMove(action_view_loc.x(), action_view_loc.y()); | 124 ui_controls::SendMouseMove(action_view_loc.x(), action_view_loc.y()); |
122 ui_controls::SendMouseEventsNotifyWhenDone( | 125 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( |
123 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, base::Closure()); | 126 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); |
124 | |
125 // Test resumes in the main test body. | 127 // Test resumes in the main test body. |
126 } | 128 } |
127 | 129 |
128 // Posts a task to test the context menu. | |
129 void OnContextMenuWillShow(bool* did_test_while_menu_open, | |
130 Browser* browser, | |
131 ToolbarActionView* toolbar_action_view) { | |
132 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
133 FROM_HERE, base::Bind(&TestWhileContextMenuOpen, did_test_while_menu_open, | |
134 browser, toolbar_action_view)); | |
135 } | |
136 | |
137 } // namespace | 130 } // namespace |
138 | 131 |
139 class ToolbarActionViewInteractiveUITest : public ExtensionBrowserTest { | 132 class ToolbarActionViewInteractiveUITest : public ExtensionBrowserTest { |
140 protected: | 133 protected: |
141 ToolbarActionViewInteractiveUITest(); | 134 ToolbarActionViewInteractiveUITest(); |
142 ~ToolbarActionViewInteractiveUITest() override; | 135 ~ToolbarActionViewInteractiveUITest() override; |
143 | 136 |
144 // ExtensionBrowserTest: | 137 // ExtensionBrowserTest: |
145 void SetUpCommandLine(base::CommandLine* command_line) override; | 138 void SetUpCommandLine(base::CommandLine* command_line) override; |
146 void TearDownOnMainThread() override; | 139 void TearDownOnMainThread() override; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 187 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
195 | 188 |
196 // Click on the app button. | 189 // Click on the app button. |
197 gfx::Point app_button_loc = | 190 gfx::Point app_button_loc = |
198 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); | 191 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
199 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 192 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
200 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( | 193 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( |
201 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); | 194 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); |
202 base::RunLoop().RunUntilIdle(); | 195 base::RunLoop().RunUntilIdle(); |
203 | 196 |
204 TestOverflowedToolbarAction(browser(), ui_controls::LEFT); | 197 TestOverflowedToolbarAction(browser(), ui_controls::LEFT, nullptr); |
205 | 198 |
206 base::RunLoop().RunUntilIdle(); | 199 base::RunLoop().RunUntilIdle(); |
207 // The app menu should no longer be showing. | 200 // The app menu should no longer be showing. |
208 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | 201 EXPECT_FALSE(app_menu_button->IsMenuShowing()); |
209 | 202 |
210 // And the extension should have been activated. | 203 // And the extension should have been activated. |
211 listener.WaitUntilSatisfied(); | 204 listener.WaitUntilSatisfied(); |
212 } | 205 } |
213 | 206 |
214 // TODO(jonross): determine cause of new flake, and restore previous MAYBE | 207 // TODO(jonross): determine cause of new flake, and restore previous MAYBE |
215 // conditions. Temporarily disabling due to number of flakes (crbug.com/639010) | 208 // conditions. Temporarily disabling due to number of flakes (crbug.com/639010) |
216 // Tests the context menus of overflowed extension actions. | 209 // Tests the context menus of overflowed extension actions. |
| 210 |
| 211 #if defined(USE_OZONE) |
| 212 // ozone bringup - http://crbug.com/401304 |
| 213 #define MAYBE_TestContextMenuOnOverflowedAction \ |
| 214 DISABLED_TestContextMenuOnOverflowedAction |
| 215 #else |
| 216 #define MAYBE_TestContextMenuOnOverflowedAction \ |
| 217 TestContextMenuOnOverflowedAction |
| 218 #endif |
217 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, | 219 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, |
218 DISABLED_TestContextMenuOnOverflowedAction) { | 220 MAYBE_TestContextMenuOnOverflowedAction) { |
219 views::MenuController::TurnOffMenuSelectionHoldForTest(); | 221 views::MenuController::TurnOffMenuSelectionHoldForTest(); |
220 | 222 |
221 // Load an extension that has a home page (important for the context menu's | 223 // Load an extension that has a home page (important for the context menu's |
222 // first item being enabled). | 224 // first item being enabled). |
223 ASSERT_TRUE(LoadExtension( | 225 ASSERT_TRUE(LoadExtension( |
224 test_data_dir_.AppendASCII("ui").AppendASCII("browser_action_popup"))); | 226 test_data_dir_.AppendASCII("ui").AppendASCII("browser_action_popup"))); |
225 base::RunLoop().RunUntilIdle(); // Ensure the extension is fully loaded. | 227 base::RunLoop().RunUntilIdle(); // Ensure the extension is fully loaded. |
226 | 228 |
227 // Aaaannnnd... Load a bunch of other extensions so that the overflow menu | 229 // Aaaannnnd... Load a bunch of other extensions so that the overflow menu |
228 // is spread across multiple rows. | 230 // is spread across multiple rows. |
229 for (int i = 0; i < 15; ++i) { | 231 for (int i = 0; i < 15; ++i) { |
230 scoped_refptr<const extensions::Extension> extension = | 232 scoped_refptr<const extensions::Extension> extension = |
231 extensions::extension_action_test_util::CreateActionExtension( | 233 extensions::extension_action_test_util::CreateActionExtension( |
232 base::IntToString(i), | 234 base::IntToString(i), |
233 extensions::extension_action_test_util::BROWSER_ACTION); | 235 extensions::extension_action_test_util::BROWSER_ACTION); |
234 extension_service()->AddExtension(extension.get()); | 236 extension_service()->AddExtension(extension.get()); |
235 } | 237 } |
236 | 238 |
237 ASSERT_EQ(16u, browser() | 239 ASSERT_EQ(16u, browser() |
238 ->window() | 240 ->window() |
239 ->GetToolbarActionsBar() | 241 ->GetToolbarActionsBar() |
240 ->toolbar_actions_unordered() | 242 ->toolbar_actions_unordered() |
241 .size()); | 243 .size()); |
242 | 244 |
243 // Reduce visible count to 0 so that all actions are overflowed. | 245 // Reduce visible count to 0 so that all actions are overflowed. |
244 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); | 246 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); |
245 | 247 |
246 // Set a callback for the context menu showing. | |
247 bool did_test_while_menu_open = false; | |
248 base::Callback<void(ToolbarActionView*)> context_menu_callback( | |
249 base::Bind(&OnContextMenuWillShow, &did_test_while_menu_open, browser())); | |
250 ToolbarActionView::set_context_menu_callback_for_testing( | |
251 &context_menu_callback); | |
252 | |
253 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 248 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
254 // Click on the app button, and then right-click on the first toolbar action. | 249 // Click on the app button, and then right-click on the first toolbar action. |
255 gfx::Point app_button_loc = | 250 gfx::Point app_button_loc = |
256 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); | 251 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
257 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 252 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
258 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( | 253 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( |
259 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); | 254 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); |
260 | |
261 base::RunLoop().RunUntilIdle(); | |
262 TestOverflowedToolbarAction(browser(), ui_controls::RIGHT); | |
263 base::RunLoop().RunUntilIdle(); | 255 base::RunLoop().RunUntilIdle(); |
264 | 256 |
265 // Test is continued first in TestOverflowedToolbarAction() to right click on | 257 // Right clicks on the action view, this should trigger the context menu. |
266 // the action, followed by OnContextMenuWillShow() and | 258 ToolbarActionView* action_view = nullptr; |
267 // TestWhileContextMenuOpen(). | 259 TestOverflowedToolbarAction(browser(), ui_controls::RIGHT, &action_view); |
| 260 base::RunLoop().RunUntilIdle(); |
268 | 261 |
269 // Make sure we did all the expected tests. | 262 // Ensure that the menu actually opened. |
270 EXPECT_TRUE(did_test_while_menu_open); | 263 EXPECT_TRUE(action_view->IsMenuRunningForTesting()); |
271 | 264 |
| 265 // Triggers the action within the context menu. This should load the extension |
| 266 // webpage, and close the menu. |
| 267 TestWhileContextMenuOpen(browser(), action_view); |
| 268 base::RunLoop().RunUntilIdle(); |
| 269 |
| 270 EXPECT_FALSE(action_view->IsMenuRunningForTesting()); |
272 // We should have navigated to the extension's home page, which is google.com. | 271 // We should have navigated to the extension's home page, which is google.com. |
273 EXPECT_EQ( | 272 EXPECT_EQ( |
274 GURL("https://www.google.com/"), | 273 GURL("https://www.google.com/"), |
275 browser()->tab_strip_model()->GetActiveWebContents()->GetVisibleURL()); | 274 browser()->tab_strip_model()->GetActiveWebContents()->GetVisibleURL()); |
276 } | 275 } |
277 | 276 |
278 // Tests that clicking on the toolbar action a second time when the action is | 277 // Tests that clicking on the toolbar action a second time when the action is |
279 // already open results in closing the popup, and doesn't re-open it. | 278 // already open results in closing the popup, and doesn't re-open it. |
280 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, | 279 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, |
281 DoubleClickToolbarActionToClose) { | 280 DoubleClickToolbarActionToClose) { |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 EXPECT_FALSE(view_controller->is_showing_popup()); | 328 EXPECT_FALSE(view_controller->is_showing_popup()); |
330 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); | 329 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); |
331 | 330 |
332 // Releasing the mouse shouldn't result in the popup being shown again. | 331 // Releasing the mouse shouldn't result in the popup being shown again. |
333 EXPECT_TRUE( | 332 EXPECT_TRUE( |
334 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); | 333 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); |
335 EXPECT_FALSE(view_controller->is_showing_popup()); | 334 EXPECT_FALSE(view_controller->is_showing_popup()); |
336 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); | 335 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); |
337 } | 336 } |
338 | 337 |
339 #if defined(USE_OZONE) || defined(OS_WIN) | 338 #if defined(USE_OZONE) |
340 // ozone bringup - http://crbug.com/401304 | 339 // ozone bringup - http://crbug.com/401304 |
341 // flaky on Windows - http://crbug.com/638692 | |
342 #define MAYBE_ActivateOverflowedToolbarActionWithKeyboard \ | 340 #define MAYBE_ActivateOverflowedToolbarActionWithKeyboard \ |
343 DISABLED_ActivateOverflowedToolbarActionWithKeyboard | 341 DISABLED_ActivateOverflowedToolbarActionWithKeyboard |
344 #else | 342 #else |
345 #define MAYBE_ActivateOverflowedToolbarActionWithKeyboard \ | 343 #define MAYBE_ActivateOverflowedToolbarActionWithKeyboard \ |
346 ActivateOverflowedToolbarActionWithKeyboard | 344 ActivateOverflowedToolbarActionWithKeyboard |
347 #endif | 345 #endif |
348 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, | 346 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, |
349 MAYBE_ActivateOverflowedToolbarActionWithKeyboard) { | 347 MAYBE_ActivateOverflowedToolbarActionWithKeyboard) { |
350 views::MenuController::TurnOffMenuSelectionHoldForTest(); | 348 views::MenuController::TurnOffMenuSelectionHoldForTest(); |
351 // Load an extension with an action. | 349 // Load an extension with an action. |
(...skipping 20 matching lines...) Expand all Loading... |
372 | 370 |
373 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 371 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
374 gfx::NativeWindow native_window = | 372 gfx::NativeWindow native_window = |
375 views::MenuController::GetActiveInstance()->owner()->GetNativeWindow(); | 373 views::MenuController::GetActiveInstance()->owner()->GetNativeWindow(); |
376 // Send a key down event followed by the return key. | 374 // Send a key down event followed by the return key. |
377 // The key down event targets the toolbar action in the app menu. | 375 // The key down event targets the toolbar action in the app menu. |
378 ui_controls::SendKeyPress(native_window, ui::VKEY_DOWN, false, false, false, | 376 ui_controls::SendKeyPress(native_window, ui::VKEY_DOWN, false, false, false, |
379 false); | 377 false); |
380 // The triggering of the action and subsequent widget destruction occurs on | 378 // The triggering of the action and subsequent widget destruction occurs on |
381 // the message loop. Wait for this all to complete. | 379 // the message loop. Wait for this all to complete. |
382 base::RunLoop loop; | 380 EXPECT_TRUE(ui_test_utils::SendKeyPressToWindowSync( |
383 ui_controls::SendKeyPressNotifyWhenDone(native_window, ui::VKEY_RETURN, false, | 381 native_window, ui::VKEY_RETURN, false, false, false, false)); |
384 false, false, false, | 382 base::RunLoop().RunUntilIdle(); |
385 loop.QuitClosure()); | |
386 loop.Run(); | |
387 | 383 |
388 // The menu should be closed. | 384 // The menu should be closed. |
389 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | 385 EXPECT_FALSE(app_menu_button->IsMenuShowing()); |
390 // And the extension should have been activated. | 386 // And the extension should have been activated. |
391 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 387 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
392 } | 388 } |
OLD | NEW |