Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/ui/views/toolbar/toolbar_action_view_interactive_uitest.cc

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

Powered by Google App Engine
This is Rietveld 408576698