Bug 1787315, starting a new load after reload() should take precedence, r=peterv,ochameau

The devtools test reloads a page twice in a row and depending on timing it isn't guaranteed that it leads to two requests anymore.
That test seems to fail on debug builds every now and then. The test itself expects 1 or more requests, but then assumes later that there
are at least 2.

Differential Revision: https://phabricator.services.mozilla.com/D160573
This commit is contained in:
Olli Pettay 2022-11-04 10:29:54 +00:00
parent 6454294d92
commit 549492fdf4
5 changed files with 78 additions and 10 deletions

View file

@ -91,15 +91,17 @@ async function testManyReloads({ tab, monitor, toolbox }) {
);
// Requests may come out of order, so try to find the bogus cancelled request
let entry = har.log.entries.find(e => e.response.status == 0);
ok(entry, "Found the cancelled request");
is(entry.request.method, "GET", "Method is set");
is(entry.request.url, SIMPLE_URL, "URL is set");
// We always get the following headers:
// "Host", "User-agent", "Accept", "Accept-Language", "Accept-Encoding", "Connection"
// but are missing the three last headers:
// "Upgrade-Insecure-Requests", "Pragma", "Cache-Control"
is(entry.request.headers.length, 6, "But headers are partialy populated");
is(entry.response.status, 0, "And status is set to 0");
if (entry) {
ok(entry, "Found the cancelled request");
is(entry.request.method, "GET", "Method is set");
is(entry.request.url, SIMPLE_URL, "URL is set");
// We always get the following headers:
// "Host", "User-agent", "Accept", "Accept-Language", "Accept-Encoding", "Connection"
// but are missing the three last headers:
// "Upgrade-Insecure-Requests", "Pragma", "Cache-Control"
is(entry.request.headers.length, 6, "But headers are partialy populated");
is(entry.response.status, 0, "And status is set to 0");
}
entry = har.log.entries.find(e => e.response.status != 0);
assertNavigationRequestEntry(entry);

View file

@ -4122,12 +4122,29 @@ nsDocShell::Reload(uint32_t aReloadFlags) {
RefPtr<BrowsingContext> browsingContext(mBrowsingContext);
nsCOMPtr<nsIURI> currentURI(mCurrentURI);
nsCOMPtr<nsIReferrerInfo> referrerInfo(mReferrerInfo);
RefPtr<StopDetector> stopDetector = new StopDetector();
nsCOMPtr<nsILoadGroup> loadGroup;
GetLoadGroup(getter_AddRefs(loadGroup));
if (loadGroup) {
// loadGroup may be null in theory. In that case stopDetector just
// doesn't do anything.
loadGroup->AddRequest(stopDetector, nullptr);
}
ContentChild::GetSingleton()->SendNotifyOnHistoryReload(
mBrowsingContext, forceReload,
[docShell, doc, loadType, browsingContext, currentURI, referrerInfo](
[docShell, doc, loadType, browsingContext, currentURI, referrerInfo,
loadGroup, stopDetector](
Tuple<bool, Maybe<RefPtr<nsDocShellLoadState>>, Maybe<bool>>&&
aResult) {
auto scopeExit = MakeScopeExit([loadGroup, stopDetector]() {
if (loadGroup) {
loadGroup->RemoveRequest(stopDetector, nullptr, NS_OK);
}
});
if (stopDetector->Canceled()) {
return;
}
bool canReload;
Maybe<RefPtr<nsDocShellLoadState>> loadState;
Maybe<bool> reloadingActiveEntry;

View file

@ -0,0 +1,12 @@
<!DOCTYPE HTML>
<html>
<head>
<script>
function notifyOpener() {
opener.postMessage("loaded", "*");
}
</script>
</head>
<body onload="notifyOpener()">
</body>
</html>

View file

@ -155,6 +155,8 @@ support-files =
[test_forceinheritprincipal_overrule_owner.html]
[test_framedhistoryframes.html]
support-files = file_framedhistoryframes.html
[test_load_during_reload.html]
support-files = file_load_during_reload.html
[test_pushState_after_document_open.html]
[test_navigate_after_pagehide.html]
[test_redirect_history.html]

View file

@ -0,0 +1,35 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test loading a new page after calling reload()</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css"/>
<script>
function promiseForLoad() {
return new Promise(resolve => {
addEventListener("message", resolve, { once: true });
});
}
add_task(async function runTest() {
let win = window.open("file_load_during_reload.html");
await promiseForLoad();
win.location.reload();
win.location.href = "file_load_during_reload.html?nextpage";
await promiseForLoad();
ok(win.location.href.includes("nextpage"), "Should have loaded the next page.");
win.close();
});
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test"></pre>
</body>
</html>