summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/controller-on-reload.https.html
blob: 4490c707963bd9371b997bdbfd0819c6fccc9b78 (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
52
53
54
<!DOCTYPE html>
<title>Service Worker: Controller on reload</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<body>
<script>
promise_test(function(t) {
    var scope = 'resources/blank.html';
    var frame;
    var registration;
    var controller;
    return service_worker_unregister(t, scope)
      .then(function() {
          return with_iframe(scope);
        })
      .then(function(f) {
          frame = f;
          return frame.contentWindow.navigator.serviceWorker.register(
              'resources/empty-worker.js', {scope: scope});
        })
      .then(function(swr) {
          registration = swr;
          return wait_for_state(t, registration.installing, 'activated');
        })
      .then(function() {
          var w = frame.contentWindow;
          assert_equals(w.navigator.serviceWorker.controller, null,
                        'controller should be null until the document is ' +
                        'reloaded');
          return new Promise(function(resolve) {
              frame.onload = function() { resolve(); }
              w.location.reload();
            });
        })
      .then(function() {
          var w = frame.contentWindow;
          controller = w.navigator.serviceWorker.controller;
          assert_true(controller instanceof w.ServiceWorker,
                      'controller should be a ServiceWorker object upon reload');

          // objects from separate windows should not be equal
          assert_not_equals(controller, registration.active);

          return w.navigator.serviceWorker.getRegistration();
        })
      .then(function(frameRegistration) {
          assert_equals(frameRegistration.active, controller);
          frame.remove();
          service_worker_unregister_and_done(t, scope);
        });
  }, 'controller is set upon reload after registration');
</script>
</body>