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

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

Issue 416003003: Test for register canceling an unregister. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: mostly formatting fix Created 6 years, 4 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 | Annotate | Revision Log
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 var options = scope ? { scope: scope } : {}; 4 var options = scope ? { scope: scope } : {};
5 return navigator.serviceWorker.unregister(scope).then( 5 return navigator.serviceWorker.unregister(scope).then(
6 test.step_func(function() { 6 test.step_func(function() {
7 return navigator.serviceWorker.register(url, options); 7 return navigator.serviceWorker.register(url, options);
8 }), 8 }),
9 unreached_rejection(test, 'Unregister should not fail') 9 unreached_rejection(test, 'Unregister should not fail')
10 ).then(test.step_func(function(worker) { 10 ).then(test.step_func(function(worker) {
11 return Promise.resolve(worker); 11 return Promise.resolve(worker);
12 }), 12 }),
13 unreached_rejection(test, 'Registration should not fail') 13 unreached_rejection(test, 'Registration should not fail')
14 ); 14 );
15 } 15 }
16 16
17 function service_worker_unregister_and_done(test, scope) { 17 function service_worker_unregister_and_done(test, scope) {
18 return navigator.serviceWorker.unregister(scope).then( 18 return navigator.serviceWorker.unregister(scope).then(
19 test.done.bind(test), 19 test.done.bind(test),
20 unreached_rejection(test, 'Unregister should not fail')); 20 unreached_rejection(test, 'Unregister should not fail'));
21 } 21 }
22 22
23 // Rejection-specific helper that provides more details 23 // Rejection-specific helper that provides more details
24 function unreached_rejection(test, prefix) { 24 function unreached_rejection(test, prefix) {
25 return test.step_func(function(error) { 25 return test.step_func(function(error) {
26 var reason = error.name ? error.name : error; 26 var reason = error.message || error.name || error;
27 var prefix = prefix ? prefix : "unexpected rejection"; 27 var error_prefix = prefix || 'unexpected rejection';
28 assert_unreached(prefix + ': ' + reason); 28 assert_unreached(error_prefix + ': ' + reason);
29 }); 29 });
30 } 30 }
31 31
32 // FIXME: Clean up the iframe when the test completes. 32 // FIXME: Clean up the iframe when the test completes.
33 function with_iframe(url, f) { 33 function with_iframe(url, f) {
34 return new Promise(function(resolve, reject) { 34 return new Promise(function(resolve, reject) {
35 var frame = document.createElement('iframe'); 35 var frame = document.createElement('iframe');
36 frame.src = url; 36 frame.src = url;
37 frame.onload = function() { 37 frame.onload = function() {
38 if (f) { 38 if (f) {
39 f(frame); 39 f(frame);
40 } 40 }
41 resolve(frame); 41 resolve(frame);
42 }; 42 };
43 document.body.appendChild(frame); 43 document.body.appendChild(frame);
44 }); 44 });
45 } 45 }
46 46
47 function unload_iframe(iframe) {
48 var saw_unload = new Promise(function(resolve) {
49 iframe.contentWindow.addEventListener('unload', function() {
50 resolve();
51 });
52 });
53 iframe.src = '';
54 iframe.remove();
55 return saw_unload;
56 }
57
47 function normalizeURL(url) { 58 function normalizeURL(url) {
48 return new URL(url, document.location).toString().replace(/#.*$/, ''); 59 return new URL(url, document.location).toString().replace(/#.*$/, '');
49 } 60 }
50 61
51 function wait_for_state(test, worker, state) { 62 function wait_for_state(test, worker, state) {
52 return new Promise(test.step_func(function(resolve, reject) { 63 return new Promise(test.step_func(function(resolve, reject) {
53 worker.addEventListener('statechange', test.step_func(function() { 64 worker.addEventListener('statechange', test.step_func(function() {
54 if (worker.state === state) 65 if (worker.state === state)
55 resolve(state); 66 resolve(state);
56 })); 67 }));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, 140 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT,
130 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, 141 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT,
131 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, 142 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT,
132 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT 143 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT
133 }; 144 };
134 } 145 }
135 146
136 function base_path() { 147 function base_path() {
137 return location.pathname.replace(/\/[^\/]*$/, '/'); 148 return location.pathname.replace(/\/[^\/]*$/, '/');
138 } 149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698