summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/registration-tests-script.js
blob: e5bdaf4291a4205fb5205eab0c76ec0bc02bdd7b (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
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
// Registration tests that mostly exercise the service worker script contents or
// response.
function registration_tests_script(register_method, type) {
  promise_test(function(t) {
      var script = 'resources/invalid-chunked-encoding.py';
      var scope = 'resources/scope/invalid-chunked-encoding/';
      return promise_rejects_js(t,
          TypeError,
          register_method(script, {scope: scope}),
          'Registration of invalid chunked encoding script should fail.');
    }, 'Registering invalid chunked encoding script');

  promise_test(function(t) {
      var script = 'resources/invalid-chunked-encoding-with-flush.py';
      var scope = 'resources/scope/invalid-chunked-encoding-with-flush/';
      return promise_rejects_js(t,
          TypeError,
          register_method(script, {scope: scope}),
          'Registration of invalid chunked encoding script should fail.');
    }, 'Registering invalid chunked encoding script with flush');

  promise_test(function(t) {
      var script = 'resources/malformed-worker.py?parse-error';
      var scope = 'resources/scope/parse-error';
      return promise_rejects_js(t,
          TypeError,
          register_method(script, {scope: scope}),
          'Registration of script including parse error should fail.');
    }, 'Registering script including parse error');

  promise_test(function(t) {
      var script = 'resources/malformed-worker.py?undefined-error';
      var scope = 'resources/scope/undefined-error';
      return promise_rejects_js(t,
          TypeError,
          register_method(script, {scope: scope}),
          'Registration of script including undefined error should fail.');
    }, 'Registering script including undefined error');

  promise_test(function(t) {
      var script = 'resources/malformed-worker.py?uncaught-exception';
      var scope = 'resources/scope/uncaught-exception';
      return promise_rejects_js(t,
          TypeError,
          register_method(script, {scope: scope}),
          'Registration of script including uncaught exception should fail.');
    }, 'Registering script including uncaught exception');

  if (type === 'classic') {
    promise_test(function(t) {
        var script = 'resources/malformed-worker.py?import-malformed-script';
        var scope = 'resources/scope/import-malformed-script';
        return promise_rejects_js(t,
            TypeError,
            register_method(script, {scope: scope}),
            'Registration of script importing malformed script should fail.');
      }, 'Registering script importing malformed script');
  }

  if (type === 'module') {
    promise_test(function(t) {
        var script = 'resources/malformed-worker.py?top-level-await';
        var scope = 'resources/scope/top-level-await';
        return promise_rejects_js(t,
            TypeError,
            register_method(script, {scope: scope}),
            'Registration of script with top-level await should fail.');
      }, 'Registering script with top-level await');

    promise_test(function(t) {
        var script = 'resources/malformed-worker.py?instantiation-error';
        var scope = 'resources/scope/instantiation-error';
        return promise_rejects_js(t,
            TypeError,
            register_method(script, {scope: scope}),
            'Registration of script with module instantiation error should fail.');
      }, 'Registering script with module instantiation error');

    promise_test(function(t) {
        var script = 'resources/malformed-worker.py?instantiation-error-and-top-level-await';
        var scope = 'resources/scope/instantiation-error-and-top-level-await';
        return promise_rejects_js(t,
            TypeError,
            register_method(script, {scope: scope}),
            'Registration of script with module instantiation error and top-level await should fail.');
      }, 'Registering script with module instantiation error and top-level await');
  }

  promise_test(function(t) {
      var script = 'resources/no-such-worker.js';
      var scope = 'resources/scope/no-such-worker';
      return promise_rejects_js(t,
          TypeError,
          register_method(script, {scope: scope}),
          'Registration of non-existent script should fail.');
    }, 'Registering non-existent script');

  if (type === 'classic') {
    promise_test(function(t) {
        var script = 'resources/malformed-worker.py?import-no-such-script';
        var scope = 'resources/scope/import-no-such-script';
        return promise_rejects_js(t,
            TypeError,
            register_method(script, {scope: scope}),
            'Registration of script importing non-existent script should fail.');
      }, 'Registering script importing non-existent script');
  }

  promise_test(function(t) {
      var script = 'resources/malformed-worker.py?caught-exception';
      var scope = 'resources/scope/caught-exception';
      return register_method(script, {scope: scope})
        .then(function(registration) {
            assert_true(
              registration instanceof ServiceWorkerRegistration,
              'Successfully registered.');
            return registration.unregister();
          });
    }, 'Registering script including caught exception');

}