Index: LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/update.html |
diff --git a/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/update.html b/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/update.html |
index 1600e19fd388b2c152a306e02f65d1aebbaed85c..8e8c584e5f13aeb298e28bfa3e2ae4f6bb14522c 100644 |
--- a/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/update.html |
+++ b/LayoutTests/http/tests/serviceworker/ServiceWorkerGlobalScope/update.html |
@@ -9,7 +9,16 @@ promise_test(function(t) { |
var script = 'resources/update-worker.php'; |
var scope = 'resources/scope/update'; |
var registration; |
- var frame1; |
+ var frame1, frame2; |
+ |
+ function update_resolved(test, container) { |
+ return new Promise(test.step_func(function(resolve) { |
+ container.addEventListener('message', test.step_func(function(e) { |
+ if (e.data == 'update resolved') |
+ resolve(); |
+ })); |
+ })); |
+ } |
return service_worker_unregister_and_register(t, script, scope) |
.then(function(r) { |
@@ -19,25 +28,48 @@ promise_test(function(t) { |
.then(function() { return with_iframe(scope); }) |
.then(function(f) { |
frame1 = f; |
- registration.active.postMessage('update'); |
- return wait_for_update(t, registration); |
+ var expected_events_seen = [ |
+ 'updatefound', // by register(). |
+ 'activate', |
+ 'fetch' |
+ ]; |
+ assert_equals( |
+ f.contentDocument.body.textContent, |
+ expected_events_seen.toString(), |
+ 'events seen by the worker for register()'); |
falken
2015/10/01 14:58:04
This assert looks unneeded for this test, which is
|
+ registration.active.postMessage(f.contentWindow.location.href); |
+ return update_resolved(t, f.contentWindow.navigator.serviceWorker); |
}) |
.then(function() { return with_iframe(scope); }) |
- .then(function(frame2) { |
+ .then(function(f) { |
+ frame2 = f; |
var expected_events_seen = [ |
- 'updatefound', // by register(). |
- 'activate', |
- 'fetch', |
'message', |
- 'updatefound', // by update() in the message handler. |
- 'fetch', |
+ 'new-version', // by update() in the message handler. |
+ 'updatefound', // new version was found and updatefound fired. |
+ 'fetch' |
]; |
assert_equals( |
- frame2.contentDocument.body.textContent, |
+ f.contentDocument.body.textContent, |
+ expected_events_seen.toString(), |
+ 'events seen by the worker for update() with a new version'); |
+ registration.active.postMessage(f.contentWindow.location.href); |
+ return update_resolved(t, f.contentWindow.navigator.serviceWorker); |
+ }) |
+ .then(function() { return with_iframe(scope); }) |
+ .then(function(frame3) { |
+ var expected_events_seen = [ |
+ 'message', |
+ 'cached-version', // by update() in the message handler. |
+ 'fetch' // version was served from cache so no updatefound |
+ ]; // fired. |
+ assert_equals( |
+ frame3.contentDocument.body.textContent, |
expected_events_seen.toString(), |
- 'events seen by the worker'); |
+ 'events seen by the worker for update() with a cached version'); |
frame1.remove(); |
frame2.remove(); |
+ frame3.remove(); |
return service_worker_unregister_and_done(t, scope); |
}); |
}, 'Update a registration on ServiceWorkerGlobalScope'); |