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

Unified Diff: LayoutTests/http/tests/notifications/resources/test-helpers.js

Issue 868053003: Expose ServiceWorkerRegistration.showNotification() in Service Workers. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
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..b9c06b2b7eb514256471068e98f21763b4779ac8 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) {
+ 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();
+ });
+ });
+}

Powered by Google App Engine
This is Rietveld 408576698