| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 ASSERT_TRUE(menu_view); | 50 ASSERT_TRUE(menu_view); |
| 51 BrowserActionsContainer* overflow_container = | 51 BrowserActionsContainer* overflow_container = |
| 52 menu_view->container_for_testing(); | 52 menu_view->container_for_testing(); |
| 53 ASSERT_TRUE(overflow_container); | 53 ASSERT_TRUE(overflow_container); |
| 54 ToolbarActionView* action_view = | 54 ToolbarActionView* action_view = |
| 55 overflow_container->GetToolbarActionViewAt(0); | 55 overflow_container->GetToolbarActionViewAt(0); |
| 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 ui_test_utils::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, | 66 void ActivateOverflowedActionWithKeyboard(Browser* browser, |
| 67 const base::Closure& closure) { | 67 const base::Closure& closure) { |
| 68 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser); | 68 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser); |
| 69 EXPECT_TRUE(app_menu_button->IsMenuShowing()); | 69 EXPECT_TRUE(app_menu_button->IsMenuShowing()); |
| 70 // We need to dispatch key events to the menu's native window, rather than the | 70 // We need to dispatch key events to the menu's native window, rather than the |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 int second_row_index = overflow_container->toolbar_actions_bar() | 120 int second_row_index = overflow_container->toolbar_actions_bar() |
| 121 ->platform_settings() | 121 ->platform_settings() |
| 122 .icons_per_overflow_menu_row; | 122 .icons_per_overflow_menu_row; |
| 123 ToolbarActionView* second_row_action = | 123 ToolbarActionView* second_row_action = |
| 124 overflow_container->GetToolbarActionViewAt(second_row_index); | 124 overflow_container->GetToolbarActionViewAt(second_row_index); |
| 125 | 125 |
| 126 EXPECT_TRUE(second_row_action->visible()); | 126 EXPECT_TRUE(second_row_action->visible()); |
| 127 EXPECT_TRUE(second_row_action->enabled()); | 127 EXPECT_TRUE(second_row_action->enabled()); |
| 128 | 128 |
| 129 gfx::Point action_view_loc = | 129 gfx::Point action_view_loc = |
| 130 test::GetCenterInScreenCoordinates(second_row_action); | 130 ui_test_utils::GetCenterInScreenCoordinates(second_row_action); |
| 131 gfx::Point action_view_loc_in_menu_item_bounds = action_view_loc; | 131 gfx::Point action_view_loc_in_menu_item_bounds = action_view_loc; |
| 132 views::View::ConvertPointFromScreen(first_menu_item, | 132 views::View::ConvertPointFromScreen(first_menu_item, |
| 133 &action_view_loc_in_menu_item_bounds); | 133 &action_view_loc_in_menu_item_bounds); |
| 134 // Regression test for crbug.com/538414: The first menu item is overlapping | 134 // Regression test for crbug.com/538414: The first menu item is overlapping |
| 135 // the second row action button. With crbug.com/538414, the click would go to | 135 // the second row action button. With crbug.com/538414, the click would go to |
| 136 // the menu button, instead of the menu item. | 136 // the menu button, instead of the menu item. |
| 137 EXPECT_TRUE( | 137 EXPECT_TRUE( |
| 138 first_menu_item->HitTestPoint(action_view_loc_in_menu_item_bounds)); | 138 first_menu_item->HitTestPoint(action_view_loc_in_menu_item_bounds)); |
| 139 | 139 |
| 140 // Click on the first menu item (which shares bounds, but overlaps, the second | 140 // Click on the first menu item (which shares bounds, but overlaps, the second |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); | 208 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); |
| 209 | 209 |
| 210 // When the extension is activated, it will send a message that its popup | 210 // When the extension is activated, it will send a message that its popup |
| 211 // opened. Listen for the message. | 211 // opened. Listen for the message. |
| 212 ExtensionTestMessageListener listener("Popup opened", false); | 212 ExtensionTestMessageListener listener("Popup opened", false); |
| 213 | 213 |
| 214 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 214 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
| 215 | 215 |
| 216 // Click on the app button. | 216 // Click on the app button. |
| 217 gfx::Point app_button_loc = | 217 gfx::Point app_button_loc = |
| 218 test::GetCenterInScreenCoordinates(app_menu_button); | 218 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
| 219 base::RunLoop loop; | 219 base::RunLoop loop; |
| 220 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 220 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
| 221 ui_controls::SendMouseEventsNotifyWhenDone( | 221 ui_controls::SendMouseEventsNotifyWhenDone( |
| 222 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 222 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
| 223 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::LEFT, | 223 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::LEFT, |
| 224 loop.QuitClosure())); | 224 loop.QuitClosure())); |
| 225 loop.Run(); | 225 loop.Run(); |
| 226 // The app menu should no longer be showing. | 226 // The app menu should no longer be showing. |
| 227 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | 227 EXPECT_FALSE(app_menu_button->IsMenuShowing()); |
| 228 | 228 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // Set a callback for the context menu showing. | 271 // Set a callback for the context menu showing. |
| 272 bool did_test_while_menu_open = false; | 272 bool did_test_while_menu_open = false; |
| 273 base::Callback<void(ToolbarActionView*)> context_menu_callback( | 273 base::Callback<void(ToolbarActionView*)> context_menu_callback( |
| 274 base::Bind(&OnContextMenuWillShow, &did_test_while_menu_open, browser())); | 274 base::Bind(&OnContextMenuWillShow, &did_test_while_menu_open, browser())); |
| 275 ToolbarActionView::set_context_menu_callback_for_testing( | 275 ToolbarActionView::set_context_menu_callback_for_testing( |
| 276 &context_menu_callback); | 276 &context_menu_callback); |
| 277 | 277 |
| 278 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 278 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
| 279 // Click on the app button, and then right-click on the first toolbar action. | 279 // Click on the app button, and then right-click on the first toolbar action. |
| 280 gfx::Point app_button_loc = | 280 gfx::Point app_button_loc = |
| 281 test::GetCenterInScreenCoordinates(app_menu_button); | 281 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
| 282 base::RunLoop loop; | 282 base::RunLoop loop; |
| 283 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 283 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
| 284 ui_controls::SendMouseEventsNotifyWhenDone( | 284 ui_controls::SendMouseEventsNotifyWhenDone( |
| 285 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 285 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
| 286 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::RIGHT, | 286 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::RIGHT, |
| 287 loop.QuitClosure())); | 287 loop.QuitClosure())); |
| 288 loop.Run(); | 288 loop.Run(); |
| 289 | 289 |
| 290 // Test is continued first in TestOverflowedToolbarAction() to right click on | 290 // Test is continued first in TestOverflowedToolbarAction() to right click on |
| 291 // the action, followed by OnContextMenuWillShow() and | 291 // the action, followed by OnContextMenuWillShow() and |
| (...skipping 24 matching lines...) Expand all Loading... |
| 316 browser_actions_container->toolbar_actions_bar(); | 316 browser_actions_container->toolbar_actions_bar(); |
| 317 ToolbarActionView* toolbar_action_view = | 317 ToolbarActionView* toolbar_action_view = |
| 318 browser_actions_container->GetToolbarActionViewAt(0); | 318 browser_actions_container->GetToolbarActionViewAt(0); |
| 319 | 319 |
| 320 // When the extension is activated, it will send a message that its popup | 320 // When the extension is activated, it will send a message that its popup |
| 321 // opened. Listen for the message. | 321 // opened. Listen for the message. |
| 322 ExtensionTestMessageListener listener("Popup opened", false); | 322 ExtensionTestMessageListener listener("Popup opened", false); |
| 323 | 323 |
| 324 // Click on the action, and wait for the popup to fully load. | 324 // Click on the action, and wait for the popup to fully load. |
| 325 EXPECT_TRUE(ui_test_utils::SendMouseMoveSync( | 325 EXPECT_TRUE(ui_test_utils::SendMouseMoveSync( |
| 326 test::GetCenterInScreenCoordinates(toolbar_action_view))); | 326 ui_test_utils::GetCenterInScreenCoordinates(toolbar_action_view))); |
| 327 | 327 |
| 328 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( | 328 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( |
| 329 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); | 329 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); |
| 330 listener.WaitUntilSatisfied(); | 330 listener.WaitUntilSatisfied(); |
| 331 | 331 |
| 332 ExtensionActionViewController* view_controller = | 332 ExtensionActionViewController* view_controller = |
| 333 static_cast<ExtensionActionViewController*>( | 333 static_cast<ExtensionActionViewController*>( |
| 334 toolbar_action_view->view_controller()); | 334 toolbar_action_view->view_controller()); |
| 335 EXPECT_EQ(view_controller, toolbar_actions_bar->popup_owner()); | 335 EXPECT_EQ(view_controller, toolbar_actions_bar->popup_owner()); |
| 336 EXPECT_TRUE(view_controller->is_showing_popup()); | 336 EXPECT_TRUE(view_controller->is_showing_popup()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Reduce visible count to 0 so that all actions are overflowed. | 380 // Reduce visible count to 0 so that all actions are overflowed. |
| 381 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); | 381 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); |
| 382 | 382 |
| 383 // Set up a listener for the extension being triggered. | 383 // Set up a listener for the extension being triggered. |
| 384 ExtensionTestMessageListener listener("Popup opened", false); | 384 ExtensionTestMessageListener listener("Popup opened", false); |
| 385 | 385 |
| 386 // Open the app menu, navigate to the toolbar action, and activate it via the | 386 // Open the app menu, navigate to the toolbar action, and activate it via the |
| 387 // keyboard. | 387 // keyboard. |
| 388 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 388 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
| 389 gfx::Point app_button_loc = | 389 gfx::Point app_button_loc = |
| 390 test::GetCenterInScreenCoordinates(app_menu_button); | 390 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
| 391 base::RunLoop loop; | 391 base::RunLoop loop; |
| 392 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 392 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
| 393 ui_controls::SendMouseEventsNotifyWhenDone( | 393 ui_controls::SendMouseEventsNotifyWhenDone( |
| 394 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 394 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
| 395 base::Bind(&ActivateOverflowedActionWithKeyboard, | 395 base::Bind(&ActivateOverflowedActionWithKeyboard, |
| 396 browser(), loop.QuitClosure())); | 396 browser(), loop.QuitClosure())); |
| 397 loop.Run(); | 397 loop.Run(); |
| 398 | 398 |
| 399 // The app menu should no longer be showing. | 399 // The app menu should no longer be showing. |
| 400 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | 400 EXPECT_FALSE(app_menu_button->IsMenuShowing()); |
| 401 // And the extension should have been activated. | 401 // And the extension should have been activated. |
| 402 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 402 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 403 } | 403 } |
| OLD | NEW |