1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/test_offlineNotification.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=462856 1.8 +--> 1.9 +<head> 1.10 + <title>Test offline app notification</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="offlineByDefault.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.14 +</head> 1.15 +<body onload="loaded()"> 1.16 +<p id="display"> 1.17 +<!-- Load the test frame twice from the same domain, 1.18 + to make sure we get notifications for both --> 1.19 +<iframe name="testFrame" src="offlineChild.html"></iframe> 1.20 +<iframe name="testFrame2" src="offlineChild2.html"></iframe> 1.21 +<!-- Load from another domain to make sure we get a second allow/deny 1.22 + notification --> 1.23 +<iframe name="testFrame3" src="http://example.com/tests/browser/base/content/test/general/offlineChild.html"></iframe> 1.24 + 1.25 +<iframe id="eventsTestFrame" src="offlineEvent.html"></iframe> 1.26 + 1.27 +<div id="content" style="display: none"> 1.28 +</div> 1.29 +<pre id="test"> 1.30 +<script class="testbody" type="text/javascript"> 1.31 + 1.32 +SimpleTest.waitForExplicitFinish(); 1.33 +const Cc = SpecialPowers.Cc; 1.34 + 1.35 +var numFinished = 0; 1.36 + 1.37 +window.addEventListener("message", function(event) { 1.38 + is(event.data, "success", "Child was successfully cached."); 1.39 + 1.40 + if (++numFinished == 3) { 1.41 + // Clean up after ourself 1.42 + var pm = Cc["@mozilla.org/permissionmanager;1"]. 1.43 + getService(SpecialPowers.Ci.nsIPermissionManager); 1.44 + var ioService = Cc["@mozilla.org/network/io-service;1"] 1.45 + .getService(SpecialPowers.Ci.nsIIOService); 1.46 + var uri1 = ioService.newURI(frames.testFrame.location, null, null); 1.47 + var uri2 = ioService.newURI(frames.testFrame3.location, null, null); 1.48 + 1.49 + var principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"] 1.50 + .getService(SpecialPowers.Ci.nsIScriptSecurityManager) 1.51 + .getNoAppCodebasePrincipal(uri1); 1.52 + var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"] 1.53 + .getService(SpecialPowers.Ci.nsIScriptSecurityManager) 1.54 + .getNoAppCodebasePrincipal(uri2); 1.55 + 1.56 + pm.removeFromPrincipal(principal1, "offline-app"); 1.57 + pm.removeFromPrincipal(principal2, "offline-app"); 1.58 + 1.59 + offlineByDefault.reset(); 1.60 + 1.61 + SimpleTest.finish(); 1.62 + } 1.63 + }, false); 1.64 + 1.65 +var count = 0; 1.66 +var expectedEvent = ""; 1.67 +function eventHandler(evt) { 1.68 + ++count; 1.69 + is(evt.type, expectedEvent, "Wrong event!"); 1.70 +} 1.71 + 1.72 +function testEventHandling() { 1.73 + var events = [ "checking", 1.74 + "error", 1.75 + "noupdate", 1.76 + "downloading", 1.77 + "progress", 1.78 + "updateready", 1.79 + "cached", 1.80 + "obsolete"]; 1.81 + var w = document.getElementById("eventsTestFrame").contentWindow; 1.82 + var e; 1.83 + for (var i = 0; i < events.length; ++i) { 1.84 + count = 0; 1.85 + expectedEvent = events[i]; 1.86 + e = w.document.createEvent("event"); 1.87 + e.initEvent(expectedEvent, true, true); 1.88 + w.applicationCache["on" + expectedEvent] = eventHandler; 1.89 + w.applicationCache.addEventListener(expectedEvent, eventHandler, true); 1.90 + w.applicationCache.dispatchEvent(e); 1.91 + is(count, 2, "Wrong number events!"); 1.92 + w.applicationCache["on" + expectedEvent] = null; 1.93 + w.applicationCache.removeEventListener(expectedEvent, eventHandler, true); 1.94 + w.applicationCache.dispatchEvent(e); 1.95 + is(count, 2, "Wrong number events!"); 1.96 + } 1.97 + 1.98 + // Test some random event. 1.99 + count = 0; 1.100 + expectedEvent = "foo"; 1.101 + e = w.document.createEvent("event"); 1.102 + e.initEvent(expectedEvent, true, true); 1.103 + w.applicationCache.addEventListener(expectedEvent, eventHandler, true); 1.104 + w.applicationCache.dispatchEvent(e); 1.105 + is(count, 1, "Wrong number events!"); 1.106 + w.applicationCache.removeEventListener(expectedEvent, eventHandler, true); 1.107 + w.applicationCache.dispatchEvent(e); 1.108 + is(count, 1, "Wrong number events!"); 1.109 +} 1.110 + 1.111 +function loaded() { 1.112 + testEventHandling(); 1.113 + 1.114 + // Click the notification panel's "Allow" button. This should kick 1.115 + // off updates, which will eventually lead to getting messages from 1.116 + // the children. 1.117 + var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"]. 1.118 + getService(SpecialPowers.Ci.nsIWindowMediator); 1.119 + var win = wm.getMostRecentWindow("navigator:browser"); 1.120 + var panel = win.PopupNotifications.panel; 1.121 + is(panel.childElementCount, 2, "2 notifications being displayed"); 1.122 + panel.firstElementChild.button.click(); 1.123 + 1.124 + // should have dismissed one of the notifications. 1.125 + is(panel.childElementCount, 1, "1 notification now being displayed"); 1.126 + panel.firstElementChild.button.click(); 1.127 +} 1.128 + 1.129 +</script> 1.130 +</pre> 1.131 +</body> 1.132 +</html>