summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/register-default-scope.https.html
blob: dc136d4e8dd74d3f851880a2bc4ff5f215caf256 (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
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<title>register() and scope</title>
<script src="/resources/testharness.js"></script>
<script src="resources/testharness-helpers.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>

promise_test(function(t) {
    var script = 'resources/empty-worker.js';
    var script_url = new URL(script, location.href);
    var expected_scope = new URL('./', script_url).href;
    return service_worker_unregister(t, expected_scope)
      .then(function() {
        return navigator.serviceWorker.register('resources/empty-worker.js');
      }).then(function(registration) {
        assert_equals(registration.scope, expected_scope,
                      'The default scope should be URL("./", script_url)');
        return registration.unregister();
      }).then(function() {
        t.done();
      });
  }, 'default scope');

promise_test(function(t) {
    // This script must be different than the 'default scope' test, or else
    // the scopes will collide.
    var script = 'resources/empty.js';
    var script_url = new URL(script, location.href);
    var expected_scope = new URL('./', script_url).href;
    return service_worker_unregister(t, expected_scope)
      .then(function() {
        return navigator.serviceWorker.register('resources/empty.js',
                                                { scope: undefined });
      }).then(function(registration) {
        assert_equals(registration.scope, expected_scope,
                      'The default scope should be URL("./", script_url)');
        return registration.unregister();
      }).then(function() {
        t.done();
      });
  }, 'undefined scope');

promise_test(function(t) {
    var script = 'resources/simple-fetch-worker.js';
    var script_url = new URL(script, location.href);
    var expected_scope = new URL('./', script_url).href;
    return service_worker_unregister(t, expected_scope)
      .then(function() {
        return navigator.serviceWorker.register('resources/empty.js',
                                                { scope: null });
      })
      .then(
        function(registration) {
          assert_unreached('register should fail');
          service_worker_unregister_and_done(t, registration.scope);
        },
        function(error) {
          assert_equals(error.name, 'SecurityError',
                        'passing a null scope should be interpreted as ' +
                        'scope="null" which violates the path restriction');
          t.done();
        });
  }, 'null scope');

</script>