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 /browser/base/content/test/general/browser_gZipOfflineChild.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 'browser/base/content/test/general/browser_gZipOfflineChild.js')
-rw-r--r-- | browser/base/content/test/general/browser_gZipOfflineChild.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/browser/base/content/test/general/browser_gZipOfflineChild.js b/browser/base/content/test/general/browser_gZipOfflineChild.js new file mode 100644 index 000000000..09691bed8 --- /dev/null +++ b/browser/base/content/test/general/browser_gZipOfflineChild.js @@ -0,0 +1,80 @@ +/** + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +const URL = "http://mochi.test:8888/browser/browser/base/content/test/general/test_offline_gzip.html" + +registerCleanupFunction(function() { + // Clean up after ourself + let uri = Services.io.newURI(URL, null, null); + let principal = Services.scriptSecurityManager.createCodebasePrincipal(uri, {}); + Services.perms.removeFromPrincipal(principal, "offline-app"); + Services.prefs.clearUserPref("offline-apps.allow_by_default"); +}); + +var cacheCount = 0; +var intervalID = 0; + +// +// Handle "message" events which are posted from the iframe upon +// offline cache events. +// +function handleMessageEvents(event) { + cacheCount++; + switch (cacheCount) { + case 1: + // This is the initial caching off offline data. + is(event.data, "oncache", "Child was successfully cached."); + // Reload the frame; this will generate an error message + // in the case of bug 501422. + event.source.location.reload(); + // Use setInterval to repeatedly call a function which + // checks that one of two things has occurred: either + // the offline cache is udpated (which means our iframe + // successfully reloaded), or the string "error" appears + // in the iframe, as in the case of bug 501422. + intervalID = setInterval(function() { + // Sometimes document.body may not exist, and trying to access + // it will throw an exception, so handle this case. + try { + var bodyInnerHTML = event.source.document.body.innerHTML; + } + catch (e) { + bodyInnerHTML = ""; + } + if (cacheCount == 2 || bodyInnerHTML.includes("error")) { + clearInterval(intervalID); + is(cacheCount, 2, "frame not reloaded successfully"); + if (cacheCount != 2) { + finish(); + } + } + }, 100); + break; + case 2: + is(event.data, "onupdate", "Child was successfully updated."); + clearInterval(intervalID); + finish(); + break; + default: + // how'd we get here? + ok(false, "cacheCount not 1 or 2"); + } +} + +function test() { + waitForExplicitFinish(); + + Services.prefs.setBoolPref("offline-apps.allow_by_default", true); + + // Open a new tab. + gBrowser.selectedTab = gBrowser.addTab(URL); + registerCleanupFunction(() => gBrowser.removeCurrentTab()); + + BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser).then(() => { + let window = gBrowser.selectedBrowser.contentWindow; + + window.addEventListener("message", handleMessageEvents, false); + }); +} |