File: test_offlineNotification.html

package info (click to toggle)
wine-gecko-2.24 2.24%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 740,092 kB
  • ctags: 688,789
  • sloc: cpp: 3,160,639; ansic: 1,619,153; python: 164,084; java: 128,022; asm: 114,527; xml: 69,863; sh: 55,281; makefile: 49,648; perl: 20,454; objc: 2,344; yacc: 2,066; pascal: 995; lex: 982; exp: 449; php: 244; lisp: 228; awk: 211; sed: 61; csh: 21; ada: 16; ruby: 3
file content (126 lines) | stat: -rw-r--r-- 4,489 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!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>
  <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 -->
<iframe name="testFrame3" src="http://example.com/tests/browser/base/content/test/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 principal1 = Cc["@mozilla.org/scriptsecuritymanager;1"]
                        .getService(SpecialPowers.Ci.nsIScriptSecurityManager)
                        .getNoAppCodebasePrincipal(uri1);
      var principal2 = Cc["@mozilla.org/scriptsecuritymanager;1"]
                        .getService(SpecialPowers.Ci.nsIScriptSecurityManager)
                        .getNoAppCodebasePrincipal(uri2);

      pm.removeFromPrincipal(principal1, "offline-app");
      pm.removeFromPrincipal(principal2, "offline-app");

      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();
}

</script>
</pre>
</body>
</html>