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