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

Unified Diff: chrome/test/data/notifications/notification_test_utils.js

Issue 1082273003: Fix NotificationUIManagerTest::testShowAndCloseMultipleNotifications. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-Integrate
Patch Set: Created 5 years, 8 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
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationUIManagerTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/notifications/notification_test_utils.js
diff --git a/chrome/test/data/notifications/notification_test_utils.js b/chrome/test/data/notifications/notification_test_utils.js
index 464238c1dd1769069483ef93abdfd58a3e3b0051..eab4881de6d5e4dff48a964b1749e71ff7904093 100644
--- a/chrome/test/data/notifications/notification_test_utils.js
+++ b/chrome/test/data/notifications/notification_test_utils.js
@@ -2,45 +2,52 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+var activatedServiceWorkerPromise = null;
+
// Returns a promise that will be resolved with an activated Service
// Worker, or rejects when the Service Worker could not be started. There
// will be a message port to and from the worker in |messagePort|.
function GetActivatedServiceWorker(script, scope) {
- return navigator.serviceWorker.getRegistration(scope)
- .then(function(registration) {
- // Unregister any existing Service Worker.
- if (registration)
- return registration.unregister();
- }).then(function() {
- // Register the Service Worker again.
- return navigator.serviceWorker.register(script, { scope: scope });
- }).then(function(registration) {
- if (registration.active) {
- return registration;
- } else if (registration.waiting || registration.installing) {
- var worker = registration.waiting || registration.installing;
+ if (activatedServiceWorkerPromise == null) {
+ activatedServiceWorkerPromise =
+ navigator.serviceWorker.getRegistration(scope)
+ .then(function(registration) {
+ // Unregister any existing Service Worker.
+ if (registration)
+ return registration.unregister();
+ }).then(function() {
+ // Register the Service Worker again.
+ return navigator.serviceWorker.register(script, { scope: scope });
+ }).then(function(registration) {
+ if (registration.active) {
+ return registration;
+ } else if (registration.waiting || registration.installing) {
+ var worker = registration.waiting || registration.installing;
+ return new Promise(function(resolve) {
+ worker.addEventListener('statechange', function () {
+ if (worker.state === 'activated')
+ resolve(registration);
+ });
+ });
+ } else {
+ return Promise.reject('Service Worker in invalid state.');
+ }
+ }).then(function(registration) {
return new Promise(function(resolve) {
- worker.addEventListener('statechange', function () {
- if (worker.state === 'activated')
+ var channel = new MessageChannel();
+ channel.port1.addEventListener('message', function(event) {
+ if (event.data == 'ready')
resolve(registration);
});
- });
- } else {
- return Promise.reject('Service Worker in invalid state.');
- }
- }).then(function(registration) {
- return new Promise(function(resolve) {
- var channel = new MessageChannel();
- channel.port1.addEventListener('message', function(event) {
- if (event.data == 'ready')
- resolve(registration);
- });
- registration.active.postMessage(channel.port2,
- [ channel.port2 ]);
+ registration.active.postMessage(channel.port2,
+ [ channel.port2 ]);
- messagePort = channel.port1;
- messagePort.start();
+ messagePort = channel.port1;
+ messagePort.start();
+ });
});
- });
+ }
+
+ return activatedServiceWorkerPromise;
}
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/notifications/NotificationUIManagerTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698