2009-02-22 11:09:10 -08:00
|
|
|
<!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>
|
2013-08-16 02:34:21 -07:00
|
|
|
<script type="text/javascript" src="offlineByDefault.js"></script>
|
2009-02-22 11:09:10 -08:00
|
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
|
|
</head>
|
|
|
|
<body onload="loaded()">
|
|
|
|
<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 -->
|
2013-09-18 23:06:20 -07:00
|
|
|
<iframe name="testFrame3" src="http://example.com/tests/browser/base/content/test/general/offlineChild.html"></iframe>
|
2009-02-22 11:09:10 -08:00
|
|
|
|
2009-06-15 01:27:29 -07:00
|
|
|
<iframe id="eventsTestFrame" src="offlineEvent.html"></iframe>
|
|
|
|
|
2009-02-22 11:09:10 -08:00
|
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2012-09-24 05:46:29 -07:00
|
|
|
const Cc = SpecialPowers.Cc;
|
2009-02-22 11:09:10 -08:00
|
|
|
|
|
|
|
var numFinished = 0;
|
|
|
|
|
|
|
|
window.addEventListener("message", function(event) {
|
|
|
|
is(event.data, "success", "Child was successfully cached.");
|
|
|
|
|
|
|
|
if (++numFinished == 3) {
|
|
|
|
// Clean up after ourself
|
2012-08-06 13:15:49 -07:00
|
|
|
var pm = Cc["@mozilla.org/permissionmanager;1"].
|
2012-09-24 05:46:29 -07:00
|
|
|
getService(SpecialPowers.Ci.nsIPermissionManager);
|
2012-08-06 13:15:49 -07:00
|
|
|
var ioService = Cc["@mozilla.org/network/io-service;1"]
|
2012-09-24 05:46:29 -07:00
|
|
|
.getService(SpecialPowers.Ci.nsIIOService);
|
2012-07-23 11:08:07 -07:00
|
|
|
var uri1 = ioService.newURI(frames.testFrame.location, null, null);
|
|
|
|
var uri2 = ioService.newURI(frames.testFrame3.location, null, null);
|
2009-02-22 11:09:10 -08:00
|
|
|
|
2012-08-06 13:15:49 -07:00
|
|
|
var principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
2012-09-24 05:46:29 -07:00
|
|
|
.getService(SpecialPowers.Ci.nsIScriptSecurityManager)
|
2012-07-23 11:08:07 -07:00
|
|
|
.getNoAppCodebasePrincipal(uri1);
|
2012-08-06 13:15:49 -07:00
|
|
|
var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"]
|
2012-09-24 05:46:29 -07:00
|
|
|
.getService(SpecialPowers.Ci.nsIScriptSecurityManager)
|
2012-07-23 11:08:07 -07:00
|
|
|
.getNoAppCodebasePrincipal(uri2);
|
|
|
|
|
|
|
|
pm.removeFromPrincipal(principal1, "offline-app");
|
|
|
|
pm.removeFromPrincipal(principal2, "offline-app");
|
2009-02-22 11:09:10 -08:00
|
|
|
|
2013-08-16 02:34:21 -07:00
|
|
|
offlineByDefault.reset();
|
|
|
|
|
2009-02-22 11:09:10 -08:00
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2009-06-15 01:27:29 -07:00
|
|
|
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!");
|
|
|
|
}
|
|
|
|
|
2009-02-22 11:09:10 -08:00
|
|
|
function loaded() {
|
2009-06-15 01:27:29 -07:00
|
|
|
testEventHandling();
|
|
|
|
|
2013-04-29 00:38:53 -07:00
|
|
|
// Click the notification panel's "Allow" button. This should kick
|
2009-02-22 11:09:10 -08:00
|
|
|
// off updates, which will eventually lead to getting messages from
|
|
|
|
// the children.
|
2012-09-24 05:46:29 -07:00
|
|
|
var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"].
|
|
|
|
getService(SpecialPowers.Ci.nsIWindowMediator);
|
2009-02-22 11:09:10 -08:00
|
|
|
var win = wm.getMostRecentWindow("navigator:browser");
|
2013-04-29 00:38:53 -07:00
|
|
|
var panel = win.PopupNotifications.panel;
|
|
|
|
is(panel.childElementCount, 2, "2 notifications being displayed");
|
|
|
|
panel.firstElementChild.button.click();
|
2009-02-22 11:09:10 -08:00
|
|
|
|
2013-04-29 00:38:53 -07:00
|
|
|
// should have dismissed one of the notifications.
|
|
|
|
is(panel.childElementCount, 1, "1 notification now being displayed");
|
|
|
|
panel.firstElementChild.button.click();
|
2009-02-22 11:09:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|