diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /docshell/test/browser/browser_bug422543.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'docshell/test/browser/browser_bug422543.js')
-rw-r--r-- | docshell/test/browser/browser_bug422543.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/docshell/test/browser/browser_bug422543.js b/docshell/test/browser/browser_bug422543.js new file mode 100644 index 000000000..0655a17b7 --- /dev/null +++ b/docshell/test/browser/browser_bug422543.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(function* runTests() { + yield setup(); + let browser = gBrowser.selectedBrowser; + // Now that we're set up, initialize our frame script. + yield checkListeners("initial", "listeners initialized"); + + // Check if all history listeners are always notified. + info("# part 1"); + yield whenPageShown(browser, () => browser.loadURI("http://www.example.com/")); + yield checkListeners("newentry", "shistory has a new entry"); + ok(browser.canGoBack, "we can go back"); + + yield whenPageShown(browser, () => browser.goBack()); + yield checkListeners("goback", "back to the first shentry"); + ok(browser.canGoForward, "we can go forward"); + + yield whenPageShown(browser, () => browser.goForward()); + yield checkListeners("goforward", "forward to the second shentry"); + + yield whenPageShown(browser, () => browser.reload()); + yield checkListeners("reload", "current shentry reloaded"); + + yield whenPageShown(browser, () => browser.gotoIndex(0)); + yield checkListeners("gotoindex", "back to the first index"); + + // Check nsISHistoryInternal.notifyOnHistoryReload + info("# part 2"); + ok((yield notifyReload()), "reloading has not been canceled"); + yield checkListeners("reload", "saw the reload notification"); + + // Let the first listener cancel the reload action. + info("# part 3"); + yield resetListeners(); + yield setListenerRetval(0, false); + ok(!(yield notifyReload()), "reloading has been canceled"); + yield checkListeners("reload", "saw the reload notification"); + + // Let both listeners cancel the reload action. + info("# part 4"); + yield resetListeners(); + yield setListenerRetval(1, false); + ok(!(yield notifyReload()), "reloading has been canceled"); + yield checkListeners("reload", "saw the reload notification"); + + // Let the second listener cancel the reload action. + info("# part 5"); + yield resetListeners(); + yield setListenerRetval(0, true); + ok(!(yield notifyReload()), "reloading has been canceled"); + yield checkListeners("reload", "saw the reload notification"); +}); + +function listenOnce(message, arg = {}) { + return new Promise(resolve => { + let mm = gBrowser.selectedBrowser.messageManager; + mm.addMessageListener(message + ":return", function listener(msg) { + mm.removeMessageListener(message + ":return", listener); + resolve(msg.data); + }); + + mm.sendAsyncMessage(message, arg); + }); +} + +function checkListeners(aLast, aMessage) { + return listenOnce("bug422543:getListenerStatus").then((listenerStatuses) => { + is(listenerStatuses[0], aLast, aMessage); + is(listenerStatuses[1], aLast, aMessage); + }); +} + +function resetListeners() { + return listenOnce("bug422543:resetListeners"); +} + +function notifyReload() { + return listenOnce("bug422543:notifyReload").then(({ rval }) => { + return rval; + }); +} + +function setListenerRetval(num, val) { + return listenOnce("bug422543:setRetval", { num, val }); +} + +function setup() { + return BrowserTestUtils.openNewForegroundTab(gBrowser, + "http://mochi.test:8888") + .then(function (tab) { + let browser = tab.linkedBrowser; + registerCleanupFunction(function* () { + yield listenOnce("bug422543:cleanup"); + gBrowser.removeTab(tab); + }); + + browser.messageManager + .loadFrameScript(getRootDirectory(gTestPath) + "file_bug422543_script.js", false); + }); +} + +function whenPageShown(aBrowser, aNavigation) { + let listener = ContentTask.spawn(aBrowser, null, function () { + return new Promise(resolve => { + addEventListener("pageshow", function onLoad() { + removeEventListener("pageshow", onLoad, true); + resolve(); + }, true); + }); + }); + + aNavigation(); + return listener; +} |