let getActor = browser => { return browser.browsingContext.currentWindowGlobal.getActor(ACTOR);
};
add_task(async function runTests() { if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) {
await setupAsync();
let browser = gBrowser.selectedBrowser; // Now that we're set up, initialize our frame script.
await checkListenersAsync("initial", "listeners initialized");
// Check if all history listeners are always notified.
info("# part 1");
await whenPageShown(browser, () => // eslint-disable-next-line @microsoft/sdl/no-insecure-url
BrowserTestUtils.startLoadingURIString(browser, "http://www.example.com/")
);
await checkListenersAsync("newentry", "shistory has a new entry");
ok(browser.canGoBackIgnoringUserInteraction, "we can go back");
await whenPageShown(browser, () => browser.goBack());
await checkListenersAsync("gotoindex", "back to the first shentry");
ok(browser.canGoForward, "we can go forward");
await whenPageShown(browser, () => browser.goForward());
await checkListenersAsync("gotoindex", "forward to the second shentry");
await whenPageShown(browser, () => browser.gotoIndex(0));
await checkListenersAsync("gotoindex", "back to the first index");
// Check nsISHistory.notifyOnHistoryReload
info("# part 2");
ok(await notifyReloadAsync(), "reloading has not been canceled");
await checkListenersAsync("reload", "saw the reload notification");
// Let the first listener cancel the reload action.
info("# part 3");
await resetListenersAsync();
await setListenerRetvalAsync(0, false);
ok(!(await notifyReloadAsync()), "reloading has been canceled");
await checkListenersAsync("reload", "saw the reload notification");
// Let both listeners cancel the reload action.
info("# part 4");
await resetListenersAsync();
await setListenerRetvalAsync(1, false);
ok(!(await notifyReloadAsync()), "reloading has been canceled");
await checkListenersAsync("reload", "saw the reload notification");
// Let the second listener cancel the reload action.
info("# part 5");
await resetListenersAsync();
await setListenerRetvalAsync(0, true);
ok(!(await notifyReloadAsync()), "reloading has been canceled");
await checkListenersAsync("reload", "saw the reload notification");
function sendQuery(message, arg = {}) { return getActor(gBrowser.selectedBrowser).sendQuery(message, arg);
}
await setup();
let browser = gBrowser.selectedBrowser; // Now that we're set up, initialize our frame script.
checkListeners("initial", "listeners initialized");
// Check if all history listeners are always notified.
info("# part 1");
await whenPageShown(browser, () => // eslint-disable-next-line @microsoft/sdl/no-insecure-url
BrowserTestUtils.startLoadingURIString(browser, "http://www.example.com/")
);
checkListeners("newentry", "shistory has a new entry");
ok(browser.canGoBackIgnoringUserInteraction, "we can go back");
await whenPageShown(browser, () => browser.goBack());
checkListeners("gotoindex", "back to the first shentry");
ok(browser.canGoForward, "we can go forward");
await whenPageShown(browser, () => browser.goForward());
checkListeners("gotoindex", "forward to the second shentry");
await whenPageShown(browser, () => browser.gotoIndex(0));
checkListeners("gotoindex", "back to the first index");
// Check nsISHistory.notifyOnHistoryReload
info("# part 2");
ok(notifyReload(browser), "reloading has not been canceled");
checkListeners("reload", "saw the reload notification");
// Let the first listener cancel the reload action.
info("# part 3");
resetListeners();
setListenerRetval(0, false);
ok(!notifyReload(browser), "reloading has been canceled");
checkListeners("reload", "saw the reload notification");
// Let both listeners cancel the reload action.
info("# part 4");
resetListeners();
setListenerRetval(1, false);
ok(!notifyReload(browser), "reloading has been canceled");
checkListeners("reload", "saw the reload notification");
// Let the second listener cancel the reload action.
info("# part 5");
resetListeners();
setListenerRetval(0, true);
ok(!notifyReload(browser), "reloading has been canceled");
checkListeners("reload", "saw the reload notification");
});
function resetListeners() { for (let listener of listeners) {
listener.last = "initial";
}
}
function notifyReload(browser) { return browser.browsingContext.sessionHistory.notifyOnHistoryReload();
}
function setListenerRetval(num, val) {
listeners[num].retval = val;
}
async function setup() {
let tab = await BrowserTestUtils.openNewForegroundTab(
gBrowser, "http://mochi.test:8888"
);
let browser = tab.linkedBrowser;
registerCleanupFunction(async function () { for (let listener of listeners) {
browser.browsingContext.sessionHistory.removeSHistoryListener(listener);
}
gBrowser.removeTab(tab);
}); for (let listener of listeners) {
browser.browsingContext.sessionHistory.addSHistoryListener(listener);
}
}
function whenPageShown(aBrowser, aNavigation) {
let promise = new Promise(resolve => {
let unregister = BrowserTestUtils.addContentEventListener(
aBrowser, "pageshow",
() => {
unregister();
resolve();
},
{ capture: true }
);
});
aNavigation(); return promise;
}
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.