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 // Tests the context menu of an overflowed action. | 66 // Tests the context menu of an overflowed action. |
67 void TestWhileContextMenuOpen(bool* did_test_while_menu_open, | 67 void TestWhileContextMenuOpen(bool* did_test_while_menu_open, |
68 Browser* browser, | 68 Browser* browser, |
69 ToolbarActionView* context_menu_action) { | 69 ToolbarActionView* context_menu_action) { |
70 *did_test_while_menu_open = true; | 70 *did_test_while_menu_open = true; |
(...skipping 26 matching lines...) Expand all Loading... |
97 int second_row_index = overflow_container->toolbar_actions_bar() | 97 int second_row_index = overflow_container->toolbar_actions_bar() |
98 ->platform_settings() | 98 ->platform_settings() |
99 .icons_per_overflow_menu_row; | 99 .icons_per_overflow_menu_row; |
100 ToolbarActionView* second_row_action = | 100 ToolbarActionView* second_row_action = |
101 overflow_container->GetToolbarActionViewAt(second_row_index); | 101 overflow_container->GetToolbarActionViewAt(second_row_index); |
102 | 102 |
103 EXPECT_TRUE(second_row_action->visible()); | 103 EXPECT_TRUE(second_row_action->visible()); |
104 EXPECT_TRUE(second_row_action->enabled()); | 104 EXPECT_TRUE(second_row_action->enabled()); |
105 | 105 |
106 gfx::Point action_view_loc = | 106 gfx::Point action_view_loc = |
107 test::GetCenterInScreenCoordinates(second_row_action); | 107 ui_test_utils::GetCenterInScreenCoordinates(second_row_action); |
108 gfx::Point action_view_loc_in_menu_item_bounds = action_view_loc; | 108 gfx::Point action_view_loc_in_menu_item_bounds = action_view_loc; |
109 views::View::ConvertPointFromScreen(first_menu_item, | 109 views::View::ConvertPointFromScreen(first_menu_item, |
110 &action_view_loc_in_menu_item_bounds); | 110 &action_view_loc_in_menu_item_bounds); |
111 // Regression test for crbug.com/538414: The first menu item is overlapping | 111 // Regression test for crbug.com/538414: The first menu item is overlapping |
112 // the second row action button. With crbug.com/538414, the click would go to | 112 // the second row action button. With crbug.com/538414, the click would go to |
113 // the menu button, instead of the menu item. | 113 // the menu button, instead of the menu item. |
114 EXPECT_TRUE( | 114 EXPECT_TRUE( |
115 first_menu_item->HitTestPoint(action_view_loc_in_menu_item_bounds)); | 115 first_menu_item->HitTestPoint(action_view_loc_in_menu_item_bounds)); |
116 | 116 |
117 // Click on the first menu item (which shares bounds, but overlaps, the second | 117 // 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... |
185 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); | 185 ToolbarActionsModel::Get(profile())->SetVisibleIconCount(0); |
186 | 186 |
187 // When the extension is activated, it will send a message that its popup | 187 // When the extension is activated, it will send a message that its popup |
188 // opened. Listen for the message. | 188 // opened. Listen for the message. |
189 ExtensionTestMessageListener listener("Popup opened", false); | 189 ExtensionTestMessageListener listener("Popup opened", false); |
190 | 190 |
191 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 191 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
192 | 192 |
193 // Click on the app button. | 193 // Click on the app button. |
194 gfx::Point app_button_loc = | 194 gfx::Point app_button_loc = |
195 test::GetCenterInScreenCoordinates(app_menu_button); | 195 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
196 base::RunLoop loop; | 196 base::RunLoop loop; |
197 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 197 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
198 ui_controls::SendMouseEventsNotifyWhenDone( | 198 ui_controls::SendMouseEventsNotifyWhenDone( |
199 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 199 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
200 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::LEFT, | 200 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::LEFT, |
201 loop.QuitClosure())); | 201 loop.QuitClosure())); |
202 loop.Run(); | 202 loop.Run(); |
203 // The app menu should no longer be showing. | 203 // The app menu should no longer be showing. |
204 EXPECT_FALSE(app_menu_button->IsMenuShowing()); | 204 EXPECT_FALSE(app_menu_button->IsMenuShowing()); |
205 | 205 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 // Set a callback for the context menu showing. | 248 // Set a callback for the context menu showing. |
249 bool did_test_while_menu_open = false; | 249 bool did_test_while_menu_open = false; |
250 base::Callback<void(ToolbarActionView*)> context_menu_callback( | 250 base::Callback<void(ToolbarActionView*)> context_menu_callback( |
251 base::Bind(&OnContextMenuWillShow, &did_test_while_menu_open, browser())); | 251 base::Bind(&OnContextMenuWillShow, &did_test_while_menu_open, browser())); |
252 ToolbarActionView::set_context_menu_callback_for_testing( | 252 ToolbarActionView::set_context_menu_callback_for_testing( |
253 &context_menu_callback); | 253 &context_menu_callback); |
254 | 254 |
255 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); | 255 AppMenuButton* app_menu_button = GetAppButtonFromBrowser(browser()); |
256 // Click on the app button, and then right-click on the first toolbar action. | 256 // Click on the app button, and then right-click on the first toolbar action. |
257 gfx::Point app_button_loc = | 257 gfx::Point app_button_loc = |
258 test::GetCenterInScreenCoordinates(app_menu_button); | 258 ui_test_utils::GetCenterInScreenCoordinates(app_menu_button); |
259 base::RunLoop loop; | 259 base::RunLoop loop; |
260 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); | 260 ui_controls::SendMouseMove(app_button_loc.x(), app_button_loc.y()); |
261 ui_controls::SendMouseEventsNotifyWhenDone( | 261 ui_controls::SendMouseEventsNotifyWhenDone( |
262 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 262 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
263 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::RIGHT, | 263 base::Bind(&TestOverflowedToolbarAction, browser(), ui_controls::RIGHT, |
264 loop.QuitClosure())); | 264 loop.QuitClosure())); |
265 loop.Run(); | 265 loop.Run(); |
266 | 266 |
267 // Test is continued first in TestOverflowedToolbarAction() to right click on | 267 // Test is continued first in TestOverflowedToolbarAction() to right click on |
268 // the action, followed by OnContextMenuWillShow() and | 268 // the action, followed by OnContextMenuWillShow() and |
(...skipping 24 matching lines...) Expand all Loading... |
293 browser_actions_container->toolbar_actions_bar(); | 293 browser_actions_container->toolbar_actions_bar(); |
294 ToolbarActionView* toolbar_action_view = | 294 ToolbarActionView* toolbar_action_view = |
295 browser_actions_container->GetToolbarActionViewAt(0); | 295 browser_actions_container->GetToolbarActionViewAt(0); |
296 | 296 |
297 // When the extension is activated, it will send a message that its popup | 297 // When the extension is activated, it will send a message that its popup |
298 // opened. Listen for the message. | 298 // opened. Listen for the message. |
299 ExtensionTestMessageListener listener("Popup opened", false); | 299 ExtensionTestMessageListener listener("Popup opened", false); |
300 | 300 |
301 // Click on the action, and wait for the popup to fully load. | 301 // Click on the action, and wait for the popup to fully load. |
302 EXPECT_TRUE(ui_test_utils::SendMouseMoveSync( | 302 EXPECT_TRUE(ui_test_utils::SendMouseMoveSync( |
303 test::GetCenterInScreenCoordinates(toolbar_action_view))); | 303 ui_test_utils::GetCenterInScreenCoordinates(toolbar_action_view))); |
304 | 304 |
305 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( | 305 EXPECT_TRUE(ui_test_utils::SendMouseEventsSync( |
306 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); | 306 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP)); |
307 listener.WaitUntilSatisfied(); | 307 listener.WaitUntilSatisfied(); |
308 | 308 |
309 ExtensionActionViewController* view_controller = | 309 ExtensionActionViewController* view_controller = |
310 static_cast<ExtensionActionViewController*>( | 310 static_cast<ExtensionActionViewController*>( |
311 toolbar_action_view->view_controller()); | 311 toolbar_action_view->view_controller()); |
312 EXPECT_EQ(view_controller, toolbar_actions_bar->popup_owner()); | 312 EXPECT_EQ(view_controller, toolbar_actions_bar->popup_owner()); |
313 EXPECT_TRUE(view_controller->is_showing_popup()); | 313 EXPECT_TRUE(view_controller->is_showing_popup()); |
(...skipping 16 matching lines...) Expand all Loading... |
330 | 330 |
331 EXPECT_FALSE(view_controller->is_showing_popup()); | 331 EXPECT_FALSE(view_controller->is_showing_popup()); |
332 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); | 332 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); |
333 | 333 |
334 // Releasing the mouse shouldn't result in the popup being shown again. | 334 // Releasing the mouse shouldn't result in the popup being shown again. |
335 EXPECT_TRUE( | 335 EXPECT_TRUE( |
336 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); | 336 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP)); |
337 EXPECT_FALSE(view_controller->is_showing_popup()); | 337 EXPECT_FALSE(view_controller->is_showing_popup()); |
338 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); | 338 EXPECT_EQ(nullptr, toolbar_actions_bar->popup_owner()); |
339 } | 339 } |
OLD | NEW |