summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/serviceworkers/simpleregister/index.html
blob: 2c0eb5345ea12a88f499530c38fe7dfd86bb58c2 (plain)
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
<html>
  <head></head>
  <body>
      <script type="text/javascript">
          var expectedEvents = 2;
          function eventReceived() {
            window.parent.postMessage({ type: "check", status: expectedEvents > 0, msg: "updatefound received" }, "*");

            if (--expectedEvents) {
              window.parent.postMessage({ type: "finish" }, "*");
            }
          }

          navigator.serviceWorker.getRegistrations().then(function(a) {
            window.parent.postMessage({ type: "check", status: Array.isArray(a),
                                        msg: "getRegistrations returns an array" }, "*");
            window.parent.postMessage({ type: "check", status: a.length > 0,
                                        msg: "getRegistrations returns an array with 1 item" }, "*");
            for (var i = 0; i < a.length; ++i) {
              window.parent.postMessage({ type: "check", status: a[i] instanceof ServiceWorkerRegistration,
                                          msg: "getRegistrations returns an array of ServiceWorkerRegistration objects" }, "*");
              if (a[i].scope.match(/simpleregister\//)) {
                a[i].onupdatefound = function(e) {
                  eventReceived();
                }
              }
            }
          });

          navigator.serviceWorker.getRegistration('http://mochi.test:8888/tests/dom/workers/test/serviceworkers/simpleregister/')
            .then(function(a) {
            window.parent.postMessage({ type: "check", status: a instanceof ServiceWorkerRegistration,
                                        msg: "getRegistration returns a ServiceWorkerRegistration" }, "*");
            a.onupdatefound = function(e) {
              eventReceived();
            }
          });

          navigator.serviceWorker.getRegistration('http://www.something_else.net/')
            .then(function(a) {
            window.parent.postMessage({ type: "check", status: false,
                                        msg: "getRegistration should throw for security error!" }, "*");
          }, function(a) {
            window.parent.postMessage({ type: "check", status: true,
                                        msg: "getRegistration should throw for security error!" }, "*");
          });

          window.parent.postMessage({ type: "ready" }, "*");
      </script>
  </body>
</html>