Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Supports test-runner control messages being send over |messagePort|, which en able | 1 // Supports test-runner control messages being send over |messagePort|, which en able |
| 2 // workers to have limited access to TestRunner methods. | 2 // workers to have limited access to TestRunner methods. |
| 3 function supportTestRunnerMessagesOnPort(messagePort) | 3 function supportTestRunnerMessagesOnPort(messagePort) |
| 4 { | 4 { |
| 5 if (!window.testRunner) | 5 if (!window.testRunner) |
| 6 return; | 6 return; |
| 7 | 7 |
| 8 messagePort.addEventListener('message', function(message) { | 8 messagePort.addEventListener('message', function(message) { |
| 9 if (message.data.type == 'simulateWebNotificationClick') | 9 if (message.data.type == 'simulateWebNotificationClick') |
| 10 testRunner.simulateWebNotificationClick(message.data.title); | 10 testRunner.simulateWebNotificationClick(message.data.title); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 supportTestRunnerMessagesOnPort(worker.port); | 29 supportTestRunnerMessagesOnPort(worker.port); |
| 30 | 30 |
| 31 fetch_tests_from_worker(worker); | 31 fetch_tests_from_worker(worker); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Used by tests to announce that all tests have been registered when they're | 34 // Used by tests to announce that all tests have been registered when they're |
| 35 // being ran from a dedicated or shared worker. Not necessary for document tests . | 35 // being ran from a dedicated or shared worker. Not necessary for document tests . |
| 36 function isDedicatedOrSharedWorker() | 36 function isDedicatedOrSharedWorker() |
| 37 { | 37 { |
| 38 return false; | 38 return false; |
| 39 } | 39 } |
| 40 | |
| 41 // Unregisters, then registers the Service Worker in |script| using |scope|, wai ts | |
| 42 // for it to activate and then inserts a message port. Returns a Promise which w ill | |
| 43 // be resolved with an object having the worker's registration and port. The | |
| 44 // Service Worker will be automatically unregistered once the test has completed . | |
| 45 function getActiveServiceWorkerWithMessagePort(test, script, scope) | |
| 46 { | |
| 47 var registration = null; | |
| 48 return service_worker_unregister_and_register(test, script, scope).then(func tion (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.
| |
| 49 registration = swRegistration; | |
| 50 add_completion_callback(function() { | |
| 51 registration.unregister(); | |
| 52 }); | |
| 53 | |
| 54 return wait_for_state(test, registration.installing, 'activated'); | |
| 55 }).then(function () { | |
| 56 assert_not_equals(registration.active, null, 'The Service Worker needs t o be activated.'); | |
| 57 return new Promise(function (resolve) { | |
| 58 var messageChannel = new MessageChannel(); | |
| 59 messageChannel.port1.addEventListener('message', function(event) { | |
| 60 if (event.data == 'ready') | |
| 61 resolve({ registration: registration, port: messageChannel.p ort1 }); | |
| 62 }); | |
| 63 | |
| 64 registration.active.postMessage(messageChannel.port2, [messageChanne l.port2]); | |
| 65 messageChannel.port1.start(); | |
| 66 }); | |
| 67 }); | |
| 68 } | |
| OLD | NEW |