summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/general/test_offlineNotification.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /browser/base/content/test/general/test_offlineNotification.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-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/test_offlineNotification.html')
-rw-r--r--browser/base/content/test/general/test_offlineNotification.html129
1 files changed, 129 insertions, 0 deletions
diff --git a/browser/base/content/test/general/test_offlineNotification.html b/browser/base/content/test/general/test_offlineNotification.html
new file mode 100644
index 000000000..4f78184b4
--- /dev/null
+++ b/browser/base/content/test/general/test_offlineNotification.html
@@ -0,0 +1,129 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=462856
+-->
+<head>
+ <title>Test offline app notification</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="offlineByDefault.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<p id="display">
+<!-- Load the test frame twice from the same domain,
+ to make sure we get notifications for both -->
+<iframe name="testFrame" src="offlineChild.html"></iframe>
+<iframe name="testFrame2" src="offlineChild2.html"></iframe>
+<!-- Load from another domain to make sure we get a second allow/deny
+ notification -->
+<iframe name="testFrame3" src="http://example.com/tests/browser/base/content/test/general/offlineChild.html"></iframe>
+
+<iframe id="eventsTestFrame" src="offlineEvent.html"></iframe>
+
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+const Cc = SpecialPowers.Cc;
+
+var numFinished = 0;
+
+window.addEventListener("message", function(event) {
+ is(event.data, "success", "Child was successfully cached.");
+
+ if (++numFinished == 3) {
+ // Clean up after ourself
+ var pm = Cc["@mozilla.org/permissionmanager;1"].
+ getService(SpecialPowers.Ci.nsIPermissionManager);
+ var ioService = Cc["@mozilla.org/network/io-service;1"]
+ .getService(SpecialPowers.Ci.nsIIOService);
+ var uri1 = ioService.newURI(frames.testFrame.location, null, null);
+ var uri2 = ioService.newURI(frames.testFrame3.location, null, null);
+
+ var ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
+ .getService(SpecialPowers.Ci.nsIScriptSecurityManager);
+ var principal1 = ssm.createCodebasePrincipal(uri1, {});
+ var principal2 = ssm.createCodebasePrincipal(uri2, {});
+
+ pm.removeFromPrincipal(principal1, "offline-app");
+ pm.removeFromPrincipal(principal2, "offline-app");
+
+ offlineByDefault.reset();
+
+ SimpleTest.finish();
+ }
+ }, false);
+
+var count = 0;
+var expectedEvent = "";
+function eventHandler(evt) {
+ ++count;
+ is(evt.type, expectedEvent, "Wrong event!");
+}
+
+function testEventHandling() {
+ var events = [ "checking",
+ "error",
+ "noupdate",
+ "downloading",
+ "progress",
+ "updateready",
+ "cached",
+ "obsolete"];
+ var w = document.getElementById("eventsTestFrame").contentWindow;
+ var e;
+ for (var i = 0; i < events.length; ++i) {
+ count = 0;
+ expectedEvent = events[i];
+ e = w.document.createEvent("event");
+ e.initEvent(expectedEvent, true, true);
+ w.applicationCache["on" + expectedEvent] = eventHandler;
+ w.applicationCache.addEventListener(expectedEvent, eventHandler, true);
+ w.applicationCache.dispatchEvent(e);
+ is(count, 2, "Wrong number events!");
+ w.applicationCache["on" + expectedEvent] = null;
+ w.applicationCache.removeEventListener(expectedEvent, eventHandler, true);
+ w.applicationCache.dispatchEvent(e);
+ is(count, 2, "Wrong number events!");
+ }
+
+ // Test some random event.
+ count = 0;
+ expectedEvent = "foo";
+ e = w.document.createEvent("event");
+ e.initEvent(expectedEvent, true, true);
+ w.applicationCache.addEventListener(expectedEvent, eventHandler, true);
+ w.applicationCache.dispatchEvent(e);
+ is(count, 1, "Wrong number events!");
+ w.applicationCache.removeEventListener(expectedEvent, eventHandler, true);
+ w.applicationCache.dispatchEvent(e);
+ is(count, 1, "Wrong number events!");
+}
+
+function loaded() {
+ testEventHandling();
+
+ // Click the notification panel's "Allow" button. This should kick
+ // off updates, which will eventually lead to getting messages from
+ // the children.
+ var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"].
+ getService(SpecialPowers.Ci.nsIWindowMediator);
+ var win = wm.getMostRecentWindow("navigator:browser");
+ var panel = win.PopupNotifications.panel;
+ is(panel.childElementCount, 2, "2 notifications being displayed");
+ panel.firstElementChild.button.click();
+
+ // should have dismissed one of the notifications.
+ is(panel.childElementCount, 1, "1 notification now being displayed");
+ panel.firstElementChild.button.click();
+}
+
+SimpleTest.waitForFocus(loaded);
+
+</script>
+</pre>
+</body>
+</html>