Commit 22156329 authored by peter's avatar peter Committed by Commit bot

Fix NotificationUIManagerTest::testShowAndCloseMultipleNotifications.

Do this by making sure that we don't unregister the Service Worker for
each notification that's being shown, which actually closes the existing
ones on the platform.

BUG=472926

Review URL: https://codereview.chromium.org/1082273003

Cr-Commit-Position: refs/heads/master@{#325436}
parent c29d5c5f
...@@ -13,7 +13,6 @@ import android.test.suitebuilder.annotation.SmallTest; ...@@ -13,7 +13,6 @@ import android.test.suitebuilder.annotation.SmallTest;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.annotations.SuppressFBWarnings; import org.chromium.base.annotations.SuppressFBWarnings;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.MinAndroidSdkLevel; import org.chromium.base.test.util.MinAndroidSdkLevel;
import org.chromium.chrome.browser.preferences.website.ContentSetting; import org.chromium.chrome.browser.preferences.website.ContentSetting;
...@@ -292,12 +291,8 @@ public class NotificationUIManagerTest extends ChromeShellTestBase { ...@@ -292,12 +291,8 @@ public class NotificationUIManagerTest extends ChromeShellTestBase {
* Verifies that multiple notifications without a tag can be opened and closed without * Verifies that multiple notifications without a tag can be opened and closed without
* affecting eachother. * affecting eachother.
*/ */
/* @LargeTest
@MediumTest
@Feature({"Browser", "Notifications"}) @Feature({"Browser", "Notifications"})
crbug.com/472926
*/
@DisabledTest
public void testShowAndCloseMultipleNotifications() throws Exception { public void testShowAndCloseMultipleNotifications() throws Exception {
setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW); setNotificationContentSettingForCurrentOrigin(ContentSetting.ALLOW);
......
...@@ -2,45 +2,52 @@ ...@@ -2,45 +2,52 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
var activatedServiceWorkerPromise = null;
// Returns a promise that will be resolved with an activated Service // Returns a promise that will be resolved with an activated Service
// Worker, or rejects when the Service Worker could not be started. There // Worker, or rejects when the Service Worker could not be started. There
// will be a message port to and from the worker in |messagePort|. // will be a message port to and from the worker in |messagePort|.
function GetActivatedServiceWorker(script, scope) { function GetActivatedServiceWorker(script, scope) {
return navigator.serviceWorker.getRegistration(scope) if (activatedServiceWorkerPromise == null) {
.then(function(registration) { activatedServiceWorkerPromise =
// Unregister any existing Service Worker. navigator.serviceWorker.getRegistration(scope)
if (registration) .then(function(registration) {
return registration.unregister(); // Unregister any existing Service Worker.
}).then(function() { if (registration)
// Register the Service Worker again. return registration.unregister();
return navigator.serviceWorker.register(script, { scope: scope }); }).then(function() {
}).then(function(registration) { // Register the Service Worker again.
if (registration.active) { return navigator.serviceWorker.register(script, { scope: scope });
return registration; }).then(function(registration) {
} else if (registration.waiting || registration.installing) { if (registration.active) {
var worker = registration.waiting || registration.installing; 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) { return new Promise(function(resolve) {
worker.addEventListener('statechange', function () { var channel = new MessageChannel();
if (worker.state === 'activated') channel.port1.addEventListener('message', function(event) {
if (event.data == 'ready')
resolve(registration); 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, registration.active.postMessage(channel.port2,
[ channel.port2 ]); [ channel.port2 ]);
messagePort = channel.port1; messagePort = channel.port1;
messagePort.start(); messagePort.start();
});
}); });
}); }
return activatedServiceWorkerPromise;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment