Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=462856 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test offline app notification</title> |
michael@0 | 8 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 9 | <script type="text/javascript" src="offlineByDefault.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body onload="loaded()"> |
michael@0 | 13 | <p id="display"> |
michael@0 | 14 | <!-- Load the test frame twice from the same domain, |
michael@0 | 15 | to make sure we get notifications for both --> |
michael@0 | 16 | <iframe name="testFrame" src="offlineChild.html"></iframe> |
michael@0 | 17 | <iframe name="testFrame2" src="offlineChild2.html"></iframe> |
michael@0 | 18 | <!-- Load from another domain to make sure we get a second allow/deny |
michael@0 | 19 | notification --> |
michael@0 | 20 | <iframe name="testFrame3" src="http://example.com/tests/browser/base/content/test/general/offlineChild.html"></iframe> |
michael@0 | 21 | |
michael@0 | 22 | <iframe id="eventsTestFrame" src="offlineEvent.html"></iframe> |
michael@0 | 23 | |
michael@0 | 24 | <div id="content" style="display: none"> |
michael@0 | 25 | </div> |
michael@0 | 26 | <pre id="test"> |
michael@0 | 27 | <script class="testbody" type="text/javascript"> |
michael@0 | 28 | |
michael@0 | 29 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 30 | const Cc = SpecialPowers.Cc; |
michael@0 | 31 | |
michael@0 | 32 | var numFinished = 0; |
michael@0 | 33 | |
michael@0 | 34 | window.addEventListener("message", function(event) { |
michael@0 | 35 | is(event.data, "success", "Child was successfully cached."); |
michael@0 | 36 | |
michael@0 | 37 | if (++numFinished == 3) { |
michael@0 | 38 | // Clean up after ourself |
michael@0 | 39 | var pm = Cc["@mozilla.org/permissionmanager;1"]. |
michael@0 | 40 | getService(SpecialPowers.Ci.nsIPermissionManager); |
michael@0 | 41 | var ioService = Cc["@mozilla.org/network/io-service;1"] |
michael@0 | 42 | .getService(SpecialPowers.Ci.nsIIOService); |
michael@0 | 43 | var uri1 = ioService.newURI(frames.testFrame.location, null, null); |
michael@0 | 44 | var uri2 = ioService.newURI(frames.testFrame3.location, null, null); |
michael@0 | 45 | |
michael@0 | 46 | var principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"] |
michael@0 | 47 | .getService(SpecialPowers.Ci.nsIScriptSecurityManager) |
michael@0 | 48 | .getNoAppCodebasePrincipal(uri1); |
michael@0 | 49 | var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"] |
michael@0 | 50 | .getService(SpecialPowers.Ci.nsIScriptSecurityManager) |
michael@0 | 51 | .getNoAppCodebasePrincipal(uri2); |
michael@0 | 52 | |
michael@0 | 53 | pm.removeFromPrincipal(principal1, "offline-app"); |
michael@0 | 54 | pm.removeFromPrincipal(principal2, "offline-app"); |
michael@0 | 55 | |
michael@0 | 56 | offlineByDefault.reset(); |
michael@0 | 57 | |
michael@0 | 58 | SimpleTest.finish(); |
michael@0 | 59 | } |
michael@0 | 60 | }, false); |
michael@0 | 61 | |
michael@0 | 62 | var count = 0; |
michael@0 | 63 | var expectedEvent = ""; |
michael@0 | 64 | function eventHandler(evt) { |
michael@0 | 65 | ++count; |
michael@0 | 66 | is(evt.type, expectedEvent, "Wrong event!"); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function testEventHandling() { |
michael@0 | 70 | var events = [ "checking", |
michael@0 | 71 | "error", |
michael@0 | 72 | "noupdate", |
michael@0 | 73 | "downloading", |
michael@0 | 74 | "progress", |
michael@0 | 75 | "updateready", |
michael@0 | 76 | "cached", |
michael@0 | 77 | "obsolete"]; |
michael@0 | 78 | var w = document.getElementById("eventsTestFrame").contentWindow; |
michael@0 | 79 | var e; |
michael@0 | 80 | for (var i = 0; i < events.length; ++i) { |
michael@0 | 81 | count = 0; |
michael@0 | 82 | expectedEvent = events[i]; |
michael@0 | 83 | e = w.document.createEvent("event"); |
michael@0 | 84 | e.initEvent(expectedEvent, true, true); |
michael@0 | 85 | w.applicationCache["on" + expectedEvent] = eventHandler; |
michael@0 | 86 | w.applicationCache.addEventListener(expectedEvent, eventHandler, true); |
michael@0 | 87 | w.applicationCache.dispatchEvent(e); |
michael@0 | 88 | is(count, 2, "Wrong number events!"); |
michael@0 | 89 | w.applicationCache["on" + expectedEvent] = null; |
michael@0 | 90 | w.applicationCache.removeEventListener(expectedEvent, eventHandler, true); |
michael@0 | 91 | w.applicationCache.dispatchEvent(e); |
michael@0 | 92 | is(count, 2, "Wrong number events!"); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | // Test some random event. |
michael@0 | 96 | count = 0; |
michael@0 | 97 | expectedEvent = "foo"; |
michael@0 | 98 | e = w.document.createEvent("event"); |
michael@0 | 99 | e.initEvent(expectedEvent, true, true); |
michael@0 | 100 | w.applicationCache.addEventListener(expectedEvent, eventHandler, true); |
michael@0 | 101 | w.applicationCache.dispatchEvent(e); |
michael@0 | 102 | is(count, 1, "Wrong number events!"); |
michael@0 | 103 | w.applicationCache.removeEventListener(expectedEvent, eventHandler, true); |
michael@0 | 104 | w.applicationCache.dispatchEvent(e); |
michael@0 | 105 | is(count, 1, "Wrong number events!"); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | function loaded() { |
michael@0 | 109 | testEventHandling(); |
michael@0 | 110 | |
michael@0 | 111 | // Click the notification panel's "Allow" button. This should kick |
michael@0 | 112 | // off updates, which will eventually lead to getting messages from |
michael@0 | 113 | // the children. |
michael@0 | 114 | var wm = SpecialPowers.Cc["@mozilla.org/appshell/window-mediator;1"]. |
michael@0 | 115 | getService(SpecialPowers.Ci.nsIWindowMediator); |
michael@0 | 116 | var win = wm.getMostRecentWindow("navigator:browser"); |
michael@0 | 117 | var panel = win.PopupNotifications.panel; |
michael@0 | 118 | is(panel.childElementCount, 2, "2 notifications being displayed"); |
michael@0 | 119 | panel.firstElementChild.button.click(); |
michael@0 | 120 | |
michael@0 | 121 | // should have dismissed one of the notifications. |
michael@0 | 122 | is(panel.childElementCount, 1, "1 notification now being displayed"); |
michael@0 | 123 | panel.firstElementChild.button.click(); |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | </script> |
michael@0 | 127 | </pre> |
michael@0 | 128 | </body> |
michael@0 | 129 | </html> |