| 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 12 matching lines...) Expand all Loading... |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/focused_node_details.h" | 24 #include "content/public/browser/focused_node_details.h" |
| 25 #include "content/public/browser/navigation_handle.h" | 25 #include "content/public/browser/navigation_handle.h" |
| 26 #include "content/public/browser/notification_details.h" | 26 #include "content/public/browser/notification_details.h" |
| 27 #include "content/public/browser/notification_observer.h" | 27 #include "content/public/browser/notification_observer.h" |
| 28 #include "content/public/browser/notification_registrar.h" | 28 #include "content/public/browser/notification_registrar.h" |
| 29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 30 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
| 31 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 32 #include "content/public/browser/render_widget_host.h" | 32 #include "content/public/browser/render_widget_host.h" |
| 33 #include "content/public/browser/render_widget_host_iterator.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" | 34 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
| 35 #include "content/public/test/browser_test_utils.h" | 36 #include "content/public/test/browser_test_utils.h" |
| 36 #include "content/public/test/content_browser_test_utils.h" | 37 #include "content/public/test/content_browser_test_utils.h" |
| 37 #include "content/public/test/test_navigation_observer.h" | 38 #include "content/public/test/test_navigation_observer.h" |
| 38 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
| 39 #include "extensions/browser/api/extensions_api_client.h" | 40 #include "extensions/browser/api/extensions_api_client.h" |
| 40 #include "extensions/common/constants.h" | 41 #include "extensions/common/constants.h" |
| 41 #include "net/dns/mock_host_resolver.h" | 42 #include "net/dns/mock_host_resolver.h" |
| 42 #include "net/test/embedded_test_server/embedded_test_server.h" | 43 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 43 #include "ui/base/test/ui_controls.h" | 44 #include "ui/base/test/ui_controls.h" |
| 44 #include "ui/display/display.h" | 45 #include "ui/display/display.h" |
| 45 #include "ui/display/screen.h" | 46 #include "ui/display/screen.h" |
| 46 #include "ui/gfx/geometry/point.h" | 47 #include "ui/gfx/geometry/point.h" |
| 47 #include "ui/gfx/geometry/rect.h" | 48 #include "ui/gfx/geometry/rect.h" |
| 48 #include "ui/gfx/geometry/vector2d.h" | 49 #include "ui/gfx/geometry/vector2d.h" |
| 49 #include "url/gurl.h" | 50 #include "url/gurl.h" |
| 50 | 51 |
| 51 namespace autofill { | 52 namespace autofill { |
| 52 class AutofillPopupDelegate; | 53 class AutofillPopupDelegate; |
| 53 struct Suggestion; | 54 struct Suggestion; |
| 54 } | 55 } |
| 55 | 56 |
| 57 namespace { |
| 58 |
| 59 // Counts and returns the number of RenderWidgetHosts in the browser process. |
| 60 size_t GetNumberOfRenderWidgetHosts() { |
| 61 std::unique_ptr<content::RenderWidgetHostIterator> all_widgets = |
| 62 content::RenderWidgetHost::GetRenderWidgetHosts(); |
| 63 size_t count = 0; |
| 64 while (auto* widget = all_widgets->GetNextHost()) |
| 65 count++; |
| 66 return count; |
| 67 } |
| 68 |
| 69 // Waits and polls the current number of RenderWidgetHosts and stops when the |
| 70 // number reaches |target_count|. |
| 71 void WaitForRenderWidgetHostCount(size_t target_count) { |
| 72 while (GetNumberOfRenderWidgetHosts() != target_count) { |
| 73 base::RunLoop run_loop; |
| 74 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 75 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); |
| 76 run_loop.Run(); |
| 77 } |
| 78 } |
| 79 } // namespace |
| 80 |
| 56 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { | 81 class SitePerProcessInteractiveBrowserTest : public InProcessBrowserTest { |
| 57 public: | 82 public: |
| 58 SitePerProcessInteractiveBrowserTest() {} | 83 SitePerProcessInteractiveBrowserTest() {} |
| 59 ~SitePerProcessInteractiveBrowserTest() override {} | 84 ~SitePerProcessInteractiveBrowserTest() override {} |
| 60 | 85 |
| 61 void SetUpCommandLine(base::CommandLine* command_line) override { | 86 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 62 content::IsolateAllSitesForTesting(command_line); | 87 content::IsolateAllSitesForTesting(command_line); |
| 63 } | 88 } |
| 64 | 89 |
| 65 void SetUpOnMainThread() override { | 90 void SetUpOnMainThread() override { |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 | 1357 |
| 1333 // Ideally, the length of the error vector should be 0.0f. But due to | 1358 // 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 | 1359 // potential rounding errors, we assume a larger limit (which is slightly |
| 1335 // larger than square root of 2). | 1360 // larger than square root of 2). |
| 1336 EXPECT_LT(error.Length(), 1.4143f) | 1361 EXPECT_LT(error.Length(), 1.4143f) |
| 1337 << "Origin of bounds from focused node changed event is '" | 1362 << "Origin of bounds from focused node changed event is '" |
| 1338 << focus_observer.focused_node_bounds_in_screen().ToString() | 1363 << focus_observer.focused_node_bounds_in_screen().ToString() |
| 1339 << "' but AutofillClient is reporting '" << bounds_origin.ToString() | 1364 << "' but AutofillClient is reporting '" << bounds_origin.ToString() |
| 1340 << "'"; | 1365 << "'"; |
| 1341 } | 1366 } |
| 1367 |
| 1368 // This test verifies that when clicking outside the bounds of a date picker |
| 1369 // associated with an <input> inside an OOPIF, the RenderWidgetHostImpl |
| 1370 // corresponding to the WebPagePopup is destroyed (see |
| 1371 // https://crbug.com/671732). |
| 1372 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, |
| 1373 ShowAndHideDatePopupInOOPIFMultipleTimes) { |
| 1374 GURL main_url(embedded_test_server()->GetURL( |
| 1375 "a.com", "/cross_site_iframe_factory.html?a(b)")); |
| 1376 ui_test_utils::NavigateToURL(browser(), main_url); |
| 1377 content::RenderFrameHost* child_frame = ChildFrameAt( |
| 1378 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 0); |
| 1379 |
| 1380 // Add <input type='date'> to the child frame. Adjust the positions that we |
| 1381 // know where to click to dismiss the popup. |
| 1382 ASSERT_TRUE(ExecuteScript( |
| 1383 child_frame, |
| 1384 "var input = document.createElement('input');" |
| 1385 "input.type = 'date';" |
| 1386 "input.value = '2008-09-02';" |
| 1387 "document.body.appendChild(input);" |
| 1388 "input.style = 'position: fixed; left: 0px; top: 10px; border: none;' +" |
| 1389 " 'width: 120px; height: 20px;';")); |
| 1390 |
| 1391 // Cache current date value for a sanity check later. |
| 1392 std::string cached_date; |
| 1393 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 1394 child_frame, "window.domAutomationController.send(input.value);", |
| 1395 &cached_date)); |
| 1396 |
| 1397 // We use this to determine whether a new RenderWidgetHost is created or an |
| 1398 // old one is removed. |
| 1399 size_t default_widget_count = GetNumberOfRenderWidgetHosts(); |
| 1400 |
| 1401 // Repeatedly invoke the date picker and then click outside the bounds of the |
| 1402 // widget to dismiss it and each time verify that a new RenderWidgetHost is |
| 1403 // added when showing the date picker and a RenderWidgetHost is destroyed when |
| 1404 // it is dismissed. |
| 1405 for (size_t tries = 0; tries < 3U; tries++) { |
| 1406 // Focus the <input>. |
| 1407 ASSERT_TRUE( |
| 1408 ExecuteScript(child_frame, "document.querySelector('input').focus();")); |
| 1409 |
| 1410 // Alt + Down seems to be working fine on all platforms. |
| 1411 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false, |
| 1412 false, true, false)); |
| 1413 |
| 1414 // We should get one more widget on the screen. |
| 1415 WaitForRenderWidgetHostCount(default_widget_count + 1U); |
| 1416 |
| 1417 content::RenderWidgetHost* child_widget_host = |
| 1418 child_frame->GetView()->GetRenderWidgetHost(); |
| 1419 |
| 1420 // Now simulate a click outside the bounds of the popup. |
| 1421 blink::WebMouseEvent event; |
| 1422 // Click a little bit to the right and top of the <input>. |
| 1423 event.SetPositionInWidget(130, 10); |
| 1424 event.button = blink::WebMouseEvent::Button::kLeft; |
| 1425 |
| 1426 // Send a mouse down event. |
| 1427 event.SetType(blink::WebInputEvent::kMouseDown); |
| 1428 child_widget_host->ForwardMouseEvent(event); |
| 1429 |
| 1430 base::RunLoop run_loop; |
| 1431 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 1432 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); |
| 1433 run_loop.Run(); |
| 1434 |
| 1435 // Now send a mouse up event. |
| 1436 event.SetType(blink::WebMouseEvent::kMouseUp); |
| 1437 child_widget_host->ForwardMouseEvent(event); |
| 1438 |
| 1439 // Wait until the popup disappears and we go back to the normal |
| 1440 // RenderWidgetHost count. |
| 1441 WaitForRenderWidgetHostCount(default_widget_count); |
| 1442 } |
| 1443 |
| 1444 // To make sure we never clicked into the date picker, get current date value |
| 1445 // and make sure it matches the cached value. |
| 1446 std::string date; |
| 1447 ASSERT_TRUE(ExecuteScriptAndExtractString( |
| 1448 child_frame, "window.domAutomationController.send(input.value);", &date)); |
| 1449 EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date |
| 1450 << "' but current date is '" << date << "'."; |
| 1451 } |
| OLD | NEW |