Ensure that Service Worker clients are always returned in MRU order (2)

Adds a layout test to ensure that client ordering is done properly.

Spec: https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#clients-matchall-method

1. (Chromium) https://codereview.chromium.org/1285373002/
2. (Blink) This CL.

BUG=461411

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

git-svn-id: svn://svn.chromium.org/blink/trunk@200875 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4585ea51
...@@ -26,7 +26,6 @@ var expected_with_all = [ ...@@ -26,7 +26,6 @@ var expected_with_all = [
function test_matchall(frame, expected, query_options) { function test_matchall(frame, expected, query_options) {
// Make sure the frame gets focus. // Make sure the frame gets focus.
frame.focus(); frame.focus();
expected.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; });
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var channel = new MessageChannel(); var channel = new MessageChannel();
channel.port1.onmessage = function(e) { channel.port1.onmessage = function(e) {
......
...@@ -42,6 +42,7 @@ function test_matchall(frame, expected, query_options) { ...@@ -42,6 +42,7 @@ function test_matchall(frame, expected, query_options) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var channel = new MessageChannel(); var channel = new MessageChannel();
channel.port1.onmessage = function(e) { channel.port1.onmessage = function(e) {
e.data.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; });
assert_equals(e.data.length, expected.length); assert_equals(e.data.length, expected.length);
for (var i = 0; i < e.data.length; i++) for (var i = 0; i < e.data.length; i++)
assert_array_equals(e.data[i], expected[i]); assert_array_equals(e.data[i], expected[i]);
......
...@@ -5,42 +5,58 @@ ...@@ -5,42 +5,58 @@
<script src="resources/test-helpers.js"></script> <script src="resources/test-helpers.js"></script>
<script> <script>
var scope = 'resources/blank.html?clients-matchAll'; var scope = 'resources/blank.html?clients-matchAll';
var t = async_test('Test Clients.matchAll()'); var expectedFirst = [
/* visibilityState, focused, url, frameType */
['visible', true, new URL(scope + '#1', location).toString(), 'nested'],
['visible', false, new URL(scope + '#2', location).toString(), 'nested']
];
var expectedSecond = [
/* visibilityState, focused, url, frameType */
['visible', true, new URL(scope + '#2', location).toString(), 'nested'],
['visible', false, new URL(scope + '#1', location).toString(), 'nested']
];
var frame1, frame2; var frame1, frame2;
t.step(function() { var worker;
service_worker_unregister_and_register( promise_test(function(t) {
return service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope) t, 'resources/clients-matchall-worker.js', scope)
.then(function(registration) { .then(function(registration) {
return wait_for_state(t, registration.installing, 'activated'); worker = registration.installing;
return wait_for_state(t, worker, 'activated');
}) })
.then(function() { return with_iframe(scope + '#1'); }) .then(function() { return with_iframe(scope + '#1'); })
.then(function(f) { .then(function(f) {
frame1 = f; frame1 = f;
f.focus();
return with_iframe(scope + '#2'); return with_iframe(scope + '#2');
}) })
.then(function(f) { .then(function(f) {
frame2 = f; frame2 = f;
var channel = new MessageChannel(); return new Promise(function(resolve) {
channel.port1.onmessage = t.step_func(onMessage); frame1.focus();
f.contentWindow.navigator.serviceWorker.controller.postMessage( var channel = new MessageChannel();
{port:channel.port2}, [channel.port2]); channel.port1.onmessage = resolve;
worker.postMessage({port:channel.port2}, [channel.port2]);
});
}) })
.catch(unreached_rejection(t)); .then(function(message) {
}); assert_equals(message.data.length, 2);
assert_array_equals(message.data[0], expectedFirst[0]);
var expected = [ assert_array_equals(message.data[1], expectedFirst[1]);
/* visibilityState, focused, url, frameType */ return new Promise(function(resolve) {
['visible', true, new URL(scope + '#1', location).toString(), 'nested'], frame2.focus();
['visible', false, new URL(scope + '#2', location).toString(), 'nested'] var channel = new MessageChannel();
]; channel.port1.onmessage = resolve;
worker.postMessage({port:channel.port2}, [channel.port2]);
function onMessage(e) { });
assert_equals(e.data.length, 2); })
assert_array_equals(e.data[0], expected[0]); .then(function(message) {
assert_array_equals(e.data[1], expected[1]); assert_equals(message.data.length, 2);
frame1.remove(); assert_array_equals(message.data[0], expectedSecond[0]);
frame2.remove(); assert_array_equals(message.data[1], expectedSecond[1]);
service_worker_unregister_and_done(t, scope); frame1.remove();
} frame2.remove();
return service_worker_unregister_and_done(t, scope);
})
}, 'Test Clients.matchAll()');
</script> </script>
...@@ -10,8 +10,6 @@ self.onmessage = function(e) { ...@@ -10,8 +10,6 @@ self.onmessage = function(e) {
client.url, client.url,
client.frameType]); client.frameType]);
}); });
// Sort by url
message.sort(function(a, b) { return a[2] > b[2] ? 1 : -1; });
port.postMessage(message); port.postMessage(message);
}); });
}; };
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