Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/import-scripts-updated-flag.https.html

Issue 2864783002: Upstream service wrkr `importScripts` tests to WPT (Closed)
Patch Set: Incorporate review feedback Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <meta charset="utf-8">
3 <title>Tests for importScripts: import scripts updated flag</title>
4 <script src="/resources/testharness.js"></script>
5 <script src="/resources/testharnessreport.js"></script>
6 <script src="resources/test-helpers.sub.js"></script>
7 <body>
8 <script>
9 // This test registers a worker that calls importScripts at various stages of
10 // service worker lifetime. The sub-tests trigger subsequent `importScript`
11 // invocations via the `message` event.
12
13 var register;
14
15 function post_and_wait_for_reply(worker, message) {
16 return new Promise(resolve => {
17 navigator.serviceWorker.onmessage = e => { resolve(e.data); };
18 worker.postMessage(message);
19 });
20 }
21
22 promise_test(function(t) {
23 const scope = 'resources/import-scripts-updated-flag';
24 let registration;
25
26 register = service_worker_unregister_and_register(
27 t, 'resources/import-scripts-updated-flag-worker.js', scope)
28 .then(r => {
29 registration = r;
30 add_completion_callback(() => { registration.unregister(); });
31 return wait_for_state(t, registration.installing, 'activated');
32 })
33 .then(() => {
34 // This test should not be considered complete until after the
35 // service worker has been unregistered. Currently, `testharness.js`
36 // does not support asynchronous global "tear down" logic, so this
37 // must be expressed using a dedicated `promise_test`. Because the
38 // other sub-tests in this file are declared synchronously, this test
39 // will be the final test executed.
40 promise_test(function(t) {
41 return registration.unregister();
42 });
43
44 return registration.active;
45 });
46
47 return register;
48 }, 'initialize global state');
49
50 promise_test(t => {
51 return register
52 .then(function(worker) {
53 return post_and_wait_for_reply(worker, 'root-and-message');
54 })
55 .then(result => {
56 assert_equals(result.error, null);
57 assert_equals(result.value, 'root-and-message');
58 });
59 }, 'import script previously imported at worker evaluation time');
60
61 promise_test(t => {
62 return register
63 .then(function(worker) {
64 return post_and_wait_for_reply(worker, 'install-and-message');
65 })
66 .then(result => {
67 assert_equals(result.error, null);
68 assert_equals(result.value, 'install-and-message');
69 });
70 }, 'import script previously imported at worker install time');
71
72 promise_test(t => {
73 return register
74 .then(function(worker) {
75 return post_and_wait_for_reply(worker, 'message');
76 })
77 .then(result => {
78 assert_equals(result.error, 'TypeError');
79 assert_equals(result.value, null);
80 });
81 }, 'import script not previously imported');
82 </script>
83 </body>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698