Commit e6fd9fbe authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Update tests in preparation for making location API navigations start synchronously

A bunch of tests need to be updated for a behavior change in
https://chromium-review.googlesource.com/c/chromium/src/+/1526426
These are the ones where the updated test passes before and after the
behavior change.

Bug: 914587
Change-Id: Ic8b34c4c205ea2f9bf59b620ca6baac47cd7b1ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1576025Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#652884}
parent 747ce67e
...@@ -1479,15 +1479,19 @@ IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest, ...@@ -1479,15 +1479,19 @@ IN_PROC_BROWSER_TEST_F(ProcessManagerBrowserTest,
const GURL sneaky_extension2_manifest(embedded_test_server()->GetURL( const GURL sneaky_extension2_manifest(embedded_test_server()->GetURL(
"/server-redirect?" + extension2_manifest.spec())); "/server-redirect?" + extension2_manifest.spec()));
{ {
content::RenderFrameDeletedObserver frame_deleted_observer(
ChildFrameAt(main_frame, 1));
EXPECT_TRUE(ExecuteScript( EXPECT_TRUE(ExecuteScript(
tab, base::StringPrintf("frames[1].location.href = '%s';", tab, base::StringPrintf("frames[1].location.href = '%s';",
sneaky_extension2_manifest.spec().c_str()))); sneaky_extension2_manifest.spec().c_str())));
WaitForLoadStop(tab); WaitForLoadStop(tab);
EXPECT_EQ(extension1->url().Resolve("/empty.html"), frame_deleted_observer.WaitUntilDeleted();
EXPECT_EQ(sneaky_extension2_manifest,
ChildFrameAt(main_frame, 1)->GetLastCommittedURL()) ChildFrameAt(main_frame, 1)->GetLastCommittedURL())
<< "The URL of frames[1] should not have changed"; << "The initial navigation should be allowed, but not the server "
EXPECT_EQ(3u, pm->GetAllFrames().size()); "redirect to extension2's manifest";
EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size()); EXPECT_EQ(2u, pm->GetAllFrames().size());
EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size());
EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size()); EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size());
} }
......
...@@ -92,7 +92,7 @@ function addPromptListener(action) { ...@@ -92,7 +92,7 @@ function addPromptListener(action) {
break; break;
case Action.CANCEL_PROMPT_AND_NAVIGATE: case Action.CANCEL_PROMPT_AND_NAVIGATE:
// Navigate the window to trigger cancellation in the renderer. // Navigate the window to trigger cancellation in the renderer.
window.location.href = "/"; setTimeout(function() { window.location.href = "/" }, 0);
break; break;
case Action.STASH_EVENT: case Action.STASH_EVENT:
stashedEvent = e; stashedEvent = e;
......
...@@ -70,6 +70,6 @@ ...@@ -70,6 +70,6 @@
} }
</script> </script>
</head> </head>
<body onload="startTheTest()"> <body onload="setTimeout(startTheTest, 0);">
</body> </body>
</html> </html>
...@@ -723,7 +723,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBeforeUnloadBrowserTest, ...@@ -723,7 +723,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBeforeUnloadBrowserTest,
DOMMessageQueue msg_queue; DOMMessageQueue msg_queue;
GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html")); GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
TestNavigationManager navigation_manager(web_contents(), new_url); TestNavigationManager navigation_manager(web_contents(), new_url);
EXPECT_TRUE(ExecuteScript(root, "location.href = '" + new_url.spec() + "';")); // Use ExecuteScriptAsync because a ping may arrive before the script
// execution completion notification and confuse our expectations.
ExecuteScriptAsync(root, "location.href = '" + new_url.spec() + "';");
dialog_manager()->Wait(); dialog_manager()->Wait();
// Answer the dialog and allow the navigation to proceed. Note that at this // Answer the dialog and allow the navigation to proceed. Note that at this
...@@ -768,8 +770,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBeforeUnloadBrowserTest, ...@@ -768,8 +770,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBeforeUnloadBrowserTest,
DOMMessageQueue msg_queue; DOMMessageQueue msg_queue;
GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html")); GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
TestNavigationManager navigation_manager(web_contents(), new_url); TestNavigationManager navigation_manager(web_contents(), new_url);
EXPECT_TRUE(ExecuteScript(root->child_at(0), // Use ExecuteScriptAsync because a ping may arrive before the script
"location.href = '" + new_url.spec() + "';")); // execution completion notification and confuse our expectations.
ExecuteScriptAsync(root->child_at(0),
"location.href = '" + new_url.spec() + "';");
navigation_manager.WaitForNavigationFinished(); navigation_manager.WaitForNavigationFinished();
EXPECT_EQ(new_url, EXPECT_EQ(new_url,
root->child_at(0)->current_frame_host()->GetLastCommittedURL()); root->child_at(0)->current_frame_host()->GetLastCommittedURL());
......
...@@ -1547,7 +1547,9 @@ IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, NonWebbyTransition) { ...@@ -1547,7 +1547,9 @@ IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, NonWebbyTransition) {
// Have the main frame submit a BeginNavigation IPC with a missing // Have the main frame submit a BeginNavigation IPC with a missing
// initiator. // initiator.
injector.Activate(); injector.Activate();
EXPECT_TRUE(ExecJs(web_contents, "window.location = '/title2.html';")); // Don't expect a response for the script, as the process may be killed
// before the script sends its completion message.
ExecuteScriptAsync(web_contents, "window.location = '/title2.html';");
// Verify that the renderer was terminated. // Verify that the renderer was terminated.
EXPECT_EQ(bad_message::RFHI_BEGIN_NAVIGATION_NON_WEBBY_TRANSITION, EXPECT_EQ(bad_message::RFHI_BEGIN_NAVIGATION_NON_WEBBY_TRANSITION,
......
Tests renderer: double redirection. Tests renderer: double redirection.
requested url: http://www.example.com/
requested url: http://www.example.com/2
<p>Pass</p> <p>Pass</p>
Frames: 1 Frames: 1
frameId=MainFrame frameId=MainFrame
......
...@@ -13,6 +13,10 @@ ...@@ -13,6 +13,10 @@
// Two navigations have been scheduled while the document was loading, but // Two navigations have been scheduled while the document was loading, but
// only the second one was started. It canceled the first one. // only the second one was started. It canceled the first one.
// Disable requested url logging because it is timing-dependent whether the
// first load will reach the interceptor or not. The important thing is
// that the final result shows the second url.
httpInterceptor.setDisableRequestedUrlsLogging(true);
httpInterceptor.addResponse('http://www.example.com/', httpInterceptor.addResponse('http://www.example.com/',
`<html> `<html>
<head> <head>
...@@ -25,6 +29,8 @@ ...@@ -25,6 +29,8 @@
<body>http://www.example.com/1</body> <body>http://www.example.com/1</body>
</html>`); </html>`);
httpInterceptor.addResponse('http://www.example.com/1',
'<p>Fail</p>');
httpInterceptor.addResponse('http://www.example.com/2', httpInterceptor.addResponse('http://www.example.com/2',
'<p>Pass</p>'); '<p>Pass</p>');
......
<script src="../../resources/js-test.js"></script> <script src="../../resources/js-test.js"></script>
<script> <iframe id=testIframe></iframe>
function test(iframe) {
iframe.contentWindow.location.href = "resources/does-not-exist.html";
testPassed('if no crash');
}
</script>
<iframe id=testIframe onload="test(this)"></iframe>
<script> <script>
description('Detaching a frame in beforeunload event handler should not crash.'); description('Detaching a frame in beforeunload event handler should not crash.');
var testIframe = document.getElementById('testIframe');
testIframe.contentWindow.onbeforeunload = function(event) { testIframe.contentWindow.onbeforeunload = function(event) {
testIframe.parentNode.removeChild(testIframe); testIframe.parentNode.removeChild(testIframe);
event.returnValue = 'beforeunload'; event.returnValue = 'beforeunload';
} }
testPassed('if no crash');
testIframe.contentWindow.location.href = "resources/does-not-exist.html";
</script> </script>
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
{ {
if (window.testRunner) { if (window.testRunner) {
// Simulate an attempt to close the window // Simulate an attempt to close the window
location.href = "resources/notify-done.html"; setTimeout(function() {
location.href = "resources/notify-done.html";
}, 0);
} }
} }
</script> </script>
......
<!DOCTYPE html> <!DOCTYPE html>
<link href="empty.html" rel="import"/> <link href="empty.html" rel="import"/>
<script> <script>
window.location.href = "javascript:'pass'"; window.onload = function() {
window.location.href = "javascript:'pass'";
}
</script> </script>
...@@ -12,18 +12,18 @@ function runTest() { ...@@ -12,18 +12,18 @@ function runTest() {
a.location.href = " javascript:document.write('FAIL')"; a.location.href = " javascript:document.write('FAIL')";
a.location.href = "javascript\t:document.write('FAIL')"; a.location.href = "javascript\t:document.write('FAIL')";
a.location.href = "javascript\1:document.write('FAIL')"; try { a.location.href = "javascript\1:document.write('FAIL')"; } catch(e) {}
a.location.href = "javascript:document.write('FAIL')"; a.location.href = "javascript:document.write('FAIL')";
a.location.replace(" javascript:document.write('FAIL')"); a.location.replace(" javascript:document.write('FAIL')");
a.location.replace("javascript\t:document.write('FAIL')"); a.location.replace("javascript\t:document.write('FAIL')");
a.location.replace("javascript\1:document.write('FAIL')"); try { a.location.replace("javascript\1:document.write('FAIL')"); } catch(e) {}
a.location.replace("javascript:document.write('FAIL')"); a.location.replace("javascript:document.write('FAIL')");
a.location = " javascript:document.write('FAIL')"; a.location = " javascript:document.write('FAIL')";
a.location = "javascript\t:document.write('FAIL')"; a.location = "javascript\t:document.write('FAIL')";
a.location = "javascript\1:document.write('FAIL')"; try { a.location = "javascript\1:document.write('FAIL')"; } catch(e) {}
a.location = "javascript:document.write('FAIL')"; a.location = "javascript:document.write('FAIL')";
} }
</script> </script>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment