summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/service-workers/service-worker/resources/import-scripts-updated-flag-worker.js
blob: e01664662ef178a1dfe51c5970392d0fb66c7234 (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
importScripts('/resources/testharness.js');

let echo_output = null;

// Tests importing a script that sets |echo_output| to the query string.
function test_import(str) {
  echo_output = null;
  importScripts('import-scripts-echo.py?msg=' + str);
  assert_equals(echo_output, str);
}

test_import('root');
test_import('root-and-message');

self.addEventListener('install', () => {
    test_import('install');
    test_import('install-and-message');
  });

self.addEventListener('message', e => {
    var error = null;
    echo_output = null;

    try {
      importScripts('import-scripts-echo.py?msg=' + e.data);
    } catch (e) {
      error = e && e.name;
    }

    e.source.postMessage({ error: error, value: echo_output });
  });