Chromium Code Reviews| 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) |
|
alexmos
2017/04/05 00:21:13
(Carrying over the discussion from previous CL)
On
avallee
2017/04/05 15:13:00
I've fixed the test, but requires a relatively maj
alexmos
2017/04/05 18:08:33
I'm ok with that change - I think it'd be great fo
| |
| 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 // EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
|
alexmos
2017/04/05 00:21:13
nit: remove commented out line
avallee
2017/04/05 15:13:00
Done.
| |
| 443 frame_focused->Wait(); | |
| 441 | 444 |
| 442 // Tab from child2 forward to root. | 445 // Tab from child2 forward to root. |
| 443 EXPECT_EQ("\"root-focused-input2\"", | 446 EXPECT_EQ("\"root-focused-input2\"", |
| 444 click_element_and_wait_for_message(main_frame_input_coords[1])); | 447 click_element_and_wait_for_message(main_frame_input_coords[1])); |
| 445 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 448 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
| 449 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); | |
| 446 EXPECT_EQ("\"child2-focused-input2\"", | 450 EXPECT_EQ("\"child2-focused-input2\"", |
| 447 click_element_and_wait_for_message(child2_input_coords[1])); | 451 click_element_and_wait_for_message(child2_input_coords[1])); |
| 448 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 452 frame_focused->Wait(); |
| 453 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(main_frame); | |
| 449 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); | 454 EXPECT_EQ("\"root-focused-input2\"", press_tab_and_wait_for_message(false)); |
| 450 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 455 frame_focused->Wait(); |
| 451 | 456 |
| 452 // Tab forward from child1 to child2. | 457 // Tab forward from child1 to child2. |
| 458 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); | |
| 453 EXPECT_EQ("\"child2-focused-input1\"", | 459 EXPECT_EQ("\"child2-focused-input1\"", |
| 454 click_element_and_wait_for_message(child2_input_coords[0])); | 460 click_element_and_wait_for_message(child2_input_coords[0])); |
| 455 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 461 frame_focused->Wait(); |
| 462 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); | |
| 456 EXPECT_EQ("\"child1-focused-input2\"", | 463 EXPECT_EQ("\"child1-focused-input2\"", |
| 457 click_element_and_wait_for_message(child1_input_coords[1])); | 464 click_element_and_wait_for_message(child1_input_coords[1])); |
| 458 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 465 frame_focused->Wait(); |
| 466 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); | |
| 459 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); | 467 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(false)); |
| 460 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 468 frame_focused->Wait(); |
| 461 | 469 |
| 462 // Tab backward from child2 to child1. | 470 // Tab backward from child2 to child1. |
| 471 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); | |
| 463 EXPECT_EQ("\"child1-focused-input2\"", | 472 EXPECT_EQ("\"child1-focused-input2\"", |
| 464 click_element_and_wait_for_message(child1_input_coords[1])); | 473 click_element_and_wait_for_message(child1_input_coords[1])); |
| 465 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 474 frame_focused->Wait(); |
| 475 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child2); | |
| 466 EXPECT_EQ("\"child2-focused-input1\"", | 476 EXPECT_EQ("\"child2-focused-input1\"", |
| 467 click_element_and_wait_for_message(child2_input_coords[0])); | 477 click_element_and_wait_for_message(child2_input_coords[0])); |
| 468 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 478 frame_focused->Wait(); |
| 479 frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); | |
| 469 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | 480 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
| 470 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 481 // EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
| 482 frame_focused->Wait(); | |
| 471 | 483 |
| 472 // Ensure there are no pending focus events after tabbing. | 484 // Ensure there are no pending focus events after tabbing. |
| 473 EXPECT_EQ("\"root-focused-input1\"", | 485 EXPECT_EQ("\"root-focused-input1\"", |
| 474 click_element_and_wait_for_message(main_frame_input_coords[0])) | 486 click_element_and_wait_for_message(main_frame_input_coords[0])) |
| 475 << "Unexpected extra focus events."; | 487 << "Unexpected extra focus events."; |
| 476 } | 488 } |
| 489 #endif | |
| 477 | 490 |
| 478 namespace { | 491 namespace { |
| 479 | 492 |
| 480 // Helper to retrieve the frame's (window.innerWidth, window.innerHeight). | 493 // Helper to retrieve the frame's (window.innerWidth, window.innerHeight). |
| 481 gfx::Size GetFrameSize(content::RenderFrameHost* frame) { | 494 gfx::Size GetFrameSize(content::RenderFrameHost* frame) { |
| 482 int width = 0; | 495 int width = 0; |
| 483 EXPECT_TRUE(ExecuteScriptAndExtractInt( | 496 EXPECT_TRUE(ExecuteScriptAndExtractInt( |
| 484 frame, "domAutomationController.send(window.innerWidth);", &width)); | 497 frame, "domAutomationController.send(window.innerWidth);", &width)); |
| 485 | 498 |
| 486 int height = 0; | 499 int height = 0; |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 | 1346 |
| 1334 // Ideally, the length of the error vector should be 0.0f. But due to | 1347 // Ideally, the length of the error vector should be 0.0f. But due to |
| 1335 // potential rounding errors, we assume a larger limit (which is slightly | 1348 // potential rounding errors, we assume a larger limit (which is slightly |
| 1336 // larger than square root of 2). | 1349 // larger than square root of 2). |
| 1337 EXPECT_LT(error.Length(), 1.4143f) | 1350 EXPECT_LT(error.Length(), 1.4143f) |
| 1338 << "Origin of bounds from focused node changed event is '" | 1351 << "Origin of bounds from focused node changed event is '" |
| 1339 << focus_observer.focused_node_bounds_in_screen().ToString() | 1352 << focus_observer.focused_node_bounds_in_screen().ToString() |
| 1340 << "' but AutofillClient is reporting '" << bounds_origin.ToString() | 1353 << "' but AutofillClient is reporting '" << bounds_origin.ToString() |
| 1341 << "'"; | 1354 << "'"; |
| 1342 } | 1355 } |
| OLD | NEW |