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

Unified Diff: LayoutTests/http/tests/serviceworker/getregistrations.html

Issue 1210883002: Service Worker: Fix getRegistrations.html layout test. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. Created 5 years, 6 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/serviceworker/getregistrations.html
diff --git a/LayoutTests/http/tests/serviceworker/getregistrations.html b/LayoutTests/http/tests/serviceworker/getregistrations.html
index 028ee9c4181f785a461dab903724f159398eed7f..3f6fbaba10767f668317472669ec9226e369e8f4 100644
--- a/LayoutTests/http/tests/serviceworker/getregistrations.html
+++ b/LayoutTests/http/tests/serviceworker/getregistrations.html
@@ -10,27 +10,32 @@
// getRegistrations() is used in order to avoid adding additional complexity
// e.g. adding an internal function.
sequential_promise_test(function(t) {
- return navigator.serviceWorker.getRegistrations()
- .then(function(registrations) {
- return registrations.reduce(function(sequence, registration) {
- return sequence.then(function() {
- return registration.unregister();
- });
- }, Promise.resolve());
+ var resolve;
+ var timer;
+ var p = new Promise(function(r) { resolve = r; });
+ navigator.serviceWorker.getRegistrations()
+ .then(function(regs) {
+ return Promise.all(regs.map(function(r) { r.unregister(); }));
+ })
+ .then(function() {
+ // As registration.unregister() promises resolve before the
+ // corresponding registrations are deleted from the storage, we must
+ // wait until the registrations are actually removed from the storage.
+ // Spec reference: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#unregister-algorithm
+ timer = setInterval(function() {
+ navigator.serviceWorker.getRegistrations()
+ .then(function(regs) {
+ if (regs.length == 0) {
+ clearInterval(timer);
+ resolve();
+ }
+ });
+ }, 100);
});
+ return p;
}, 'Purge the existing registrations.');
sequential_promise_test(function(t) {
- return navigator.serviceWorker.getRegistrations()
- .then(function(value) {
- assert_array_equals(
- value,
- [],
- 'getRegistrations should resolve with an empty array.');
- });
- }, 'getRegistrations');
-
-sequential_promise_test(function(t) {
var scope = 'resources/scope/getregistrations/normal';
var script = 'resources/empty-worker.js';
var registrations = [];
@@ -93,8 +98,8 @@ sequential_promise_test(function(t) {
}, 'Register then Unregister then getRegistrations');
sequential_promise_test(function(t) {
- // Top-level window's origin is http://127.0.0.1:8000
- // Set frame's origin to http://localhost:8000
+ // Top-level window's origin: http://127.0.0.1:8000.
+ // Frame's origin: http://localhost:8000.
var host_info = get_host_info();
var frame_url = host_info['HTTP_REMOTE_ORIGIN'] +
'/serviceworker/resources/frame-for-getregistrations.html';
@@ -105,32 +110,34 @@ sequential_promise_test(function(t) {
return with_iframe(frame_url)
.then(function(f) {
- // frame registered its registration scoped
- // http://localhost:8000/serviceworker/resources/scope-for-getregistrations
frame = f;
- // Top-level window registers its registration scoped
- // http://127.0.0.1:8000/serviceworker/resources/scope-for-getregistrations
- return service_worker_unregister_and_register(t, script, scope);
- })
- .then(function(r) {
- registrations.push(r);
- return navigator.serviceWorker.getRegistrations();
- })
- .then(function(value) {
- assert_array_equals(
- value,
- registrations,
- 'getRegistrations should only return same origin registrations.');
- var channel = new MessageChannel();
var resolve;
var p = new Promise(function(r) { resolve = r; });
+ var channel = new MessageChannel();
+
channel.port1.onmessage = function(e) {
- if (e.data == 'unregistered')
+ // Frame's registration is registered.
+ if (e.data == 'registered') {
+ // Top-level window registers a registration scoped
+ // http://127.0.0.1:8000/serviceworker/resources/scope-for-getregistrations.
+ service_worker_unregister_and_register(t, script, scope)
+ .then(function(r) {
+ registrations.push(r);
+ return navigator.serviceWorker.getRegistrations();
+ })
+ .then(function(value) {
+ assert_array_equals(value, registrations,
+ 'getRegistrations should return only the same origin ' +
+ 'registrations.');
+ channel.port1.postMessage('unregister');
+ });
+ } else if (e.data == 'unregistered') {
resolve();
+ }
};
- frame.contentWindow.postMessage('unregister', '*', [channel.port2]);
+ frame.contentWindow.postMessage('register', '*', [channel.port2]);
return p;
})
.then(function() {
« no previous file with comments | « LayoutTests/TestExpectations ('k') | LayoutTests/http/tests/serviceworker/resources/frame-for-getregistrations.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698