Modernize update-bytecheck.https.html and split into two files
The test sometimes fails due to timeout on Windows. This CL splits the
test into two to mitigate the workload.
Bug: 1002377, 1150000
Change-Id: I1cfb2198b304cc21e3aeb9dc00b4db66e7eeb4e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546145
Commit-Queue: Makoto Shimazu <shimazu@chromium.org>
Reviewed-by: Asami Doi <asamidoi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828656}
diff --git a/service-workers/service-worker/update-bytecheck-cors-import.https.html b/service-workers/service-worker/update-bytecheck-cors-import.https.html
new file mode 100644
index 0000000..de7023c
--- /dev/null
+++ b/service-workers/service-worker/update-bytecheck-cors-import.https.html
@@ -0,0 +1,59 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<meta name="timeout" content="long">
+<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 src="/common/get-host-info.sub.js"></script>
+<script>
+// Tests of updating a service worker. This file contains cors cases only.
+// The cases of cors: false are in update-bytecheck.https.html.
+
+/*
+ * @param string main
+ * Decide the content of the main script, where 'default' is for constant
+ * content while 'time' is for time-variant content.
+ * @param string imported
+ * Decide the content of the imported script, where 'default' is for constant
+ * content while 'time' is for time-variant content.
+ */
+const settings = [{main: 'default', imported: 'default'},
+ {main: 'default', imported: 'time' },
+ {main: 'time', imported: 'default'},
+ {main: 'time', imported: 'time' }];
+
+const host_info = get_host_info();
+settings.forEach(({cors, main, imported}) => {
+ promise_test(async (t) => {
+ // Specify a cross origin path to load imported scripts from a cross origin.
+ const path = host_info.HTTPS_REMOTE_ORIGIN +
+ '/service-workers/service-worker/resources/';
+ const script = 'resources/bytecheck-worker.py' +
+ '?main=' + main +
+ '&imported=' + imported +
+ '&path=' + path;
+ const scope = 'resources/blank.html';
+
+ // Register a service worker.
+ const swr = await service_worker_unregister_and_register(t, script, scope);
+ t.add_cleanup(() => swr.unregister());
+ const sw = await wait_for_update(t, swr);
+ await wait_for_state(t, sw, 'activated');
+ assert_array_equals([swr.active, swr.waiting, swr.installing],
+ [sw, null, null]);
+
+ // Update the service worker registration.
+ await swr.update();
+
+ // If there should be a new service worker.
+ if (main === 'time' || imported === 'time') {
+ return wait_for_update(t, swr);
+ }
+ // Otherwise, make sure there is no newly created service worker.
+ assert_array_equals([swr.active, swr.waiting, swr.installing],
+ [sw, null, null]);
+ }, `Test(main: ${main}, imported: ${imported})`);
+});
+</script>
diff --git a/service-workers/service-worker/update-bytecheck.https.html b/service-workers/service-worker/update-bytecheck.https.html
index 6628dba..3329938 100644
--- a/service-workers/service-worker/update-bytecheck.https.html
+++ b/service-workers/service-worker/update-bytecheck.https.html
@@ -8,10 +8,10 @@
<script src="resources/test-helpers.sub.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script>
+// Tests of updating a service worker. This file contains non-cors cases only.
+// The cases of cors: true are in update-bytecheck-cors-import.https.html.
/*
- * @param bolean cors
- * Determine wether the imported script should be a cross origin script.
* @param string main
* Decide the content of the main script, where 'default' is for constant
* content while 'time' is for time-variant content.
@@ -19,57 +19,40 @@
* Decide the content of the imported script, where 'default' is for constant
* content while 'time' is for time-variant content.
*/
-const settings = [{cors: false, main: 'default', imported: 'default'},
- {cors: false, main: 'default', imported: 'time' },
- {cors: false, main: 'time', imported: 'default'},
- {cors: false, main: 'time', imported: 'time' },
- {cors: true, main: 'default', imported: 'default'},
- {cors: true, main: 'default', imported: 'time' },
- {cors: true, main: 'time', imported: 'default'},
- {cors: true, main: 'time', imported: 'time' }];
+const settings = [{main: 'default', imported: 'default'},
+ {main: 'default', imported: 'time' },
+ {main: 'time', imported: 'default'},
+ {main: 'time', imported: 'time' }];
const host_info = get_host_info();
-settings.reduce((p, s) => {
- return p.then(promise_test(function(t) {
- var path = !s.cors ? ''
- : host_info.HTTPS_REMOTE_ORIGIN +
- '/service-workers/service-worker/resources/';
- var script = 'resources/bytecheck-worker.py' +
- '?main=' + s.main +
- '&imported=' + s.imported +
- '&path=' + path;
- var scope = 'resources/blank.html';
+settings.forEach(({main, imported}) => {
+ promise_test(async (t) => {
+ // Empty path results in the same origin imported scripts.
+ const path = '';
+ const script = 'resources/bytecheck-worker.py' +
+ '?main=' + main +
+ '&imported=' + imported +
+ '&path=' + path;
+ const scope = 'resources/blank.html';
- var swr, sw;
- return Promise.resolve()
- // Register a service worker.
- .then(_ => service_worker_unregister_and_register(t, script, scope))
- .then(r => {
- t.add_cleanup(() => service_worker_unregister(t, scope));
- swr = r;
- return wait_for_update(t, swr);
- })
- .then(w => sw = w)
- .then(_ => wait_for_state(t, sw, 'activated'))
- .then(_ => assert_array_equals([swr.active,
- swr.waiting,
- swr.installing],
- [sw, null, null]))
+ // Register a service worker.
+ const swr = await service_worker_unregister_and_register(t, script, scope);
+ t.add_cleanup(() => swr.unregister());
+ const sw = await wait_for_update(t, swr);
+ await wait_for_state(t, sw, 'activated');
+ assert_array_equals([swr.active, swr.waiting, swr.installing],
+ [sw, null, null]);
- // Update the service worker registration.
- .then(_ => swr.update())
- .then(_ => {
- // If there should be a new service worker.
- if (s.main === 'time' || s.imported === 'time') {
- return wait_for_update(t, swr);
- }
- // Otherwise, make sure there is no newly created service worker.
- assert_array_equals([swr.active,
- swr.waiting,
- swr.installing],
- [sw, null, null]);
- });
- }, `Test(cors: ${s.cors}, main: ${s.main}, imported: ${s.imported})`));
-}, Promise.resolve());
+ // Update the service worker registration.
+ await swr.update();
+ // If there should be a new service worker.
+ if (main === 'time' || imported === 'time') {
+ return wait_for_update(t, swr);
+ }
+ // Otherwise, make sure there is no newly created service worker.
+ assert_array_equals([swr.active, swr.waiting, swr.installing],
+ [sw, null, null]);
+ }, `Test(main: ${main}, imported: ${imported})`);
+});
</script>