browser/base/content/test/general/test_offlineNotification.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial