fune/browser/base/content/test/general/browser_bug623893.js
Kris Maglione 94e3b0bd8d Bug 1596918: Part 3a - Scripted rewrite of most ContentTask.spawn calls to SpecialPowers.spawn calls. r=mccr8,remote-protocol-reviewers,ato
This is generally pretty straightforward, and rewrites nearly all calls. It
skips the ones that it can detect using frame script globals like
`sendAsyncMessage`, though.

Differential Revision: https://phabricator.services.mozilla.com/D53740

--HG--
extra : moz-landing-system : lando
2019-12-13 20:36:16 +00:00

41 lines
1.3 KiB
JavaScript

add_task(async function test() {
await BrowserTestUtils.withNewTab(
"data:text/plain;charset=utf-8,1",
async function(browser) {
BrowserTestUtils.loadURI(browser, "data:text/plain;charset=utf-8,2");
await BrowserTestUtils.browserLoaded(browser);
BrowserTestUtils.loadURI(browser, "data:text/plain;charset=utf-8,3");
await BrowserTestUtils.browserLoaded(browser);
await duplicate(0, "maintained the original index");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
await duplicate(-1, "went back");
await duplicate(1, "went forward");
BrowserTestUtils.removeTab(gBrowser.selectedTab);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
}
);
});
function promiseGetIndex(browser) {
return SpecialPowers.spawn(browser, [], function() {
let shistory = docShell
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsISHistory);
return shistory.index;
});
}
let duplicate = async function(delta, msg, cb) {
var startIndex = await promiseGetIndex(gBrowser.selectedBrowser);
duplicateTabIn(gBrowser.selectedTab, "tab", delta);
let tab = gBrowser.selectedTab;
await BrowserTestUtils.waitForEvent(tab, "SSTabRestored");
let endIndex = await promiseGetIndex(gBrowser.selectedBrowser);
is(endIndex, startIndex + delta, msg);
};