Skip to content

Commit

Permalink
Bug 1705532 use async/await instead of callbacks r=annyG
Browse files Browse the repository at this point in the history
  • Loading branch information
karlt committed Dec 25, 2021
1 parent d1934b2 commit 5ec8638
Showing 1 changed file with 22 additions and 37 deletions.
59 changes: 22 additions & 37 deletions docshell/test/navigation/test_bug386782.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,24 @@
},
];

var gTestNum = -1;
var gTest = null;

window.onload = goNext;

function goNext() {
gTestNum++;
if (gTestNum >= gTests.length) {
SimpleTest.finish();
return;
add_task(async () => {
while (gTests.length) {
gTest = gTests.shift();
await runTest();
}
gTest = gTests[gTestNum];
});

async function runTest() {
gTest.window = window.open(gTest.url, gTest.name, "width=500,height=500");
window.onmessage = function(e) {
is(e.data.persisted, false, "Initial load cannot be persisted");
window.onmessage = null;
if ("onload" in gTest) {
gTest.onload(gTest.window.document);
}
SimpleTest.waitForFocus(beginTest, gTest.window);
};
}
let e = await new Promise(r => window.onmessage = r);
is(e.data.persisted, false, "Initial load cannot be persisted");
if ("onload" in gTest) {
gTest.onload(gTest.window.document);
}
await SimpleTest.promiseFocus(gTest.window);

function beginTest() {
gTest.window.document.body.focus();

// WARNING: If the following test fails, give the setTimeout() in the onload()
Expand All @@ -71,23 +65,17 @@

gTest.window.location = "about:blank";
let cond = () => gTest.window.location.href == "about:blank";
SimpleTest.waitForCondition(cond, () => {
SimpleTest.waitForFocus(goBack, gTest.window, true);
}, "about:blank never loaded");
}
await SimpleTest.promiseWaitForCondition(cond,
"about:blank never loaded");
await SimpleTest.promiseFocus(gTest.window, true);

function goBack() {
window.onmessage = function(e) {
window.onmessage = null;
// Skip the test if the page is not loaded from the bf-cache when going back.
if (e.data.persisted) {
checkStillEditable();
} else {
gTest.window.close();
goNext();
}
};
gTest.window.history.back();
e = await new Promise(r => window.onmessage = r);
// Skip the test if the page is not loaded from the bf-cache when going back.
if (e.data.persisted) {
checkStillEditable();
}
gTest.window.close();
}

function checkStillEditable() {
Expand All @@ -105,9 +93,6 @@
gTest.window.document.body.focus();
sendString("TWICE ", gTest.window);
is(gTest.window.document.body.innerHTML, gTest.expectedBodyAfterSecondEdit, "Can we still edit?");

gTest.window.close();
goNext();
}

</script>
Expand Down

0 comments on commit 5ec8638

Please sign in to comment.