Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability for service worker to filter out frozen windows. #17554

Merged
merged 1 commit into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions service-workers/service-worker/clients-matchall-frozen.https.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<!DOCTYPE html>
<title>Service Worker: Clients.matchAll</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/test-helpers.sub.js"></script>
<script>
var scope = 'resources/clients-frame-freeze.html';
var windows = [];
var expected_window_1 =
{visibilityState: 'visible', focused: false, lifecycleState: "frozen", url: new URL(scope + '#1', location).toString(), type: 'window', frameType: 'top-level'};
var expected_window_2 =
{visibilityState: 'visible', focused: false, lifecycleState: "active", url: new URL(scope + '#2', location).toString(), type: 'window', frameType: 'top-level'};
function with_window(url, name) {
return new Promise(function(resolve) {
var child = window.open(url, name);
window.onmessage = () => {resolve(child)};
});
}

promise_test(function(t) {
return service_worker_unregister_and_register(
t, 'resources/clients-matchall-worker.js', scope)
.then(function(registration) {
t.add_cleanup(function() {
return service_worker_unregister(t, scope);
});

return wait_for_state(t, registration.installing, 'activated');
})
.then(function() { return with_window(scope + '#1', 'Child 1'); })
.then(function(window1) {
windows.push(window1);
return with_window(scope + '#2', 'Child 2');
})
.then(function(window2) {
windows.push(window2);
return new Promise(function(resolve) {
window.onmessage = resolve;
windows[0].postMessage('freeze');
});
})
.then(function() {
var channel = new MessageChannel();

return new Promise(function(resolve) {
channel.port1.onmessage = resolve;
windows[1].navigator.serviceWorker.controller.postMessage(
{port:channel.port2, includeLifecycleState: true}, [channel.port2]);
});
})
.then(function(e) {
assert_equals(e.data.length, 1);
assert_object_equals(e.data[0], expected_window_2);
})
.then(function() {
var channel = new MessageChannel();

return new Promise(function(resolve) {
channel.port1.onmessage = resolve;
windows[1].navigator.serviceWorker.controller.postMessage(
{port:channel.port2, options: {lifecycleState: "all"}, includeLifecycleState: true}, [channel.port2]);
});
})
.then(function(e) {
assert_equals(e.data.length, 2);
// No specific order is required, so support inversion.
if (e.data[0][3] == new URL(scope + '#2', location)) {
assert_object_equals(e.data[0], expected_window_2);
assert_object_equals(e.data[1], expected_window_1);
} else {
assert_object_equals(e.data[0], expected_window_1);
assert_object_equals(e.data[1], expected_window_2);
}
})
.then(function() {
var channel = new MessageChannel();

return new Promise(function(resolve) {
channel.port1.onmessage = resolve;
windows[1].navigator.serviceWorker.controller.postMessage(
{port:channel.port2, options: {lifecycleState: "frozen"}, includeLifecycleState: true}, [channel.port2]);
});
})
.then(function(e) {
assert_equals(e.data.length, 1);
assert_object_equals(e.data[0], expected_window_1);
})
.then(function() {
var channel = new MessageChannel();

return new Promise(function(resolve) {
channel.port1.onmessage = resolve;
windows[1].navigator.serviceWorker.controller.postMessage(
{port:channel.port2, options: {lifecycleState: "active"}, includeLifecycleState: true}, [channel.port2]);
});
})
.then(function(e) {
assert_equals(e.data.length, 1);
assert_object_equals(e.data[0], expected_window_2);
});
}, 'Test Clients.matchAll()');

</script>
15 changes: 15 additions & 0 deletions service-workers/service-worker/resources/clients-frame-freeze.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script>
document.addEventListener('freeze', () => {
opener.postMessage('frozen', "*");
});

window.onmessage = (e) => {
if (e.data == 'freeze') {
test_driver.freeze();
}
};
opener.postMessage('loaded', '*');
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@ self.onmessage = function(e) {
// In that case, just pretend it's top-level!
frame_type = 'top-level';
}
message.push([client.visibilityState,
client.focused,
client.url,
client.type,
frame_type]);
if (e.data.includeLifecycleState) {
message.push({visibilityState: client.visibilityState,
focused: client.focused,
url: client.url,
lifecycleState: client.lifecycleState,
type: client.type,
frameType: frame_type});
} else {
message.push([client.visibilityState,
client.focused,
client.url,
client.type,
frame_type]);
}
});
// Sort by url
if (!e.data.disableSort) {
Expand Down