Chromium Code Reviews| Index: LayoutTests/http/tests/notifications/resources/test-helpers.js |
| diff --git a/LayoutTests/http/tests/notifications/resources/test-helpers.js b/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| index 7706199464431c09c5f6227d61b80ffd1f5d7637..81d584effbc49334d5fe80b5f3ba872d7204db04 100644 |
| --- a/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| +++ b/LayoutTests/http/tests/notifications/resources/test-helpers.js |
| @@ -36,4 +36,33 @@ function sharedWorkerTest(script) |
| function isDedicatedOrSharedWorker() |
| { |
| return false; |
| -} |
| +} |
| + |
| +// Unregisters, then registers the Service Worker in |script| using |scope|, waits |
| +// for it to activate and then inserts a message port. Returns a Promise which will |
| +// be resolved with an object having the worker's registration and port. The |
| +// Service Worker will be automatically unregistered once the test has completed. |
| +function getActiveServiceWorkerWithMessagePort(test, script, scope) |
| +{ |
| + var registration = null; |
| + return service_worker_unregister_and_register(test, script, scope).then(function (swRegistration) { |
|
Michael van Ouwerkerk
2015/01/26 16:52:37
Please don't leave space between 'function' and '(
Peter Beverloo
2015/01/27 11:16:56
Done.
|
| + registration = swRegistration; |
| + add_completion_callback(function() { |
| + registration.unregister(); |
| + }); |
| + |
| + return wait_for_state(test, registration.installing, 'activated'); |
| + }).then(function () { |
| + assert_not_equals(registration.active, null, 'The Service Worker needs to be activated.'); |
| + return new Promise(function (resolve) { |
| + var messageChannel = new MessageChannel(); |
| + messageChannel.port1.addEventListener('message', function(event) { |
| + if (event.data == 'ready') |
| + resolve({ registration: registration, port: messageChannel.port1 }); |
| + }); |
| + |
| + registration.active.postMessage(messageChannel.port2, [messageChannel.port2]); |
| + messageChannel.port1.start(); |
| + }); |
| + }); |
| +} |