mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1464503 [wpt PR 11165] - [PageLifecycle] Add WPT test for lifecycle's onfreeze callback, a=testonly
Automatic update from web-platform-tests[PageLifecycle] Add WPT test for lifecycle's onfreeze callback Since the onfreeze callback is invoked based on an internal decision from the browser, to be able to test the callback, we are adding support for it from chromeGPUBenchmak as well as in chromedriver/WebDriver. This CL focuses on the chromeGPUBenchmark solution. The WPT test itself, verifies that the onfreeze callback is called, and it also verifies that only fetch keepalive is allowed from withing the callback. Bug: chromium:837709 Change-Id: Ia4cb16dc10625f478ec270617da1a26395a9d29d Reviewed-on: https://chromium-review.googlesource.com/1072899 Reviewed-by: Jonathon Kereliuk <kereliuk@chromium.org> Reviewed-by: Shubhie Panicker <panicker@chromium.org> Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Fadi Meawad <fmeawad@chromium.org> Cr-Commit-Position: refs/heads/master@{#563338} -- wpt-commits: 3d6920b84bac82c45a8da5c8b04b6da0c64f02fd wpt-pr: 11165
This commit is contained in:
parent
edd862fe03
commit
8f3b4d6b16
@ -287640,6 +287640,16 @@
|
||||
{}
|
||||
]
|
||||
],
|
||||
"lifecycle/resources/foo.txt": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"lifecycle/resources/window.html": [
|
||||
[
|
||||
{}
|
||||
]
|
||||
],
|
||||
"longtask-timing/OWNERS": [
|
||||
[
|
||||
{}
|
||||
@ -349799,6 +349809,12 @@
|
||||
{}
|
||||
]
|
||||
],
|
||||
"lifecycle/freeze.html": [
|
||||
[
|
||||
"/lifecycle/freeze.html",
|
||||
{}
|
||||
]
|
||||
],
|
||||
"longtask-timing/longtask-attributes.html": [
|
||||
[
|
||||
"/longtask-timing/longtask-attributes.html",
|
||||
@ -587410,6 +587426,18 @@
|
||||
"28b559875ce9514702d181cb4cb5e0a207083e2d",
|
||||
"testharness"
|
||||
],
|
||||
"lifecycle/freeze.html": [
|
||||
"aca6ab2b23924ff891dc2abc26eb3067ad099e5b",
|
||||
"testharness"
|
||||
],
|
||||
"lifecycle/resources/foo.txt": [
|
||||
"b909d6288b51d2b2dfe06382f057a5892826949b",
|
||||
"support"
|
||||
],
|
||||
"lifecycle/resources/window.html": [
|
||||
"3c839ba3697d5ce8bcda99824af7dea7b37534c1",
|
||||
"support"
|
||||
],
|
||||
"longtask-timing/OWNERS": [
|
||||
"30a9c29ba53bac131c0cca801c01dddb4779824e",
|
||||
"support"
|
||||
|
48
testing/web-platform/tests/lifecycle/freeze.html
Normal file
48
testing/web-platform/tests/lifecycle/freeze.html
Normal file
@ -0,0 +1,48 @@
|
||||
<!DOCTYPE html>
|
||||
<meta charset="utf-8">
|
||||
<title>TestDriver freeze method</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
<script>
|
||||
var test = async_test('Test freeze callback.');
|
||||
var childWindow = window.open('resources/window.html', 'Child Window');
|
||||
var total_steps = 0;
|
||||
|
||||
const StepStatus = {
|
||||
ADDED: 0,
|
||||
SUCCESS: 1,
|
||||
FAIL: 2,
|
||||
};
|
||||
|
||||
var steps_map = new Map();
|
||||
|
||||
function add_step(name) {
|
||||
steps_map[name] = StepStatus.ADDED;
|
||||
total_steps++;
|
||||
}
|
||||
|
||||
function step_success(name) {
|
||||
total_steps--;
|
||||
steps_map[name] = StepStatus.SUCCESS;
|
||||
if (total_steps == 0)
|
||||
test.done();
|
||||
}
|
||||
|
||||
function step_fail(name) {
|
||||
total_steps--;
|
||||
steps_map[name] = StepStatus.FAIL;
|
||||
test.step(() => assert_unreached('During onfreeze: ' + name + ' failed to behave as expected.'));
|
||||
if (total_steps == 0)
|
||||
test.done();
|
||||
}
|
||||
|
||||
test.step_timeout(() => {
|
||||
for (var step in steps_map) {
|
||||
if(steps_map[step] == StepStatus.ADDED)
|
||||
test.step(() => assert_unreached('During onfreeze: ' + step + ' never finshed.'));
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
</script>
|
||||
|
1
testing/web-platform/tests/lifecycle/resources/foo.txt
Normal file
1
testing/web-platform/tests/lifecycle/resources/foo.txt
Normal file
@ -0,0 +1 @@
|
||||
Sample test file for fetch inside onfreeze.
|
66
testing/web-platform/tests/lifecycle/resources/window.html
Normal file
66
testing/web-platform/tests/lifecycle/resources/window.html
Normal file
@ -0,0 +1,66 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head><title>Frozen Window</title></head>
|
||||
<script src="/resources/testdriver.js"></script>
|
||||
<script src="/resources/testdriver-vendor.js"></script>
|
||||
<body>
|
||||
<h1>This window will be frozen</h1>
|
||||
<script>
|
||||
|
||||
const freezingStepName = 'testOnFreeze';
|
||||
|
||||
function testFetch(keepalive) {
|
||||
var name = 'testfetch' + (keepalive ? 'with' : 'without') + 'keepalive';
|
||||
window.opener.add_step(name);
|
||||
|
||||
function handler(expected) {
|
||||
if (expected == true)
|
||||
window.opener.step_success(name);
|
||||
else
|
||||
window.opener.step_fail(name);
|
||||
}
|
||||
|
||||
fetch('foo.txt', {
|
||||
keepalive: keepalive
|
||||
}).then(() => handler(keepalive)).catch(() => handler(!keepalive));
|
||||
}
|
||||
|
||||
function testXHR(async) {
|
||||
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', 'foo.txt', async);
|
||||
try {
|
||||
xhr.send(null);
|
||||
} catch {
|
||||
window.opener.step_success(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 */);
|
||||
window.opener.step_success(freezingStepName);
|
||||
});
|
||||
|
||||
onload = function() {
|
||||
window.opener.focus();
|
||||
window.opener.add_step(freezingStepName);
|
||||
test_driver.freeze();
|
||||
};
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -119,6 +119,21 @@
|
||||
}
|
||||
|
||||
return window.test_driver_internal.send_keys(element, keys);
|
||||
},
|
||||
|
||||
/**
|
||||
* Freeze the current page
|
||||
*
|
||||
* The freeze function transitions the page from the HIDDEN state to
|
||||
* the FROZEN state as described in {@link
|
||||
* https://github.com/WICG/page-lifecycle/blob/master/README.md|Lifecycle API
|
||||
* for Web Pages}
|
||||
*
|
||||
* @returns {Promise} fullfilled after the freeze request is sent, or rejected
|
||||
* in case the WebDriver command errors
|
||||
*/
|
||||
freeze: function() {
|
||||
return window.test_driver_internal.freeze();
|
||||
}
|
||||
};
|
||||
|
||||
@ -143,6 +158,16 @@
|
||||
*/
|
||||
send_keys: function(element, keys) {
|
||||
return Promise.reject(new Error("unimplemented"));
|
||||
},
|
||||
|
||||
/**
|
||||
* Freeze the current page
|
||||
*
|
||||
* @returns {Promise} fullfilled after freeze request is sent, otherwise
|
||||
* it gets rejected
|
||||
*/
|
||||
freeze: function() {
|
||||
return Promise.reject(new Error("unimplemented"));
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user