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 |
323 // Assign a name to each frame. This will be sent along in test messages | 324 // Assign a name to each frame. This will be sent along in test messages |
324 // from focus events. | 325 // from focus events. |
325 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); | 326 EXPECT_TRUE(ExecuteScript(main_frame, "window.name = 'root';")); |
326 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); | 327 EXPECT_TRUE(ExecuteScript(child1, "window.name = 'child1';")); |
327 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); | 328 EXPECT_TRUE(ExecuteScript(child2, "window.name = 'child2';")); |
328 | 329 |
329 // This script will insert two <input> fields in the document, one at the | 330 // 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 | 331 // 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>. | 332 // 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 | 333 // 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 | 334 // 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> | 335 // 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 | 336 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each |
336 // iframe: 55,18;55,67 | 337 // iframe: 55,18;55,67 |
337 std::string script = | 338 std::string script = |
338 "function onFocus(e) {" | 339 "function onFocus(e) {" |
339 " console.log(window.name+'-focused-'+ e.target.id);" | |
340 " domAutomationController.setAutomationId(0);" | 340 " domAutomationController.setAutomationId(0);" |
341 " domAutomationController.send(window.name + '-focused-' + e.target.id);" | 341 " domAutomationController.send(window.name + '-focused-' + e.target.id);" |
342 "}" | 342 "}" |
343 "" | 343 "" |
344 "function getElementCoords(element) {" | 344 "function getElementCoords(element) {" |
345 " var rect = element.getBoundingClientRect();" | 345 " var rect = element.getBoundingClientRect();" |
346 " return Math.floor(rect.left + 0.5 * rect.width) +','+" | 346 " return Math.floor(rect.left + 0.5 * rect.width) +','+" |
347 " Math.floor(rect.top + 0.5 * rect.height);" | 347 " Math.floor(rect.top + 0.5 * rect.height);" |
348 "}" | 348 "}" |
349 "function getIframeCoords(element) {" | 349 "function getIframeCoords(element) {" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 426 |
427 std::string reply; | 427 std::string reply; |
428 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); | 428 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
429 return reply; | 429 return reply; |
430 }; | 430 }; |
431 | 431 |
432 // Tab from child1 back to root. | 432 // Tab from child1 back to root. |
433 EXPECT_EQ("\"root-focused-input1\"", | 433 EXPECT_EQ("\"root-focused-input1\"", |
434 click_element_and_wait_for_message(main_frame_input_coords[0])); | 434 click_element_and_wait_for_message(main_frame_input_coords[0])); |
435 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 435 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 436 auto frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
436 EXPECT_EQ("\"child1-focused-input1\"", | 437 EXPECT_EQ("\"child1-focused-input1\"", |
437 click_element_and_wait_for_message(child1_input_coords[0])); | 438 click_element_and_wait_for_message(child1_input_coords[0])); |
438 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 439 frame_focused->Wait(); |
| 440 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(main_frame); |
439 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); | 441 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); |
440 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 442 frame_focused->Wait(); |
441 | 443 |
442 // Tab from child2 forward to root. | 444 // Tab from child2 forward to root. |
443 EXPECT_EQ("\"root-focused-input2\"", | 445 EXPECT_EQ("\"root-focused-input2\"", |
444 click_element_and_wait_for_message(main_frame_input_coords[1])); | 446 click_element_and_wait_for_message(main_frame_input_coords[1])); |
445 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 447 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 448 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
446 EXPECT_EQ("\"child2-focused-input2\"", | 449 EXPECT_EQ("\"child2-focused-input2\"", |
447 click_element_and_wait_for_message(child2_input_coords[1])); | 450 click_element_and_wait_for_message(child2_input_coords[1])); |
448 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 451 frame_focused->Wait(); |
| 452 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(main_frame); |
449 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); | 453 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); |
450 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 454 frame_focused->Wait(); |
451 | 455 |
452 // Tab forward from child1 to child2. | 456 // Tab forward from child1 to child2. |
| 457 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
453 EXPECT_EQ("\"child2-focused-input1\"", | 458 EXPECT_EQ("\"child2-focused-input1\"", |
454 click_element_and_wait_for_message(child2_input_coords[0])); | 459 click_element_and_wait_for_message(child2_input_coords[0])); |
455 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 460 frame_focused->Wait(); |
| 461 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
456 EXPECT_EQ("\"child1-focused-input2\"", | 462 EXPECT_EQ("\"child1-focused-input2\"", |
457 click_element_and_wait_for_message(child1_input_coords[1])); | 463 click_element_and_wait_for_message(child1_input_coords[1])); |
458 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 464 frame_focused->Wait(); |
| 465 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
459 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); | 466 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); |
460 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 467 frame_focused->Wait(); |
461 | 468 |
462 // Tab backward from child2 to child1. | 469 // Tab backward from child2 to child1. |
| 470 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
463 EXPECT_EQ("\"child1-focused-input2\"", | 471 EXPECT_EQ("\"child1-focused-input2\"", |
464 click_element_and_wait_for_message(child1_input_coords[1])); | 472 click_element_and_wait_for_message(child1_input_coords[1])); |
465 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 473 frame_focused->Wait(); |
| 474 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); |
466 EXPECT_EQ("\"child2-focused-input1\"", | 475 EXPECT_EQ("\"child2-focused-input1\"", |
467 click_element_and_wait_for_message(child2_input_coords[0])); | 476 click_element_and_wait_for_message(child2_input_coords[0])); |
468 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 477 frame_focused->Wait(); |
| 478 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
469 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | 479 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
470 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 480 // EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
| 481 frame_focused->Wait(); |
471 | 482 |
472 // Ensure there are no pending focus events after tabbing. | 483 // Ensure there are no pending focus events after tabbing. |
473 EXPECT_EQ("\"root-focused-input1\"", | 484 EXPECT_EQ("\"root-focused-input1\"", |
474 click_element_and_wait_for_message(main_frame_input_coords[0])) | 485 click_element_and_wait_for_message(main_frame_input_coords[0])) |
475 << "Unexpected extra focus events."; | 486 << "Unexpected extra focus events."; |
476 } | 487 } |
| 488 #endif |
477 | 489 |
478 namespace { | 490 namespace { |
479 | 491 |
480 // Helper to retrieve the frame's (window.innerWidth, window.innerHeight). | 492 // Helper to retrieve the frame's (window.innerWidth, window.innerHeight). |
481 gfx::Size GetFrameSize(content::RenderFrameHost* frame) { | 493 gfx::Size GetFrameSize(content::RenderFrameHost* frame) { |
482 int width = 0; | 494 int width = 0; |
483 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 495 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
484 frame, "domAutomationController.send(window.innerWidth);", &width)); | 496 frame, "domAutomationController.send(window.innerWidth);", &width)); |
485 | 497 |
486 int height = 0; | 498 int height = 0; |
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1332 | 1344 |
1333 // Ideally, the length of the error vector should be 0.0f. But due to | 1345 // 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 | 1346 // potential rounding errors, we assume a larger limit (which is slightly |
1335 // larger than square root of 2). | 1347 // larger than square root of 2). |
1336 EXPECT_LT(error.Length(), 1.4143f) | 1348 EXPECT_LT(error.Length(), 1.4143f) |
1337 << "Origin of bounds from focused node changed event is '" | 1349 << "Origin of bounds from focused node changed event is '" |
1338 << focus_observer.focused_node_bounds_in_screen().ToString() | 1350 << focus_observer.focused_node_bounds_in_screen().ToString() |
1339 << "' but AutofillClient is reporting '" << bounds_origin.ToString() | 1351 << "' but AutofillClient is reporting '" << bounds_origin.ToString() |
1340 << "'"; | 1352 << "'"; |
1341 } | 1353 } |
OLD | NEW |