diff options
Diffstat (limited to 'testing/web-platform/tests/lifecycle/resources')
7 files changed, 169 insertions, 0 deletions
diff --git a/testing/web-platform/tests/lifecycle/resources/beacon.py b/testing/web-platform/tests/lifecycle/resources/beacon.py new file mode 100644 index 0000000000..09915ffbcf --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/beacon.py @@ -0,0 +1,25 @@ +def main(request, response): + + # |token| should be a unique UUID request parameter for the duration of this + # request. It will get stored in the server stash and will be used later in + # a query request. + # |query| should be a request parameter indicating the request would like + # to know how many times the server has seen the request (with the + # same token). + token = request.GET.first(b"token", None) + is_query = request.GET.first(b"query", None) is not None + with request.server.stash.lock: + value = request.server.stash.take(token) + count = 0 + if value is not None: + count = int(value) + if is_query: + request.server.stash.put(token, count) + else: + count += 1 + request.server.stash.put(token, count) + + headers = [] + if is_query: + headers = [(b"Count", count)] + return (200, headers, b"") diff --git a/testing/web-platform/tests/lifecycle/resources/child.html b/testing/web-platform/tests/lifecycle/resources/child.html new file mode 100644 index 0000000000..708bbfe02d --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/child.html @@ -0,0 +1,15 @@ +<!doctype html> +<html> +<head><title>Frozen Child iframe</title></head> +<body> +<script> + +// This child removes itself from the parent on dispatch of the freeze event. +// Regression test of https://crbug.com/994442 +window.document.addEventListener("freeze", () => { + window.frameElement.remove(); +}); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/lifecycle/resources/subframe.html b/testing/web-platform/tests/lifecycle/resources/subframe.html new file mode 100644 index 0000000000..2f1d70a80a --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/subframe.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script> +window.addEventListener('load', () => { + window.parent.postMessage('load'); +}); + +document.addEventListener('freeze', () => { + window.parent.postMessage('freeze'); +}); + +document.addEventListener('resume', () => { + window.parent.postMessage('resume'); +}); + +</script> diff --git a/testing/web-platform/tests/lifecycle/resources/subframe_worker.html b/testing/web-platform/tests/lifecycle/resources/subframe_worker.html new file mode 100644 index 0000000000..350d27437a --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/subframe_worker.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<script> +window.addEventListener('load', () => { + window.parent.postMessage('load'); +}); + +document.addEventListener('freeze', () => { + window.parent.postMessage('freeze'); +}); + +document.addEventListener('resume', () => { + window.parent.postMessage('resume'); +}); + +worker = new Worker("subframe_worker1.js"); +</script> diff --git a/testing/web-platform/tests/lifecycle/resources/subframe_worker1.js b/testing/web-platform/tests/lifecycle/resources/subframe_worker1.js new file mode 100644 index 0000000000..2d13e89065 --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/subframe_worker1.js @@ -0,0 +1,7 @@ +var bc = new BroadcastChannel('subworker_channel'); + +setInterval(() => { + bc.postMessage('subworker'); +}, 10); + +w2 = new Worker("subframe_worker2.js"); diff --git a/testing/web-platform/tests/lifecycle/resources/subframe_worker2.js b/testing/web-platform/tests/lifecycle/resources/subframe_worker2.js new file mode 100644 index 0000000000..32d2741331 --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/subframe_worker2.js @@ -0,0 +1,5 @@ +var bc = new BroadcastChannel('subworker_channel'); + +setInterval(() => { + bc.postMessage('subworker2'); +}, 10); diff --git a/testing/web-platform/tests/lifecycle/resources/window.html b/testing/web-platform/tests/lifecycle/resources/window.html new file mode 100644 index 0000000000..58181f32da --- /dev/null +++ b/testing/web-platform/tests/lifecycle/resources/window.html @@ -0,0 +1,84 @@ +<!doctype html> +<html> +<head><title>Frozen Window</title></head> +<script src="/resources/testdriver.js"></script> +<script src="/resources/testdriver-vendor.js"></script> +<script src="/common/utils.js"></script> +<body> +<h1>This window will be frozen</h1> +<iframe id="child_frame" src="child.html"></iframe> +<script> + +const freezingStepName = 'testOnFreeze'; + +function testFetch(keepalive) { + var request_token = token(); + var name = 'testfetch' + (keepalive ? 'with' : 'without') + 'keepalive'; + window.opener.add_step(name); + + function handler() { + window.opener.step_fail(name); + } + + fetch('beacon.py?token=' + request_token, { + keepalive: keepalive + }).then(() => handler()).catch(() => handler()); + + window.opener.poll_for_result(request_token, name, keepalive); +} + +function testXHR(async) { + var request_token = token(); + var name = 'test' + (async ? 'Async' : 'Sync') + 'XHR'; + window.opener.add_step(name); + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = () => { + if (xhr.readyState === 4) { + if (xhr.status === 0) + window.opener.step_success(name); + else + window.opener.step_fail(name); + } + } + xhr.open('GET', 'beacon.py?token=' + request_token, async); + try { + xhr.send(null); + if (async) { + window.opener.poll_for_result(request_token, name, false); + } + } catch { + window.opener.step_success(name); + }; +} + +function testSendBeacon() { + var request_token = token(); + var name = 'testSendBeacon'; + window.opener.add_step(name); + if (navigator.sendBeacon("beacon.py?token=" + request_token, "")) { + window.opener.poll_for_result(request_token, name, true); + } else { + window.opener.step_fail(name); + } +} + +window.document.addEventListener("freeze", () => { + // Testing fetch, only fetch keepalive should succeed. + testFetch(true /* keepalive */); + testFetch(false /* keepalive */); + // Testing XHR, both sync and async should fail. + testXHR(true /* async */); + testXHR(false /* sync */); + // Testing navigator.sendBeacon, which should be allowed. + testSendBeacon(); + window.opener.step_success(freezingStepName); +}); + +onload = function() { + window.opener.add_step(freezingStepName); + test_driver.freeze(); +}; + +</script> +</body> +</html> |