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

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

Issue 1828063002: Add support for origin trials in workers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@trial-token-in-header-blink-document
Patch Set: fix test flakyness Created 4 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
1 // Adapter for testharness.js-style tests with Service Workers 1 // Adapter for testharness.js-style tests with Service Workers
2 2
3 function service_worker_unregister_and_register(test, url, scope) { 3 function service_worker_unregister_and_register(test, url, scope) {
4 if (!scope || scope.length == 0) 4 if (!scope || scope.length == 0)
5 return Promise.reject(new Error('tests must define a scope')); 5 return Promise.reject(new Error('tests must define a scope'));
6 6
7 var options = { scope: scope }; 7 var options = { scope: scope };
8 return service_worker_unregister(test, scope) 8 return service_worker_unregister(test, scope)
9 .then(function() { 9 .then(function() {
10 return navigator.serviceWorker.register(url, options); 10 return navigator.serviceWorker.register(url, options);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 })); 142 }));
143 })); 143 }));
144 } 144 }
145 145
146 // Declare a test that runs entirely in the ServiceWorkerGlobalScope. The |url| 146 // Declare a test that runs entirely in the ServiceWorkerGlobalScope. The |url|
147 // is the service worker script URL. This function: 147 // is the service worker script URL. This function:
148 // - Instantiates a new test with the description specified in |description|. 148 // - Instantiates a new test with the description specified in |description|.
149 // The test will succeed if the specified service worker can be successfully 149 // The test will succeed if the specified service worker can be successfully
150 // registered and installed. 150 // registered and installed.
151 // - Creates a new ServiceWorker registration with a scope unique to the current 151 // - Creates a new ServiceWorker registration with a scope unique to the current
152 // document URL. Note that this doesn't allow more than one 152 // document URL and the script URL. This allows more than one
153 // service_worker_test() to be run from the same document. 153 // service_worker_test() to be run from the same document.
154 // - Waits for the new worker to begin installing. 154 // - Waits for the new worker to begin installing.
155 // - Imports tests results from tests running inside the ServiceWorker. 155 // - Imports tests results from tests running inside the ServiceWorker.
156 function service_worker_test(url, description) { 156 function service_worker_test(url, description) {
157 // If the document URL is https://example.com/document and the script URL is 157 // If the document URL is https://example.com/document and the script URL is
158 // https://example.com/script/worker.js, then the scope would be 158 // https://example.com/script/worker.js, then the scope would be
159 // https://example.com/script/scope/document. 159 // https://example.com/script/scope/document/script/worker.js.
160 var scope = new URL('scope' + window.location.pathname, 160 var document_path = window.location.pathname;
161 var script_path = new URL(url, window.location).pathname;
162 var scope = new URL('scope' + document_path + script_path,
161 new URL(url, window.location)).toString(); 163 new URL(url, window.location)).toString();
162 promise_test(function(test) { 164 promise_test(function(test) {
163 return service_worker_unregister_and_register(test, url, scope) 165 return service_worker_unregister_and_register(test, url, scope)
164 .then(function(registration) { 166 .then(function(registration) {
165 add_completion_callback(function() { 167 add_completion_callback(function() {
166 registration.unregister(); 168 registration.unregister();
167 }); 169 });
168 return wait_for_update(test, registration) 170 return wait_for_update(test, registration)
169 .then(function(worker) { 171 .then(function(worker) {
170 return fetch_tests_from_worker(worker); 172 return fetch_tests_from_worker(worker);
(...skipping 26 matching lines...) Expand all
197 199
198 function login(test, local, remote) { 200 function login(test, local, remote) {
199 var suffix = (local.indexOf("https") != -1) ? "s": ""; 201 var suffix = (local.indexOf("https") != -1) ? "s": "";
200 return test_login(test, local, 'username1' + suffix, 'password1' + suffix, 202 return test_login(test, local, 'username1' + suffix, 'password1' + suffix,
201 'cookie1') 203 'cookie1')
202 .then(function() { 204 .then(function() {
203 return test_login(test, remote, 'username2' + suffix, 205 return test_login(test, remote, 'username2' + suffix,
204 'password2' + suffix, 'cookie2'); 206 'password2' + suffix, 'cookie2');
205 }); 207 });
206 } 208 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698