fune/toolkit/content/tests/browser/browser_bug982298.js
Nika Layzell 42028efc71 Bug 1671983 - Part 4: Stop awaiting BrowserTestUtils.loadURI, r=annyG,remote-protocol-reviewers,extension-reviewers,preferences-reviewers,whimboo,zombie
This method only is async in order to allow callers to wait for a process switch
triggered by the call to `loadURI` to be finished before resolving. With
DocumentChannel, we should never trigger a process switch eagerly like this
again, so we don't need any of the async behaviour here anymore.

This part is largely mechanical changes to tests, removing the `await` calls on
`loadURI`, and a follow-up part will remove the actual async logic from
`BrowserTestUtils.loadURI`.

Differential Revision: https://phabricator.services.mozilla.com/D94641
2020-11-12 18:01:03 +00:00

72 lines
2.2 KiB
JavaScript

const scrollHtml =
'<textarea id="textarea1" row=2>Firefox\n\nFirefox\n\n\n\n\n\n\n\n\n\n' +
'</textarea><a href="about:blank">blank</a>';
add_task(async function() {
let url = "data:text/html;base64," + btoa(scrollHtml);
await BrowserTestUtils.withNewTab({ gBrowser, url }, async function(browser) {
let awaitFindResult = new Promise(resolve => {
let listener = {
onFindResult(aData) {
info("got find result");
browser.finder.removeResultListener(listener);
ok(
aData.result == Ci.nsITypeAheadFind.FIND_FOUND,
"should find string"
);
resolve();
},
onCurrentSelection() {},
onMatchesCountResult() {},
};
info("about to add results listener, open find bar, and send 'F' string");
browser.finder.addResultListener(listener);
});
await gFindBarPromise;
gFindBar.onFindCommand();
EventUtils.sendString("F");
info("added result listener and sent string 'F'");
await awaitFindResult;
// scroll textarea to bottom
await SpecialPowers.spawn(browser, [], () => {
let textarea = content.document.getElementById("textarea1");
textarea.scrollTop = textarea.scrollHeight;
});
BrowserTestUtils.loadURI(browser, "about:blank");
await BrowserTestUtils.browserLoaded(browser);
ok(
browser.currentURI.spec == "about:blank",
"got load event for about:blank"
);
let awaitFindResult2 = new Promise(resolve => {
let listener = {
onFindResult(aData) {
info("got find result #2");
browser.finder.removeResultListener(listener);
resolve();
},
onCurrentSelection() {},
onMatchesCountResult() {},
};
browser.finder.addResultListener(listener);
info("added result listener");
});
// find again needs delay for crash test
setTimeout(function() {
// ignore exception if occured
try {
info("about to send find again command");
gFindBar.onFindAgainCommand(false);
info("sent find again command");
} catch (e) {
info("got exception from onFindAgainCommand: " + e);
}
}, 0);
await awaitFindResult2;
});
});