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

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

Issue 466723002: ServiceWorker: Enable ServiceWorkerRegistration and update layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@updatefound
Patch Set: rebase 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
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) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 }); 52 });
53 iframe.src = ''; 53 iframe.src = '';
54 iframe.remove(); 54 iframe.remove();
55 return saw_unload; 55 return saw_unload;
56 } 56 }
57 57
58 function normalizeURL(url) { 58 function normalizeURL(url) {
59 return new URL(url, document.location).toString().replace(/#.*$/, ''); 59 return new URL(url, document.location).toString().replace(/#.*$/, '');
60 } 60 }
61 61
62 function wait_for_update(test, registration) {
63 return new Promise(test.step_func(function(resolve) {
64 registration.addEventListener('updatefound', test.step_func(function() {
65 resolve(registration.installing);
66 }));
67 }));
68 }
69
62 function wait_for_state(test, worker, state) { 70 function wait_for_state(test, worker, state) {
63 return new Promise(test.step_func(function(resolve, reject) { 71 return new Promise(test.step_func(function(resolve) {
64 worker.addEventListener('statechange', test.step_func(function() { 72 worker.addEventListener('statechange', test.step_func(function() {
65 if (worker.state === state) 73 if (worker.state === state)
66 resolve(state); 74 resolve(state);
67 })); 75 }));
68 })); 76 }));
69 } 77 }
70 78
71 (function() { 79 (function() {
72 function fetch_tests_from_worker(worker) { 80 function fetch_tests_from_worker(worker) {
73 return new Promise(function(resolve, reject) { 81 return new Promise(function(resolve, reject) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 113 }
106 } 114 }
107 }; 115 };
108 116
109 function service_worker_test(url, description) { 117 function service_worker_test(url, description) {
110 var scope = window.location.origin + '/service-worker-scope/' + 118 var scope = window.location.origin + '/service-worker-scope/' +
111 window.location.pathname; 119 window.location.pathname;
112 120
113 var test = async_test(description); 121 var test = async_test(description);
114 service_worker_unregister_and_register(test, url, scope) 122 service_worker_unregister_and_register(test, url, scope)
123 .then(function(registration) {
124 return wait_for_update(test, registration);
125 })
115 .then(function(worker) { return fetch_tests_from_worker(worker); }) 126 .then(function(worker) { return fetch_tests_from_worker(worker); })
116 .then(function() { return navigator.serviceWorker.unregister(scope); }) 127 .then(function() { return navigator.serviceWorker.unregister(scope); })
117 .then(function() { test.done(); }) 128 .then(function() { test.done(); })
118 .catch(test.step_func(function(e) { throw e; })); 129 .catch(test.step_func(function(e) { throw e; }));
119 }; 130 };
120 131
121 self.service_worker_test = service_worker_test; 132 self.service_worker_test = service_worker_test;
122 })(); 133 })();
123 134
124 function get_host_info() { 135 function get_host_info() {
(...skipping 15 matching lines...) Expand all
140 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT, 151 HTTP_ORIGIN: 'http://' + ORIGINAL_HOST + ':' + HTTP_PORT,
141 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT, 152 HTTPS_ORIGIN: 'https://' + ORIGINAL_HOST + ':' + HTTPS_PORT,
142 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT, 153 HTTP_REMOTE_ORIGIN: 'http://' + REMOTE_HOST + ':' + HTTP_PORT,
143 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT 154 HTTPS_REMOTE_ORIGIN: 'https://' + REMOTE_HOST + ':' + HTTPS_PORT
144 }; 155 };
145 } 156 }
146 157
147 function base_path() { 158 function base_path() {
148 return location.pathname.replace(/\/[^\/]*$/, '/'); 159 return location.pathname.replace(/\/[^\/]*$/, '/');
149 } 160 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698