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

Side by Side Diff: LayoutTests/http/tests/serviceworker/getregistrations.html

Issue 1216203003: Replace all sequential_promise_tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@update-testharnessjs
Patch Set: Created 5 years, 5 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
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <title>Service Worker: getRegistrations()</title> 2 <title>Service Worker: getRegistrations()</title>
3 <script src="../resources/testharness.js"></script> 3 <script src="../resources/testharness.js"></script>
4 <script src="../resources/testharnessreport.js"></script> 4 <script src="../resources/testharnessreport.js"></script>
5 <script src="../resources/testharness-helpers.js"></script>
6 <script src="resources/test-helpers.js"></script> 5 <script src="resources/test-helpers.js"></script>
7 <script src="../resources/get-host-info.js"></script> 6 <script src="../resources/get-host-info.js"></script>
8 <script> 7 <script>
9 // Purge the existing registrations for the origin. 8 // Purge the existing registrations for the origin.
10 // getRegistrations() is used in order to avoid adding additional complexity 9 // getRegistrations() is used in order to avoid adding additional complexity
11 // e.g. adding an internal function. 10 // e.g. adding an internal function.
12 sequential_promise_test(function(t) { 11 promise_test(function(t) {
13 var resolve; 12 var resolve;
14 var timer; 13 var timer;
15 var p = new Promise(function(r) { resolve = r; }); 14 var p = new Promise(function(r) { resolve = r; });
16 navigator.serviceWorker.getRegistrations() 15 navigator.serviceWorker.getRegistrations()
17 .then(function(regs) { 16 .then(function(regs) {
18 return Promise.all(regs.map(function(r) { r.unregister(); })); 17 return Promise.all(regs.map(function(r) { r.unregister(); }));
19 }) 18 })
20 .then(function() { 19 .then(function() {
21 // As registration.unregister() promises resolve before the 20 // As registration.unregister() promises resolve before the
22 // corresponding registrations are deleted from the storage, we must 21 // corresponding registrations are deleted from the storage, we must
23 // wait until the registrations are actually removed from the storage. 22 // wait until the registrations are actually removed from the storage.
24 // Spec reference: https://slightlyoff.github.io/ServiceWorker/spec/se rvice_worker/#unregister-algorithm 23 // Spec reference: https://slightlyoff.github.io/ServiceWorker/spec/se rvice_worker/#unregister-algorithm
25 timer = setInterval(function() { 24 timer = setInterval(function() {
26 navigator.serviceWorker.getRegistrations() 25 navigator.serviceWorker.getRegistrations()
27 .then(function(regs) { 26 .then(function(regs) {
28 if (regs.length == 0) { 27 if (regs.length == 0) {
29 clearInterval(timer); 28 clearInterval(timer);
30 resolve(); 29 resolve();
31 } 30 }
32 }); 31 });
33 }, 100); 32 }, 100);
34 }); 33 });
35 return p; 34 return p;
36 }, 'Purge the existing registrations.'); 35 }, 'Purge the existing registrations.');
37 36
38 sequential_promise_test(function(t) { 37 promise_test(function(t) {
39 var scope = 'resources/scope/getregistrations/normal'; 38 var scope = 'resources/scope/getregistrations/normal';
40 var script = 'resources/empty-worker.js'; 39 var script = 'resources/empty-worker.js';
41 var registrations = []; 40 var registrations = [];
42 return service_worker_unregister_and_register(t, script, scope) 41 return service_worker_unregister_and_register(t, script, scope)
43 .then(function(r) { 42 .then(function(r) {
44 registrations.push(r); 43 registrations.push(r);
45 return navigator.serviceWorker.getRegistrations(); 44 return navigator.serviceWorker.getRegistrations();
46 }) 45 })
47 .then(function(value) { 46 .then(function(value) {
48 assert_array_equals( 47 assert_array_equals(
49 value, 48 value,
50 registrations, 49 registrations,
51 'getRegistrations should resolve with array of registrations.'); 50 'getRegistrations should resolve with array of registrations.');
52 return service_worker_unregister(t, scope); 51 return service_worker_unregister(t, scope);
53 }); 52 });
54 }, 'Register then getRegistrations'); 53 }, 'Register then getRegistrations');
55 54
56 sequential_promise_test(function(t) { 55 promise_test(function(t) {
57 var scope1 = 'resources/scope/getregistrations/scope1'; 56 var scope1 = 'resources/scope/getregistrations/scope1';
58 var scope2 = 'resources/scope/getregistrations/scope2'; 57 var scope2 = 'resources/scope/getregistrations/scope2';
59 var script = 'resources/empty-worker.js'; 58 var script = 'resources/empty-worker.js';
60 var registrations = []; 59 var registrations = [];
61 return service_worker_unregister_and_register(t, script, scope1) 60 return service_worker_unregister_and_register(t, script, scope1)
62 .then(function(r) { 61 .then(function(r) {
63 registrations.push(r); 62 registrations.push(r);
64 return service_worker_unregister_and_register(t, script, scope2); 63 return service_worker_unregister_and_register(t, script, scope2);
65 }) 64 })
66 .then(function(r) { 65 .then(function(r) {
67 registrations.push(r); 66 registrations.push(r);
68 return navigator.serviceWorker.getRegistrations(); 67 return navigator.serviceWorker.getRegistrations();
69 }) 68 })
70 .then(function(value) { 69 .then(function(value) {
71 assert_array_equals( 70 assert_array_equals(
72 value, 71 value,
73 registrations, 72 registrations,
74 'getRegistrations should resolve with array of registrations.'); 73 'getRegistrations should resolve with array of registrations.');
75 return service_worker_unregister(t, scope1); 74 return service_worker_unregister(t, scope1);
76 }) 75 })
77 .then(function() { 76 .then(function() {
78 return service_worker_unregister(t, scope2); 77 return service_worker_unregister(t, scope2);
79 }); 78 });
80 }, 'Register multiple times then getRegistrations'); 79 }, 'Register multiple times then getRegistrations');
81 80
82 sequential_promise_test(function(t) { 81 promise_test(function(t) {
83 var scope = 'resources/scope/getregistrations/register-unregister'; 82 var scope = 'resources/scope/getregistrations/register-unregister';
84 var script = 'resources/empty-worker.js'; 83 var script = 'resources/empty-worker.js';
85 return service_worker_unregister_and_register(t, script, scope) 84 return service_worker_unregister_and_register(t, script, scope)
86 .then(function(registration) { 85 .then(function(registration) {
87 return registration.unregister(); 86 return registration.unregister();
88 }) 87 })
89 .then(function() { 88 .then(function() {
90 return navigator.serviceWorker.getRegistrations(); 89 return navigator.serviceWorker.getRegistrations();
91 }) 90 })
92 .then(function(value) { 91 .then(function(value) {
93 assert_array_equals( 92 assert_array_equals(
94 value, 93 value,
95 [], 94 [],
96 'getRegistrations should resolve with an empty array.'); 95 'getRegistrations should resolve with an empty array.');
97 }); 96 });
98 }, 'Register then Unregister then getRegistrations'); 97 }, 'Register then Unregister then getRegistrations');
99 98
100 sequential_promise_test(function(t) { 99 promise_test(function(t) {
101 // Top-level window's origin: http://127.0.0.1:8000. 100 // Top-level window's origin: http://127.0.0.1:8000.
102 // Frame's origin: http://localhost:8000. 101 // Frame's origin: http://localhost:8000.
103 var host_info = get_host_info(); 102 var host_info = get_host_info();
104 var frame_url = host_info['HTTP_REMOTE_ORIGIN'] + 103 var frame_url = host_info['HTTP_REMOTE_ORIGIN'] +
105 '/serviceworker/resources/frame-for-getregistrations.html'; 104 '/serviceworker/resources/frame-for-getregistrations.html';
106 var scope = 'resources/scope-for-getregistrations'; 105 var scope = 'resources/scope-for-getregistrations';
107 var script = 'resources/empty-worker.js'; 106 var script = 'resources/empty-worker.js';
108 var frame; 107 var frame;
109 var registrations = []; 108 var registrations = [];
110 109
(...skipping 30 matching lines...) Expand all
141 return p; 140 return p;
142 }) 141 })
143 .then(function() { 142 .then(function() {
144 frame.remove(); 143 frame.remove();
145 return service_worker_unregister(t, scope); 144 return service_worker_unregister(t, scope);
146 }); 145 });
147 }, 'getRegistrations promise resolves only with same origin registrations.'); 146 }, 'getRegistrations promise resolves only with same origin registrations.');
148 147
149 done(); 148 done();
150 </script> 149 </script>
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/resources/testharness-helpers.js ('k') | LayoutTests/resources/testharness-helpers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698