Chromium Code Reviews| 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/run_loop.h" | 6 #include "base/run_loop.h" |
| 7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_action_test_util.h" | 8 #include "chrome/browser/extensions/extension_action_test_util.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 EXPECT_TRUE(action_view->visible()); | 56 EXPECT_TRUE(action_view->visible()); |
| 57 | 57 |
| 58 // Click on the toolbar action to activate it. | 58 // Click on the toolbar action to activate it. |
| 59 gfx::Point action_view_loc = | 59 gfx::Point action_view_loc = |
| 60 test::GetCenterInScreenCoordinates(action_view); | 60 test::GetCenterInScreenCoordinates(action_view); |
| 61 ui_controls::SendMouseMove(action_view_loc.x(), action_view_loc.y()); | 61 ui_controls::SendMouseMove(action_view_loc.x(), action_view_loc.y()); |
| 62 ui_controls::SendMouseEventsNotifyWhenDone( | 62 ui_controls::SendMouseEventsNotifyWhenDone( |
| 63 button, ui_controls::DOWN | ui_controls::UP, quit_closure); | 63 button, ui_controls::DOWN | ui_controls::UP, quit_closure); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void ActivateOverflowedActionWithKeyboard(Browser* browser, | |
| 67 const base::Closure& closure) { | |
| 68 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser); | |
| 69 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | |
| 70 // We need to dispatch key events to the menu's native window, rather than the | |
| 71 // browser's. | |
| 72 gfx::NativeWindow native_window = | |
| 73 views::MenuController::GetActiveInstance()->owner()->GetNativeWindow(); | |
| 74 | |
| 75 // Send two key down events followed by the return key. | |
| 76 // The two key down events target the toolbar action in the app menu. | |
| 77 // TODO(devlin): Shouldn't this be one key down event? | |
|
varkha
2016/02/06 00:58:08
This will be fixed with https://codereview.chromiu
Devlin
2016/02/06 02:04:23
Oh, nice! I was going to look into that next. Gl
| |
| 78 ui_controls::SendKeyPress(native_window, | |
| 79 ui::VKEY_DOWN, | |
| 80 false, false, false, false); | |
| 81 ui_controls::SendKeyPress(native_window, | |
| 82 ui::VKEY_DOWN, | |
| 83 false, false, false, false); | |
| 84 ui_controls::SendKeyPressNotifyWhenDone(native_window, | |
| 85 ui::VKEY_RETURN, | |
| 86 false, false, false, false, closure); | |
| 87 } | |
| 88 | |
| 66 // Tests the context menu of an overflowed action. | 89 // Tests the context menu of an overflowed action. |
| 67 void TestWhileContextMenuOpen(bool* did_test_while_menu_open, | 90 void TestWhileContextMenuOpen(bool* did_test_while_menu_open, |
| 68 Browser* browser, | 91 Browser* browser, |
| 69 ToolbarActionView* context_menu_action) { | 92 ToolbarActionView* context_menu_action) { |
| 70 *did_test_while_menu_open = true; | 93 *did_test_while_menu_open = true; |
| 71 | 94 |
| 72 views::MenuItemView* menu_root = context_menu_action->menu_for_testing(); | 95 views::MenuItemView* menu_root = context_menu_action->menu_for_testing(); |
| 73 ASSERT_TRUE(menu_root); | 96 ASSERT_TRUE(menu_root); |
| 74 ASSERT_TRUE(menu_root->GetSubmenu()); | 97 ASSERT_TRUE(menu_root->GetSubmenu()); |
| 75 EXPECT_TRUE(menu_root->GetSubmenu()->IsShowing()); | 98 EXPECT_TRUE(menu_root->GetSubmenu()->IsShowing()); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 353 |
| 331 EXPECT_FALSE(view_controller->is_showing_popup()); | 354 EXPECT_FALSE(view_controller->is_showing_popup()); |
| 332 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); | 355 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); |
| 333 | 356 |
| 334 // Releasing the mouse shouldn't result in the popup being shown again. | 357 // Releasing the mouse shouldn't result in the popup being shown again. |
| 335 EXPECT_TRUE( | 358 EXPECT_TRUE( |
| 336 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); | 359 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); |
| 337 EXPECT_FALSE(view_controller->is_showing_popup()); | 360 EXPECT_FALSE(view_controller->is_showing_popup()); |
| 338 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); | 361 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); |
| 339 } | 362 } |
| 363 | |
| 364 #if defined(USE_OZONE) | |
| 365 // ozone bringup - http://crbug.com/401304 | |
| 366 #define MAYBE_ActivateOverflowedToolbarActionWithKeyboard \ | |
| 367 DISABLED_ActivateOverflowedToolbarActionWithKeyboard | |
| 368 #else | |
| 369 #define MAYBE_ActivateOverflowedToolbarActionWithKeyboard \ | |
| 370 ActivateOverflowedToolbarActionWithKeyboard | |
| 371 #endif | |
| 372 IN_PROC_BROWSER_TEST_F(ToolbarActionViewInteractiveUITest, | |
| 373 MAYBE_ActivateOverflowedToolbarActionWithKeyboard) { | |
| 374 views::MenuController::TurnOffMenuSelectionHoldForTest(); | |
| 375 // Load an extension with an action. | |
| 376 ASSERT_TRUE(LoadExtension( | |
| 377 test_data_dir_.AppendASCII("ui").AppendASCII("browser_action_popup"))); | |
| 378 base::RunLoop().RunUntilIdle(); // Ensure the extension is fully loaded. | |
| 379 | |
| 380 // Reduce visible count to 0 so that all actions are overflowed. | |
| 381 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); | |
| 382 | |
| 383 // Set up a listener for the extension being triggered. | |
| 384 ExtensionTestMessageListener listener("Popup opened", false); | |
| 385 | |
| 386 // Open the app menu, navigate to the toolbar action, and activate it via the | |
| 387 // keyboard. | |
| 388 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | |
| 389 gfx::Point app_button_loc = | |
| 390 test::GetCenterInScreenCoordinates(app_menu_button); | |
| 391 base::RunLoop loop; | |
| 392 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | |
| 393 ui_controls::SendMouseEventsNotifyWhenDone( | |
| 394 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | |
| 395 base::Bind(&ActivateOverflowedActionWithKeyboard, | |
| 396 browser(), loop.QuitClosure())); | |
| 397 loop.Run(); | |
| 398 | |
| 399 // The app menu should no longer be showing. | |
| 400 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | |
| 401 // And the extension should have been activated. | |
| 402 EXPECT_TRUE(listener.WaitUntilSatisfied()); | |
| 403 } | |
| OLD | NEW |