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 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" |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1332 | 1333 |
| 1333 // Ideally, the length of the error vector should be 0.0f. But due to | 1334 // 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 | 1335 // potential rounding errors, we assume a larger limit (which is slightly |
| 1335 // larger than square root of 2). | 1336 // larger than square root of 2). |
| 1336 EXPECT_LT(error.Length(), 1.4143f) | 1337 EXPECT_LT(error.Length(), 1.4143f) |
| 1337 << "Origin of bounds from focused node changed event is '" | 1338 << "Origin of bounds from focused node changed event is '" |
| 1338 << focus_observer.focused_node_bounds_in_screen().ToString() | 1339 << focus_observer.focused_node_bounds_in_screen().ToString() |
| 1339 << "' but AutofillClient is reporting '" << bounds_origin.ToString() | 1340 << "' but AutofillClient is reporting '" << bounds_origin.ToString() |
| 1340 << "'"; | 1341 << "'"; |
| 1341 } | 1342 } |
| 1343 | |
| 1344 // Counts and returns the number of RenderWidgetHosts in the browser process. | |
| 1345 size_t GetNumberOfRenderWidgetHosts() { | |
|
alexmos
2017/04/18 19:59:49
Perhaps put both helpers in an anonymous namespace
EhsanK
2017/04/20 15:23:09
Done. Thanks for the suggestion.
| |
| 1346 std::unique_ptr<content::RenderWidgetHostIterator> all_widgets = | |
| 1347 content::RenderWidgetHost::GetRenderWidgetHosts(); | |
| 1348 size_t count = 0; | |
| 1349 while (auto* widget = all_widgets->GetNextHost()) | |
| 1350 count++; | |
| 1351 return count; | |
| 1352 } | |
| 1353 | |
| 1354 // Waits and polls the current number of RenderWidgetHosts and stops when the | |
| 1355 // number reaches |target_count|. | |
| 1356 void WaitForRenderWidgetHostCount(size_t target_count) { | |
| 1357 while (GetNumberOfRenderWidgetHosts() != target_count) { | |
| 1358 base::RunLoop run_loop; | |
| 1359 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1360 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); | |
| 1361 run_loop.Run(); | |
| 1362 } | |
| 1363 } | |
| 1364 | |
| 1365 // This test verifies that when clicking outside the bounds of a date picker | |
| 1366 // associated with an <input> inside an OOPIF, the RenderWidgetHostImpl | |
| 1367 // corresponding to the WebPagePopup is destroyed (see | |
| 1368 // https://crbug.com/671732). | |
| 1369 IN_PROC_BROWSER_TEST_F(SitePerProcessInteractiveBrowserTest, | |
| 1370 ShowAndHideDatePopupInOOPIFMultipleTimes) { | |
| 1371 GURL main_url(embedded_test_server()->GetURL( | |
| 1372 "a.com", "/cross_site_iframe_factory.html?a(b)")); | |
| 1373 ui_test_utils::NavigateToURL(browser(), main_url); | |
| 1374 content::RenderFrameHost* child_frame = ChildFrameAt( | |
| 1375 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), 0); | |
| 1376 | |
| 1377 // Add <input type='date'> to the child frame. Adjust the positions that we | |
| 1378 // know where to click to dismiss the popup. | |
| 1379 ASSERT_TRUE(ExecuteScript( | |
| 1380 child_frame, | |
| 1381 "var input = document.createElement('input');" | |
| 1382 "input.type = 'date';" | |
| 1383 "input.value = '2008-09-02';" | |
| 1384 "document.body.appendChild(input);" | |
| 1385 "input.style = 'position: fixed; left: 0px; top: 10px; border: none;' +" | |
| 1386 " 'width: 120px; height: 20px;';")); | |
| 1387 | |
| 1388 // Cache current date value for a sanity check later. | |
| 1389 std::string cached_date; | |
| 1390 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 1391 child_frame, "window.domAutomationController.send(input.value);", | |
| 1392 &cached_date)); | |
| 1393 | |
| 1394 // We use this to determine wether a new RenderWidgetHost is created or an old | |
|
alexmos
2017/04/18 19:59:49
nit: s/wether/whether/
EhsanK
2017/04/20 15:23:09
Thanks. Done.
| |
| 1395 // one is removed. | |
| 1396 size_t default_widget_count = GetNumberOfRenderWidgetHosts(); | |
| 1397 | |
| 1398 // Repeatedly invoke the date picker and then click outside the bounds of the | |
| 1399 // widget to dismiss it and each time verify that a new RenderWidgetHost is | |
| 1400 // added when showing the date picker and a RenderWidgetHost is destroyed when | |
| 1401 // it is dismissed. | |
| 1402 for (size_t tries = 0; tries < 3U; tries++) { | |
| 1403 // Focus the <input>. | |
| 1404 ASSERT_TRUE( | |
| 1405 ExecuteScript(child_frame, "document.querySelector('input').focus();")); | |
| 1406 | |
| 1407 // Alt + Down seems to be working fine on all platforms. | |
| 1408 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), ui::VKEY_DOWN, false, | |
| 1409 false, true, false)); | |
| 1410 | |
| 1411 // We should get one more widget on the screen. | |
| 1412 WaitForRenderWidgetHostCount(default_widget_count + 1U); | |
| 1413 | |
| 1414 content::RenderWidgetHost* child_widget_host = | |
| 1415 child_frame->GetView()->GetRenderWidgetHost(); | |
| 1416 | |
| 1417 // Now simulate a click outside the bounds of the popup. | |
| 1418 blink::WebMouseEvent event; | |
| 1419 // Click a little bit to the right and top of the <input>. | |
| 1420 event.SetPositionInWidget(130, 10); | |
| 1421 event.button = blink::WebMouseEvent::Button::kLeft; | |
| 1422 | |
| 1423 // Send a mouse down event. | |
| 1424 event.SetType(blink::WebInputEvent::kMouseDown); | |
| 1425 child_widget_host->ForwardMouseEvent(event); | |
| 1426 | |
| 1427 // Wait a tiny bit. | |
|
kenrb
2017/04/18 19:25:53
In general, comments like this that describe easy-
EhsanK
2017/04/20 15:23:09
Noted. Thanks. I think I was just writing what I w
| |
| 1428 base::RunLoop run_loop; | |
| 1429 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | |
| 1430 FROM_HERE, run_loop.QuitClosure(), TestTimeouts::tiny_timeout()); | |
| 1431 run_loop.Run(); | |
| 1432 | |
| 1433 // Now send a mouse up event. | |
| 1434 event.SetType(blink::WebMouseEvent::kMouseUp); | |
| 1435 child_widget_host->ForwardMouseEvent(event); | |
| 1436 | |
| 1437 // Wait until the popup disappears and we go back to the normal | |
| 1438 // RenderWidgetHost count. | |
| 1439 WaitForRenderWidgetHostCount(default_widget_count); | |
| 1440 } | |
| 1441 | |
| 1442 // to make sure we never clicked into the date picker, get current date value | |
|
kenrb
2017/04/18 19:25:53
nit: Capitalize start of comment.
alexmos
2017/04/18 19:59:49
nit: capitalize To
EhsanK
2017/04/20 15:23:09
Done. Thanks.
| |
| 1443 // and make sure it matches the cached value. | |
| 1444 std::string date; | |
| 1445 ASSERT_TRUE(ExecuteScriptAndExtractString( | |
| 1446 child_frame, "window.domAutomationController.send(input.value);", &date)); | |
| 1447 EXPECT_EQ(cached_date, date) << "Cached date was '" << cached_date | |
| 1448 << "' but current date is '" << date << "'."; | |
| 1449 } | |
| OLD | NEW |