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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html

Issue 1872243002: ServiceWorker: Check the equality of JS-level SW/SWR objects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use promise_test and make synced-state.html deterministic order Created 4 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
Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html
index 63a6e5b23226e2cc655dd3473da658a965f77d2e..622b62d113c2c908a04b3d8e794aa9b52b837abf 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/synced-state.html
@@ -5,53 +5,70 @@
<script src="resources/test-helpers.js"></script>
<script>
// Tests that ServiceWorker objects representing the same Service Worker
-// entity have the same state. JS object equality is not tested, since the spec
-// does not require it.
+// entity have the same state. JS-level equality is now required according to
+// the spec.
promise_test(function(t) {
- var scope = 'resources/synced-state';
- var script = 'resources/empty-worker.js';
- return service_worker_unregister_and_register(t, script, scope)
- .then(function(registration) {
- return new Promise(function(resolve) {
- var step = 0;
- registration.installing.addEventListener('statechange',
- function(e) {
- step++;
- if (step == 1) {
- assert_equals(e.currentTarget.state, 'installed',
- 'original SW should be installed');
- assert_equals(registration.installing, null,
- 'in installed, .installing should be null');
- assert_equals(registration.waiting.state, 'installed',
- 'in installed, .waiting should be installed');
- assert_equals(registration.active, null,
- 'in installed, .active should be null');
- } else if (step == 2) {
- assert_equals(e.currentTarget.state, 'activating',
- 'original SW should be activating');
- assert_equals(registration.installing, null,
- 'in activating, .installing should be null');
- assert_equals(registration.waiting, null,
- 'in activating, .waiting should be null');
- assert_equals(
- registration.active.state, 'activating',
- 'in activating, .active should be activating');
- } else if (step == 3) {
- assert_equals(e.currentTarget.state, 'activated',
- 'original SW should be activated');
- assert_equals(registration.installing, null,
- 'in activated, .installing should be null');
- assert_equals(registration.waiting, null,
- 'in activated, .waiting should be null');
- assert_equals(registration.active.state, 'activated',
- 'in activated .active should be activated');
- resolve();
- }
- })
- })
- })
- .then(function() {
- return service_worker_unregister_and_done(t, scope);
- });
- }, 'worker objects for the same entity have the same state');
+ var scope = 'resources/synced-state';
nhiroki 2016/04/18 03:26:53 Indents would be broken. These lines need 2 more s
shimazu (google) 2016/04/18 06:39:13 Done.
+ var script = 'resources/empty-worker.js';
+ var registration;
+ return service_worker_unregister_and_register(t, script, scope)
+ .then(function(r) {
+ var step = 0;
+ registration = r;
+ add_completion_callback(function() { r.unregister(); });
+ return new Promise(function(resolve) {
+ r.installing.addEventListener('statechange', function(e) {
+ step++;
+ if (step == 1) {
+ assert_equals(e.currentTarget.state, 'installed',
+ 'original SW should be installed');
+ assert_equals(r.installing, null,
+ 'in installed, .installing should be null');
+ assert_equals(r.waiting.state, 'installed',
+ 'in installed, the state of .waiting ' +
+ 'should be installed');
+ assert_equals(r.active, null,
+ 'in installed, .active should be null');
+ assert_equals(r.waiting, e.currentTarget,
+ '.waiting should be equal to the original ' +
+ 'SW in installed');
+ } else if (step == 2) {
+ assert_equals(e.currentTarget.state, 'activating',
+ 'original SW should be activating');
+ assert_equals(r.installing, null,
+ 'in activating, .installing should be null');
+ assert_equals(r.waiting, null,
+ 'in activating, .waiting should be null');
+ assert_equals(r.active.state, 'activating',
+ 'in activating, the state of .active ' +
+ 'should be activating');
+ assert_equals(r.active, e.currentTarget,
+ '.active should be equal to the original ' +
+ 'SW in activating');
+ } else if (step == 3) {
+ assert_equals(e.currentTarget.state, 'activated',
+ 'original SW should be activated');
+ assert_equals(r.installing, null,
+ 'in activated, .installing should be null');
+ assert_equals(r.waiting, null,
+ 'in activated, .waiting should be null');
+ assert_equals(r.active.state, 'activated',
+ 'in activated, the state of .active should ' +
+ 'be activated');
+ assert_equals(r.active, e.currentTarget,
+ '.active should be equal to the original ' +
+ 'SW in activated');
+ resolve();
+ }
+ });
+ });
+ })
+ .then(function() {
+ return navigator.serviceWorker.getRegistration(scope);
+ })
+ .then(function(r) {
+ assert_equals(r, registration, 'getRegistration should return the ' +
+ 'same object with the registered one');
+ });
+}, 'worker objects for the same entity have the same state');
</script>

Powered by Google App Engine
This is Rietveld 408576698