OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "base/test/scoped_feature_list.h" | 7 #include "base/test/scoped_feature_list.h" |
8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
9 #include "chrome/browser/password_manager/chrome_password_manager_client.h" | 9 #include "chrome/browser/password_manager/chrome_password_manager_client.h" |
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); | 295 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); |
296 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 296 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); |
297 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); | 297 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); |
298 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | 298 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
299 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 299 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
300 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); | 300 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); |
301 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); | 301 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); |
302 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 302 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
303 } | 303 } |
304 | 304 |
305 // TODO(https://crbug.com/702330): Enable this test. | 305 #if (defined(OS_LINUX) && !defined(USE_OZONE)) || defined(OS_WIN) |
306 // Ensures that renderers know to advance focus to sibling frames and parent | 306 // Ensures that renderers know to advance focus to sibling frames and parent |
307 // frames in the presence of mouse click initiated focus changes. | 307 // frames in the presence of mouse click initiated focus changes. |
| 308 // Verifies against regression of https://crbug.com/702330 |
308 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, | 309 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
309 DISABLED_TabAndMouseFocusNavigation) { | 310 TabAndMouseFocusNavigation) { |
310 GURL main_url(embedded_test_server()->GetURL( | 311 GURL main_url(embedded_test_server()->GetURL( |
311 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); | 312 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); |
312 ui_test_utils::NavigateToURL(browser(), main_url); | 313 ui_test_utils::NavigateToURL(browser(), main_url); |
313 | 314 |
314 content::WebContents* web_contents = | 315 content::WebContents* web_contents = |
315 browser()->tab_strip_model()->GetActiveWebContents(); | 316 browser()->tab_strip_model()->GetActiveWebContents(); |
316 | 317 |
317 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); | 318 content::RenderFrameHost* main_frame = web_contents->GetMainFrame(); |
318 content::RenderFrameHost* child1 = ChildFrameAt(main_frame, 0); | 319 content::RenderFrameHost* child1 = ChildFrameAt(main_frame, 0); |
319 ASSERT_NE(nullptr, child1); | 320 ASSERT_NE(nullptr, child1); |
320 content::RenderFrameHost* child2 = ChildFrameAt(main_frame, 1); | 321 content::RenderFrameHost* child2 = ChildFrameAt(main_frame, 1); |
321 ASSERT_NE(nullptr, child2); | 322 ASSERT_NE(nullptr, child2); |
322 | 323 |
| 324 // Needed to avoid flakiness with --enable-browser-side-navigation. |
| 325 content::WaitForChildFrameSurfaceReady(child1); |
| 326 content::WaitForChildFrameSurfaceReady(child2); |
| 327 |
323 // Assign a name to each frame. This will be sent along in test messages | 328 // Assign a name to each frame. This will be sent along in test messages |
324 // from focus events. | 329 // from focus events. |
325 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); | 330 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); |
326 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); | 331 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); |
327 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); | 332 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); |
328 | 333 |
329 // This script will insert two <input> fields in the document, one at the | 334 // This script will insert two <input> fields in the document, one at the |
330 // beginning and one at the end. For root frame, this means that we will | 335 // beginning and one at the end. For root frame, this means that we will |
331 // have an <input>, then two <iframe> elements, then another <input>. | 336 // have an <input>, then two <iframe> elements, then another <input>. |
332 // The script will send back the coordinates to click for each <input>, in the | 337 // The script will send back the coordinates to click for each <input>, in the |
333 // document's space. Additionally, the outer frame will return the top left | 338 // document's space. Additionally, the outer frame will return the top left |
334 // point of each <iframe> to transform the coordinates of the inner <input> | 339 // point of each <iframe> to transform the coordinates of the inner <input> |
335 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each | 340 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each |
336 // iframe: 55,18;55,67 | 341 // iframe: 55,18;55,67 |
337 std::string script = | 342 std::string script = |
338 "function onFocus(e) {" | 343 "function onFocus(e) {" |
339 " console.log(window.name+'-focused-'+ e.target.id);" | |
340 " domAutomationController.setAutomationId(0);" | 344 " domAutomationController.setAutomationId(0);" |
341 " domAutomationController.send(window.name + '-focused-' + e.target.id);" | 345 " domAutomationController.send(window.name + '-focused-' + e.target.id);" |
342 "}" | 346 "}" |
343 "" | 347 "" |
344 "function getElementCoords(element) {" | 348 "function getElementCoords(element) {" |
345 " var rect = element.getBoundingClientRect();" | 349 " var rect = element.getBoundingClientRect();" |
346 " return Math.floor(rect.left + 0.5 * rect.width) +','+" | 350 " return Math.floor(rect.left + 0.5 * rect.width) +','+" |
347 " Math.floor(rect.top + 0.5 * rect.height);" | 351 " Math.floor(rect.top + 0.5 * rect.height);" |
348 "}" | 352 "}" |
349 "function getIframeCoords(element) {" | 353 "function getIframeCoords(element) {" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 430 |
427 std::string reply; | 431 std::string reply; |
428 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); | 432 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
429 return reply; | 433 return reply; |
430 }; | 434 }; |
431 | 435 |
432 // Tab from child1 back to root. | 436 // Tab from child1 back to root. |
433 EXPECT_EQ("\"root-focused-input1\"", | 437 EXPECT_EQ("\"root-focused-input1\"", |
434 click_element_and_wait_for_message(main_frame_input_coords[0])); | 438 click_element_and_wait_for_message(main_frame_input_coords[0])); |
435 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 439 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 440 auto frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
436 EXPECT_EQ("\"child1-focused-input1\"", | 441 EXPECT_EQ("\"child1-focused-input1\"", |
437 click_element_and_wait_for_message(child1_input_coords[0])); | 442 click_element_and_wait_for_message(child1_input_coords[0])); |
438 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 443 frame_focused->Wait(); |
| 444 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(main_frame); |
439 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); | 445 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); |
440 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 446 frame_focused->Wait(); |
441 | 447 |
442 // Tab from child2 forward to root. | 448 // Tab from child2 forward to root. |
443 EXPECT_EQ("\"root-focused-input2\"", | 449 EXPECT_EQ("\"root-focused-input2\"", |
444 click_element_and_wait_for_message(main_frame_input_coords[1])); | 450 click_element_and_wait_for_message(main_frame_input_coords[1])); |
445 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 451 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 452 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
446 EXPECT_EQ("\"child2-focused-input2\"", | 453 EXPECT_EQ("\"child2-focused-input2\"", |
447 click_element_and_wait_for_message(child2_input_coords[1])); | 454 click_element_and_wait_for_message(child2_input_coords[1])); |
448 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 455 frame_focused->Wait(); |
| 456 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(main_frame); |
449 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); | 457 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); |
450 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 458 frame_focused->Wait(); |
451 | 459 |
452 // Tab forward from child1 to child2. | 460 // Tab forward from child1 to child2. |
| 461 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
453 EXPECT_EQ("\"child2-focused-input1\"", | 462 EXPECT_EQ("\"child2-focused-input1\"", |
454 click_element_and_wait_for_message(child2_input_coords[0])); | 463 click_element_and_wait_for_message(child2_input_coords[0])); |
455 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 464 frame_focused->Wait(); |
| 465 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
456 EXPECT_EQ("\"child1-focused-input2\"", | 466 EXPECT_EQ("\"child1-focused-input2\"", |
457 click_element_and_wait_for_message(child1_input_coords[1])); | 467 click_element_and_wait_for_message(child1_input_coords[1])); |
458 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 468 frame_focused->Wait(); |
| 469 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
459 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); | 470 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); |
460 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 471 frame_focused->Wait(); |
461 | 472 |
462 // Tab backward from child2 to child1. | 473 // Tab backward from child2 to child1. |
| 474 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
463 EXPECT_EQ("\"child1-focused-input2\"", | 475 EXPECT_EQ("\"child1-focused-input2\"", |
464 click_element_and_wait_for_message(child1_input_coords[1])); | 476 click_element_and_wait_for_message(child1_input_coords[1])); |
465 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 477 frame_focused->Wait(); |
| 478 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
466 EXPECT_EQ("\"child2-focused-input1\"", | 479 EXPECT_EQ("\"child2-focused-input1\"", |
467 click_element_and_wait_for_message(child2_input_coords[0])); | 480 click_element_and_wait_for_message(child2_input_coords[0])); |
468 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 481 frame_focused->Wait(); |
| 482 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
469 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | 483 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
470 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 484 // EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
| 485 frame_focused->Wait(); |
471 | 486 |
472 // Ensure there are no pending focus events after tabbing. | 487 // Ensure there are no pending focus events after tabbing. |
473 EXPECT_EQ("\"root-focused-input1\"", | 488 EXPECT_EQ("\"root-focused-input1\"", |
474 click_element_and_wait_for_message(main_frame_input_coords[0])) | 489 click_element_and_wait_for_message(main_frame_input_coords[0])) |
475 << "Unexpected extra focus events."; | 490 << "Unexpected extra focus events."; |
476 } | 491 } |
| 492 #endif |
477 | 493 |
478 namespace { | 494 namespace { |
479 | 495 |
480 // Helper to retrieve the frame's (window.innerWidth, window.innerHeight). | 496 // Helper to retrieve the frame's (window.innerWidth, window.innerHeight). |
481 gfx::Size GetFrameSize(content::RenderFrameHost* frame) { | 497 gfx::Size GetFrameSize(content::RenderFrameHost* frame) { |
482 int width = 0; | 498 int width = 0; |
483 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 499 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
484 frame, "domAutomationController.send(window.innerWidth);", &width)); | 500 frame, "domAutomationController.send(window.innerWidth);", &width)); |
485 | 501 |
486 int height = 0; | 502 int height = 0; |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 | 1348 |
1333 // Ideally, the length of the error vector should be 0.0f. But due to | 1349 // Ideally, the length of the error vector should be 0.0f. But due to |
1334 // potential rounding errors, we assume a larger limit (which is slightly | 1350 // potential rounding errors, we assume a larger limit (which is slightly |
1335 // larger than square root of 2). | 1351 // larger than square root of 2). |
1336 EXPECT_LT(error.Length(), 1.4143f) | 1352 EXPECT_LT(error.Length(), 1.4143f) |
1337 << "Origin of bounds from focused node changed event is '" | 1353 << "Origin of bounds from focused node changed event is '" |
1338 << focus_observer.focused_node_bounds_in_screen().ToString() | 1354 << focus_observer.focused_node_bounds_in_screen().ToString() |
1339 << "' but AutofillClient is reporting '" << bounds_origin.ToString() | 1355 << "' but AutofillClient is reporting '" << bounds_origin.ToString() |
1340 << "'"; | 1356 << "'"; |
1341 } | 1357 } |
OLD | NEW |