forked from mirrors/gecko-dev
Bug 1598513. Apply the same polling fixes as in bug 1605807 but to this test. r=kmag
Differential Revision: https://phabricator.services.mozilla.com/D60346 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
745c94b1df
commit
ebbddce5e1
1 changed files with 45 additions and 17 deletions
|
|
@ -16,31 +16,57 @@ var faultyURL = "http://some-nonexistent-domain-27489274c892748217cn2384.com/";
|
||||||
var w = null;
|
var w = null;
|
||||||
var phase = 0;
|
var phase = 0;
|
||||||
var isWindowLoaded = false;
|
var isWindowLoaded = false;
|
||||||
|
// Token that represents which page we currently have loaded.
|
||||||
|
var token = 0;
|
||||||
|
|
||||||
function delay(msec) {
|
function delay(msec) {
|
||||||
return new Promise(resolve => setTimeout(resolve, msec));
|
return new Promise(resolve => setTimeout(resolve, msec));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function pollForPage(expectErrorPage, win) {
|
async function assignToken(tokenToAssign) {
|
||||||
// Start with polling after a delay, we might mistakenly take the current page
|
await SpecialPowers.spawn(w, [tokenToAssign],
|
||||||
// as an expected one.
|
newToken => { this.content.token = newToken });
|
||||||
await delay(1000);
|
}
|
||||||
|
|
||||||
for (let i = 0; i < 200; i++) {
|
// Returns when a new page is loaded and returns whether that page is an
|
||||||
await delay(100);
|
// error page.
|
||||||
|
async function pollForPage(win) {
|
||||||
let haveErrorPage = false;
|
while (true) {
|
||||||
try {
|
try {
|
||||||
win.document.title;
|
// When we do our navigation, there may be an interstitial about:blank
|
||||||
} catch (ex) {
|
// page if the navigation involves a process switch. That about:blank
|
||||||
haveErrorPage = true;
|
// will exist between the new process's docshell being created and the
|
||||||
|
// actual page that's being loaded loading (which can happen async from
|
||||||
|
// the docshell creation). We want to avoid treating the initial
|
||||||
|
// about:blank as a new page.
|
||||||
|
//
|
||||||
|
// We could conceivably expose Document::IsInitialDocument() as a
|
||||||
|
// ChromeOnly thing and use it here, but let's just filter out all
|
||||||
|
// about:blank, since we don't expect any in this test.
|
||||||
|
var haveNewPage = await SpecialPowers.spawn(w, [token],
|
||||||
|
currentToken => this.content.token != currentToken &&
|
||||||
|
this.content.location.href != "about:blank");
|
||||||
|
|
||||||
|
if (haveNewPage) {
|
||||||
|
++token;
|
||||||
|
assignToken(token);
|
||||||
|
|
||||||
|
// In this test, error pages are non-same-origin with us, and non-error
|
||||||
|
// pages are same-origin.
|
||||||
|
let haveErrorPage = false;
|
||||||
|
try {
|
||||||
|
win.document.title;
|
||||||
|
} catch (ex) {
|
||||||
|
haveErrorPage = true;
|
||||||
|
}
|
||||||
|
return haveErrorPage;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Something went wrong; just keep waiting.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveErrorPage == expectErrorPage) {
|
await delay(100);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function windowLoaded() {
|
async function windowLoaded() {
|
||||||
|
|
@ -50,13 +76,15 @@ async function windowLoaded() {
|
||||||
return;
|
return;
|
||||||
isWindowLoaded = true;
|
isWindowLoaded = true;
|
||||||
|
|
||||||
|
assignToken(token);
|
||||||
|
|
||||||
/* 2. We have successfully loaded a page, now go to a faulty URL */
|
/* 2. We have successfully loaded a page, now go to a faulty URL */
|
||||||
// XXX The test fails when we change the location synchronously
|
// XXX The test fails when we change the location synchronously
|
||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
w.location.href = faultyURL;
|
w.location.href = faultyURL;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
ok(await pollForPage(true, w), "Waiting for error page succeeded");
|
ok(await pollForPage(w), "Waiting for error page succeeded");
|
||||||
/* 3. now, while we are on the error page, navigate back */
|
/* 3. now, while we are on the error page, navigate back */
|
||||||
try {
|
try {
|
||||||
// We need the SpecialPowers bit, because this is a cross-origin window
|
// We need the SpecialPowers bit, because this is a cross-origin window
|
||||||
|
|
@ -66,7 +94,7 @@ async function windowLoaded() {
|
||||||
ok(false, "w.history.back() threw " + ex);
|
ok(false, "w.history.back() threw " + ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(await pollForPage(false, w), "Waiting for original page succeeded");
|
ok(!await pollForPage(w), "Waiting for original page succeeded");
|
||||||
/* 4-finish, check we are back at the original page */
|
/* 4-finish, check we are back at the original page */
|
||||||
is(await SpecialPowers.spawn(w, [], () => this.content.location.href),
|
is(await SpecialPowers.spawn(w, [], () => this.content.location.href),
|
||||||
workingURL,
|
workingURL,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue