Source code

Revision control

Copy as Markdown

Other Tools

<!DOCTYPE HTML>
<meta charset=utf-8>
<title>Long Animation Frame Timing: first UI Event</title>
<meta name="timeout" content="long">
<script src=/resources/testdriver.js></script>
<script src=/resources/testdriver-actions.js></script>
<script src=/resources/testdriver-vendor.js></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/utils.js"></script>
<body>
<h1>Long Animation Frame: First UI Event</h1>
<div id="log"></div>
<script>
promise_test(async t => {
const button = document.createElement("button");
button.innerText = "Click";
document.body.appendChild(button);
t.add_cleanup(() => button.remove());
let busy_wait = null;
let event_ts = 0;
const entryPromise = expect_long_frame_with_script((t, busy_wait) => {
button.addEventListener("click", event => {
busy_wait();
event_ts = event.timeStamp;
});
test_driver.click(button);
}, s => s.invoker === "BUTTON.onclick", t);
await new Promise(resolve => t.step_timeout(resolve, 0));
const [entry] = await entryPromise;
assert_equals(entry.firstUIEventTimestamp, event_ts);
}, "LoAF should expose firstUIEventTimestamp for click events");
promise_test(async t => {
const button = document.createElement("button");
button.innerText = "Hover";
document.body.appendChild(button);
t.add_cleanup(() => button.remove());
let expectedTimestamp = null;
const entryPromise = expect_long_frame_with_script(async (t, busy_wait) => {
const eventPromise = new Promise(resolve => button.addEventListener("pointermove", event => {
busy_wait();
expectedTimestamp = event.timeStamp;
resolve();
}));
const actions = new test_driver.Actions()
.pointerMove(0, 0, {origin: button})
.pointerDown()
.pointerUp();
await actions.send();
await eventPromise;
}, (script, entry) =>
script.invoker === "BUTTON.onpointermove" &&
entry.firstUIEventTimestamp === expectedTimestamp, t);
}, "LoAF should expose firstUIEventTimestamp for pointermove events");
promise_test(async t => {
const button = document.createElement("button");
button.innerText = "Click";
document.body.appendChild(button);
t.add_cleanup(() => button.remove());
let firstUIEventTimestamp = null;
let busy_wait = null;
const eventPromise = new Promise(resolve => button.addEventListener("click", event => {
if (firstUIEventTimestamp)
resolve(event);
else {
firstUIEventTimestamp = event.timeStamp;
busy_wait();
}
}));
const entryPromise = expect_long_frame_with_script(async (t, busy_wait_func) => {
busy_wait = busy_wait_func;
await test_driver.click(button);
}, s => s.invoker === "BUTTON.onclick", t);
const [event, [entry]] = await Promise.all([eventPromise, entryPromise]);
assert_equals(entry.firstUIEventTimestamp, firstUIEventTimestamp);
}, "firstUIEventTimestamp doesn't have to come from a long script");
promise_test(async t => {
const input = document.createElement("input");
document.body.appendChild(input);
t.add_cleanup(() => input.remove());
input.focus();
let event_ts = 0;
const [entry] = await expect_long_frame_with_script(async (t, busy_wait) => {
const keyPromise = new Promise(resolve => input.addEventListener("keydown", event => {
event_ts = event.timeStamp;
busy_wait();
resolve();
}, {once: true}));
await test_driver.send_keys(input, "a");
await keyPromise;
}, s => s.invoker === "INPUT.onkeydown", t);
assert_equals(entry.firstUIEventTimestamp, event_ts);
}, "LoAF should expose firstUIEventTimestamp for keydown events");
promise_test(async t => {
const [entry] = await expect_long_frame_with_script((t, busy_wait) => {
const channel = new MessageChannel();
channel.port1.onmessage = () => {
busy_wait();
};
channel.port2.postMessage("go");
}, s => s.invoker === "MessagePort.onmessage", t);
assert_true(!!entry, "Entry detected");
assert_equals(entry.firstUIEventTimestamp, 0,
"Non-UIEvent should leave firstUIEventTimestamp at 0");
}, "Non-UIEvent events do not set firstUIEventTimestamp");
</script>
</body>