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,
const GURL sneaky_extension2_manifest(embedded_test_server()->GetURL(
"/server-redirect?" + extension2_manifest.spec()));
{
content::RenderFrameDeletedObserver frame_deleted_observer(
ChildFrameAt(main_frame, 1));
EXPECT_TRUE(ExecuteScript(
tab, base::StringPrintf("frames[1].location.href = '%s';",
sneaky_extension2_manifest.spec().c_str())));
WaitForLoadStop(tab);
EXPECT_EQ(extension1->url().Resolve("/empty.html"),
frame_deleted_observer.WaitUntilDeleted();
EXPECT_EQ(sneaky_extension2_manifest,
ChildFrameAt(main_frame, 1)->GetLastCommittedURL())
<< "The URL of frames[1] should not have changed";
EXPECT_EQ(3u, pm->GetAllFrames().size());
EXPECT_EQ(2u, pm->GetRenderFrameHostsForExtension(extension1->id()).size());
<< "The initial navigation should be allowed, but not the server "
"redirect to extension2's manifest";
EXPECT_EQ(2u, pm->GetAllFrames().size());
EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension1->id()).size());
EXPECT_EQ(1u, pm->GetRenderFrameHostsForExtension(extension2->id()).size());
}
......
......@@ -92,7 +92,7 @@ function addPromptListener(action) {
break;
case Action.CANCEL_PROMPT_AND_NAVIGATE:
// Navigate the window to trigger cancellation in the renderer.
window.location.href = "/";
setTimeout(function() { window.location.href = "/" }, 0);
break;
case Action.STASH_EVENT:
stashedEvent = e;
......
......@@ -70,6 +70,6 @@
}
</script>
</head>
<body onload="startTheTest()">
<body onload="setTimeout(startTheTest, 0);">
</body>
</html>
......@@ -723,7 +723,9 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBeforeUnloadBrowserTest,
DOMMessageQueue msg_queue;
GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
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();
// Answer the dialog and allow the navigation to proceed. Note that at this
......@@ -768,8 +770,10 @@ IN_PROC_BROWSER_TEST_F(RenderFrameHostImplBeforeUnloadBrowserTest,
DOMMessageQueue msg_queue;
GURL new_url(embedded_test_server()->GetURL("a.com", "/title1.html"));
TestNavigationManager navigation_manager(web_contents(), new_url);
EXPECT_TRUE(ExecuteScript(root->child_at(0),
"location.href = '" + new_url.spec() + "';"));
// Use ExecuteScriptAsync because a ping may arrive before the script
// execution completion notification and confuse our expectations.
ExecuteScriptAsync(root->child_at(0),
"location.href = '" + new_url.spec() + "';");
navigation_manager.WaitForNavigationFinished();
EXPECT_EQ(new_url,
root->child_at(0)->current_frame_host()->GetLastCommittedURL());
......
......@@ -1547,7 +1547,9 @@ IN_PROC_BROWSER_TEST_F(SecurityExploitBrowserTest, NonWebbyTransition) {
// Have the main frame submit a BeginNavigation IPC with a missing
// initiator.
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.
EXPECT_EQ(bad_message::RFHI_BEGIN_NAVIGATION_NON_WEBBY_TRANSITION,
......
Tests renderer: double redirection.
requested url: http://www.example.com/
requested url: http://www.example.com/2
<p>Pass</p>
Frames: 1
frameId=MainFrame
......
......@@ -13,6 +13,10 @@
// Two navigations have been scheduled while the document was loading, but
// 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/',
`<html>
<head>
......@@ -25,6 +29,8 @@
<body>http://www.example.com/1</body>
</html>`);
httpInterceptor.addResponse('http://www.example.com/1',
'<p>Fail</p>');
httpInterceptor.addResponse('http://www.example.com/2',
'<p>Pass</p>');
......
<script src="../../resources/js-test.js"></script>
<script>
function test(iframe) {
iframe.contentWindow.location.href = "resources/does-not-exist.html";
testPassed('if no crash');
}
</script>
<iframe id=testIframe onload="test(this)"></iframe>
<iframe id=testIframe></iframe>
<script>
description('Detaching a frame in beforeunload event handler should not crash.');
var testIframe = document.getElementById('testIframe');
testIframe.contentWindow.onbeforeunload = function(event) {
testIframe.parentNode.removeChild(testIframe);
event.returnValue = 'beforeunload';
}
testPassed('if no crash');
testIframe.contentWindow.location.href = "resources/does-not-exist.html";
</script>
......@@ -24,7 +24,9 @@
{
if (window.testRunner) {
// Simulate an attempt to close the window
location.href = "resources/notify-done.html";
setTimeout(function() {
location.href = "resources/notify-done.html";
}, 0);
}
}
</script>
......
<!DOCTYPE html>
<link href="empty.html" rel="import"/>
<script>
window.location.href = "javascript:'pass'";
window.onload = function() {
window.location.href = "javascript:'pass'";
}
</script>
......@@ -12,18 +12,18 @@ function runTest() {
a.location.href = " javascript: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.replace(" javascript: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 = " javascript: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')";
}
</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