Commit edcbe126 authored by nhiroki@chromium.org's avatar nhiroki@chromium.org

ServiceWorker: Make APIs that return ServiceWorkerRegistration coin a new JS object (3/3)

This CL re-enables tests and updates their expectations.

(1) Blink: https://codereview.chromium.org/1311113002/
(2) Chromium: https://codereview.chromium.org/1307133003/
(3) Blink: THIS PATCH

BUG=523904

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201113 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 9efd0375
......@@ -1642,9 +1642,3 @@ crbug.com/502927 [ XP ] paint/frames/frameset-with-stacking-contexts.html [ Fail
crbug.com/353746 virtual/android/fullscreen/video-specified-size.html [ ImageOnlyFailure Pass ]
crbug.com/523500 http/tests/inspector-protocol/request-mixed-content-status.html [ Failure Pass ]
# Temporary disabled for landing chromium-side patch.
crbug.com/523904 http/tests/serviceworker/getregistration.html [ Skip ]
crbug.com/523904 http/tests/serviceworker/getregistrations.html [ Skip ]
crbug.com/523904 http/tests/serviceworker/multiple-register.html [ Skip ]
crbug.com/523904 http/tests/serviceworker/unregister-then-register.html [ Skip ]
......@@ -24,8 +24,10 @@ async_test(function(t) {
return navigator.serviceWorker.getRegistration(scope);
})
.then(function(value) {
assert_equals(value, registration,
'getRegistration should resolve with registration');
assert_registration_equals(value, registration);
assert_not_equals(
value, registration,
'getRegistration should resolve to a new registration object');
service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
......@@ -42,8 +44,7 @@ async_test(function(t) {
return navigator.serviceWorker.getRegistration(documentURL);
})
.then(function(value) {
assert_equals(value, registration,
'getRegistration should resolve with registration');
assert_registration_equals(value, registration);
service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
......
......@@ -45,7 +45,7 @@ promise_test(function(t) {
return navigator.serviceWorker.getRegistrations();
})
.then(function(value) {
assert_array_equals(
assert_registration_array_equals(
value,
registrations,
'getRegistrations should resolve with array of registrations.');
......@@ -68,7 +68,7 @@ promise_test(function(t) {
return navigator.serviceWorker.getRegistrations();
})
.then(function(value) {
assert_array_equals(
assert_registration_array_equals(
value,
registrations,
'getRegistrations should resolve with array of registrations.');
......@@ -128,7 +128,7 @@ promise_test(function(t) {
return navigator.serviceWorker.getRegistrations();
})
.then(function(value) {
assert_array_equals(value, registrations,
assert_registration_array_equals(value, registrations,
'getRegistrations should return only the same origin ' +
'registrations.');
channel.port1.postMessage('unregister');
......
......@@ -18,8 +18,10 @@ async_test(function(t) {
return navigator.serviceWorker.register(worker_url, { scope: scope });
})
.then(function(new_registration) {
assert_equals(new_registration, registration,
'register should resolve to the same registration');
assert_registration_equals(new_registration, registration);
assert_not_equals(
new_registration, registration,
'register should resolve to a new registration object');
assert_equals(new_registration.active, registration.active,
'register should resolve to the same worker');
assert_equals(new_registration.active.state, 'activated',
......@@ -28,7 +30,8 @@ async_test(function(t) {
})
.then(function() { t.done(); })
.catch(unreached_rejection(t));
}, 'Subsequent registrations resolve to the same registration object');
}, 'Subsequent registrations resolve to a different registration object ' +
'but they refer to the same registration and workers');
async_test(function(t) {
var scope = 'resources/scope/subsequent-register-from-different-iframe';
......@@ -49,7 +52,7 @@ async_test(function(t) {
.then(function(new_registration) {
assert_not_equals(
registration, new_registration,
'register should resolve to the different registration');
'register should resolve to a different registration');
assert_equals(
registration.scope, new_registration.scope,
'registrations should have the same scope');
......@@ -69,7 +72,7 @@ async_test(function(t) {
assert_not_equals(
registration.active, new_registration.active,
'registration should have the different active worker');
'registration should have a different active worker');
assert_equals(
registration.active.scriptURL,
new_registration.active.scriptURL,
......@@ -90,25 +93,31 @@ async_test(function(t) {
async_test(function(t) {
var scope = 'resources/scope/concurrent-register';
var number_of_registrations = 10;
service_worker_unregister(t, scope)
.then(function() {
var promises = [];
for (var i = 0; i < 10; ++i) {
for (var i = 0; i < number_of_registrations; ++i) {
promises.push(navigator.serviceWorker.register(worker_url,
{ scope: scope }));
}
return Promise.all(promises);
})
.then(function(registrations) {
for (var i = 1; i < number_of_registrations; ++i) {
assert_registration_equals(registrations[i], registrations[0]);
assert_not_equals(
registrations[i], registrations[0],
'register should resolve to a new registration object');
}
registrations.forEach(function(registration) {
assert_equals(registration, registrations[0],
'register should resolve to the same registration');
});
return registrations[0].unregister();
})
.then(function() { t.done(); })
.catch(unreached_rejection(t));
}, 'Concurrent registrations resolve to the same registration object');
}, 'Concurrent registrations resolve to a different registration object ' +
'but they refer to the same registration and workers');
</script>
......@@ -205,3 +205,26 @@ function login_https(test) {
'username2s', 'password2s', 'cookie2');
});
}
// Helper for testing with ServiceWorkerRegistration objects. Compares simple
// attributes defined on the interfaces.
function assert_registration_equals(actual, expected, description) {
assert_class_string(actual, 'ServiceWorkerRegistration', description);
['scope', 'installing', 'waiting', 'active'].forEach(function(attribute) {
assert_equals(actual[attribute], expected[attribute],
description + ' Attributes differ: ' + attribute + '.');
});
}
// Asserts that two arrays |actual| and |expected| contain the same set of
// ServiceWorkerRegistration as determined by assert_registration_equals(). The
// corresponding elements must occupy corresponding indices in their respective
// arrays.
function assert_registration_array_equals(actual, expected, description) {
assert_true(Array.isArray(actual), description);
assert_equals(actual.length, expected.length, description);
actual.forEach(function(value, index) {
assert_registration_equals(value, expected[index],
description + ' : object[' + index + ']');
});
}
......@@ -48,8 +48,9 @@ async_test(function(t) {
return navigator.serviceWorker.register(worker_url, { scope: scope });
})
.then(function(new_registration) {
assert_equals(registration, new_registration,
'register should resolve to the same value');
assert_registration_equals(
registration, new_registration,
'register should resolve to the same registration');
service_worker_unregister_and_done(t, scope);
})
.catch(unreached_rejection(t));
......
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