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

Side by Side Diff: LayoutTests/http/tests/serviceworker/resources/test-helpers.js

Issue 531423002: ServiceWorker: Clean up fetch-event.html (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: introduce wait_fo_activated Created 6 years, 3 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
« no previous file with comments | « LayoutTests/http/tests/serviceworker/fetch-event.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Adapter for testharness.js-style tests with Service Workers 1 // Adapter for testharness.js-style tests with Service Workers
2 2
3 // Can only be used with a worker that installs successfully, since it 3 // Can only be used with a worker that installs successfully, since it
4 // first registers to acquire a ServiceWorkerRegistration object to 4 // first registers to acquire a ServiceWorkerRegistration object to
5 // unregister. 5 // unregister.
6 // FIXME: Use getRegistration() when implemented. 6 // FIXME: Use getRegistration() when implemented.
7 function service_worker_unregister_and_register(test, url, scope) { 7 function service_worker_unregister_and_register(test, url, scope) {
8 if (!scope || scope.length == 0) 8 if (!scope || scope.length == 0)
9 return Promise.reject(new Error('tests must define a scope')); 9 return Promise.reject(new Error('tests must define a scope'));
10 10
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 function wait_for_state(test, worker, state) { 76 function wait_for_state(test, worker, state) {
77 return new Promise(test.step_func(function(resolve) { 77 return new Promise(test.step_func(function(resolve) {
78 worker.addEventListener('statechange', test.step_func(function() { 78 worker.addEventListener('statechange', test.step_func(function() {
79 if (worker.state === state) 79 if (worker.state === state)
80 resolve(state); 80 resolve(state);
81 })); 81 }));
82 })); 82 }));
83 } 83 }
84 84
85 function wait_for_activated(test, registration) {
86 var expected_state = 'activated';
87 if (registration.active) {
88 if (registration.active.state === expected_state)
89 return Promise.resolve(registration.active);
90 else
91 return wait_for_state(test, registration.active, expected_state);
92 }
93 if (registration.waiting)
94 return wait_for_state(test, registration.waiting, expected_state);
95 if (registration.installing)
96 return wait_for_state(test, registration.installing, expected_state);
97 return Promise.reject(
98 new Error('registration must have at least one version'));
99 }
100
85 (function() { 101 (function() {
86 function fetch_tests_from_worker(worker) { 102 function fetch_tests_from_worker(worker) {
87 return new Promise(function(resolve, reject) { 103 return new Promise(function(resolve, reject) {
88 var messageChannel = new MessageChannel(); 104 var messageChannel = new MessageChannel();
89 messageChannel.port1.addEventListener('message', function(message) { 105 messageChannel.port1.addEventListener('message', function(message) {
90 if (message.data.type == 'complete') { 106 if (message.data.type == 'complete') {
91 synthesize_tests(message.data.tests, message.data.status); 107 synthesize_tests(message.data.tests, message.data.status);
92 resolve(); 108 resolve();
93 } 109 }
94 }); 110 });
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, 175 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT,
160 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, 176 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT,
161 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT, 177 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT,
162 UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PO RT 178 UNAUTHENTICATED_ORIGIN: 'http://' + UNAUTHENTICATED_HOST + ':' + HTTP_PO RT
163 }; 179 };
164 } 180 }
165 181
166 function base_path() { 182 function base_path() {
167 return location.pathname.replace(/\/[^\/]*$/, '/'); 183 return location.pathname.replace(/\/[^\/]*$/, '/');
168 } 184 }
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/serviceworker/fetch-event.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698