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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); | 320 EXPECT_EQ("\"child2-focused-input2\"", press_tab_and_wait_for_message(true)); |
321 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); | 321 EXPECT_EQ(child2, web_contents->GetFocusedFrame()); |
322 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); | 322 EXPECT_EQ("\"child2-focused-input1\"", press_tab_and_wait_for_message(true)); |
323 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); | 323 EXPECT_EQ("\"child1-focused-input2\"", press_tab_and_wait_for_message(true)); |
324 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); | 324 EXPECT_EQ(child1, web_contents->GetFocusedFrame()); |
325 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); | 325 EXPECT_EQ("\"child1-focused-input1\"", press_tab_and_wait_for_message(true)); |
326 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); | 326 EXPECT_EQ("\"root-focused-input1\"", press_tab_and_wait_for_message(true)); |
327 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 327 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
328 } | 328 } |
329 | 329 |
330 #if (defined(OS_LINUX) && !defined(USE_OZONE)) || defined(OS_WIN) | 330 #if (defined(OS_LINUX) && !defined(USE_OZONE)) |
331 // Ensures that renderers know to advance focus to sibling frames and parent | 331 // Ensures that renderers know to advance focus to sibling frames and parent |
332 // frames in the presence of mouse click initiated focus changes. | 332 // frames in the presence of mouse click initiated focus changes. |
333 // Verifies against regression of https://crbug.com/702330 | 333 // Verifies against regression of https://crbug.com/702330 |
334 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, | 334 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
335 TabAndMouseFocusNavigation) { | 335 TabAndMouseFocusNavigation) { |
336 GURL main_url(embedded_test_server()->GetURL( | 336 GURL main_url(embedded_test_server()->GetURL( |
337 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); | 337 "a.com", "/cross_site_iframe_factory.html?a(b,c)")); |
338 ui_test_utils::NavigateToURL(browser(), main_url); | 338 ui_test_utils::NavigateToURL(browser(), main_url); |
339 | 339 |
340 content::WebContents* web_contents = | 340 content::WebContents* web_contents = |
(...skipping 19 matching lines...) Expand all Loading... |
360 // beginning and one at the end. For root frame, this means that we will | 360 // beginning and one at the end. For root frame, this means that we will |
361 // have an <input>, then two <iframe> elements, then another <input>. | 361 // have an <input>, then two <iframe> elements, then another <input>. |
362 // The script will send back the coordinates to click for each <input>, in the | 362 // The script will send back the coordinates to click for each <input>, in the |
363 // document's space. Additionally, the outer frame will return the top left | 363 // document's space. Additionally, the outer frame will return the top left |
364 // point of each <iframe> to transform the coordinates of the inner <input> | 364 // point of each <iframe> to transform the coordinates of the inner <input> |
365 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each | 365 // elements. For example, main frame: 497,18;497,185:381,59;499,59 and each |
366 // iframe: 55,18;55,67 | 366 // iframe: 55,18;55,67 |
367 std::string script = | 367 std::string script = |
368 "function onFocus(e) {" | 368 "function onFocus(e) {" |
369 " domAutomationController.setAutomationId(0);" | 369 " domAutomationController.setAutomationId(0);" |
370 " console.log(window.name + '-focused-' + e.target.id);" | |
371 " domAutomationController.send(window.name + '-focused-' + e.target.id);" | 370 " domAutomationController.send(window.name + '-focused-' + e.target.id);" |
372 "}" | 371 "}" |
373 "" | 372 "" |
374 "function getElementCoords(element) {" | 373 "function getElementCoords(element) {" |
375 " var rect = element.getBoundingClientRect();" | 374 " var rect = element.getBoundingClientRect();" |
376 " return Math.floor(rect.left + 0.5 * rect.width) +','+" | 375 " return Math.floor(rect.left + 0.5 * rect.width) +','+" |
377 " Math.floor(rect.top + 0.5 * rect.height);" | 376 " Math.floor(rect.top + 0.5 * rect.height);" |
378 "}" | 377 "}" |
379 "function getIframeCoords(element) {" | 378 "function getIframeCoords(element) {" |
380 " var rect = element.getBoundingClientRect();" | 379 " var rect = element.getBoundingClientRect();" |
381 " return Math.floor(rect.left) +','+" | 380 " return Math.floor(rect.left) +','+" |
382 " Math.floor(rect.top);" | 381 " Math.floor(rect.top);" |
383 "}" | 382 "}" |
384 "function onClick(e) {" | |
385 " console.log('Click event ' + window.name + ' at: ' + e.x + ', ' + e.y " | |
386 " + ' screen: ' + e.screenX + ', ' + e.screenY);" | |
387 "}" | |
388 "" | 383 "" |
389 "window.addEventListener('click', onClick);" | |
390 "console.log(document.location.origin);" | |
391 "document.styleSheets[0].insertRule('input {width:100%;margin:0;}', 1);" | 384 "document.styleSheets[0].insertRule('input {width:100%;margin:0;}', 1);" |
392 "document.styleSheets[0].insertRule('h2 {margin:0;}', 1);" | 385 "document.styleSheets[0].insertRule('h2 {margin:0;}', 1);" |
393 "var input1 = document.createElement('input');" | 386 "var input1 = document.createElement('input');" |
394 "input1.id = 'input1';" | 387 "input1.id = 'input1';" |
395 "input1.addEventListener('focus', onFocus, false);" | 388 "input1.addEventListener('focus', onFocus, false);" |
396 "var input2 = document.createElement('input');" | 389 "var input2 = document.createElement('input');" |
397 "input2.id = 'input2';" | 390 "input2.id = 'input2';" |
398 "input2.addEventListener('focus', onFocus, false);" | 391 "input2.addEventListener('focus', onFocus, false);" |
399 "document.body.insertBefore(input1, document.body.firstChild);" | 392 "document.body.insertBefore(input1, document.body.firstChild);" |
400 "document.body.appendChild(input2);" | 393 "document.body.appendChild(input2);" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 auto child1_input_coords = parse_points(result, iframe1_offset); | 433 auto child1_input_coords = parse_points(result, iframe1_offset); |
441 EXPECT_TRUE(ExecuteScriptAndExtractString(child2, script, &result)); | 434 EXPECT_TRUE(ExecuteScriptAndExtractString(child2, script, &result)); |
442 auto child2_input_coords = parse_points(result, iframe2_offset); | 435 auto child2_input_coords = parse_points(result, iframe2_offset); |
443 | 436 |
444 // Helper to simulate a tab press and wait for a focus message. | 437 // Helper to simulate a tab press and wait for a focus message. |
445 auto press_tab_and_wait_for_message = [web_contents](bool reverse) { | 438 auto press_tab_and_wait_for_message = [web_contents](bool reverse) { |
446 content::DOMMessageQueue msg_queue; | 439 content::DOMMessageQueue msg_queue; |
447 std::string reply; | 440 std::string reply; |
448 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, | 441 SimulateKeyPress(web_contents, ui::DomKey::TAB, ui::DomCode::TAB, |
449 ui::VKEY_TAB, false, reverse /* shift */, false, false); | 442 ui::VKEY_TAB, false, reverse /* shift */, false, false); |
450 LOG(INFO) << "Press tab"; | |
451 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); | 443 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
452 return reply; | 444 return reply; |
453 }; | 445 }; |
454 | 446 |
455 auto click_element_and_wait_for_message = | 447 auto click_element_and_wait_for_message = |
456 [web_contents](const gfx::Point& point) { | 448 [web_contents](const gfx::Point& point) { |
457 content::DOMMessageQueue msg_queue; | 449 content::DOMMessageQueue msg_queue; |
458 | 450 |
459 auto content_bounds = web_contents->GetContainerBounds(); | 451 auto content_bounds = web_contents->GetContainerBounds(); |
460 ui_controls::SendMouseMove(point.x() + content_bounds.x(), | 452 ui_controls::SendMouseMove(point.x() + content_bounds.x(), |
461 point.y() + content_bounds.y()); | 453 point.y() + content_bounds.y()); |
462 ui_controls::SendMouseClick(ui_controls::LEFT); | 454 ui_controls::SendMouseClick(ui_controls::LEFT); |
463 | 455 |
464 std::string reply; | 456 std::string reply; |
465 LOG(INFO) << "Click element"; | |
466 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); | 457 EXPECT_TRUE(msg_queue.WaitForMessage(&reply)); |
467 return reply; | 458 return reply; |
468 }; | 459 }; |
469 | 460 |
470 // Tab from child1 back to root. | 461 // Tab from child1 back to root. |
471 EXPECT_EQ("\"root-focused-input1\"", | 462 EXPECT_EQ("\"root-focused-input1\"", |
472 click_element_and_wait_for_message(main_frame_input_coords[0])); | 463 click_element_and_wait_for_message(main_frame_input_coords[0])); |
473 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); | 464 EXPECT_EQ(main_frame, web_contents->GetFocusedFrame()); |
474 auto frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); | 465 auto frame_focused = base::MakeUnique<content::FrameFocusedObserver>(child1); |
475 EXPECT_EQ("\"child1-focused-input1\"", | 466 EXPECT_EQ("\"child1-focused-input1\"", |
(...skipping 991 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1467 } | 1458 } |
1468 | 1459 |
1469 // To make sure we never clicked into the date picker, get current date value | 1460 // To make sure we never clicked into the date picker, get current date value |
1470 // and make sure it matches the cached value. | 1461 // and make sure it matches the cached value. |
1471 std::string date; | 1462 std::string date; |
1472 ASSERT_TRUE(ExecuteScriptAndExtractString( | 1463 ASSERT_TRUE(ExecuteScriptAndExtractString( |
1473 child_frame, "window.domAutomationController.send(input.value);", &date)); | 1464 child_frame, "window.domAutomationController.send(input.value);", &date)); |
1474 EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date | 1465 EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date |
1475 << "' but current date is '" << date << "'."; | 1466 << "' but current date is '" << date << "'."; |
1476 } | 1467 } |
OLD | NEW |