blob: e23f51dfac4a64ac4897a5087781eda30f27f5f1 [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8 />
<title>Event Timing only times certain types of trusted event.
</title>
<button id='button' onclick='mainThreadBusy(100)'
onfocus='mainThreadBusy(100)'>Generate a 'click' event</button>
<script src=../../../resources/testharness.js></script>
<script src=../../../resources/testharnessreport.js></script>
<script src=./resources/event-timing-support.js></script>
<script>
let trustedClickStart = 0;
function trustedClickAndBlockMain(id) {
return new Promise((resolve, reject) => {
trustedClickStart = performance.now();
clickOnElement(id);
mainThreadBusy(100);
resolve();
});
}
function untrustedClickAndBlockMain(id) {
return new Promise((resolve, reject) => {
const target = document.getElementById(id);
target.dispatchEvent(new MouseEvent('click'));
// Block mainthread in the callback, as dispatchEvent() is an sync call.
resolve();
});
}
function trustedFocusAndBlockMain(id) {
return new Promise((resolve, reject) => {
const target = document.getElementById(id);
trustedFocusStart = performance.now();
target.focus();
// Block mainthread in the callback, as focus() is an sync call.
resolve();
});
}
async_test(function(t) {
new PerformanceObserver(entryList => {
const observerCallbackTime = performance.now();
const entries = entryList.getEntries().filter(entry => entry.name === 'mousedown');
t.step(()=>{
assert_equals(entries.length, 1,
"Observe more than one entries: " +
JSON.stringify(entries) + ".");
assert_equals(entries[0].name, 'mousedown',
"The observed entry should be a mousedown");
assert_greater_than(observerCallbackTime, entries[0].startTime,
"assert(untrustedClickStart > entries[0].startTime) failed");
assert_greater_than(entries[0].startTime, trustedClickStart,
"assert(entries[0].startTime > trustedClickStart) failed");
});
t.done();
}).observe({ entryTypes: ['event'] });
// untrusted event of a type event timing cares about
untrustedClickAndBlockMain('button').then(wait);
// trusted event of a type event timing doesn't cares about
trustedFocusAndBlockMain('button').then(wait);
// trusted event of a type event timing cares about
trustedClickAndBlockMain('button').then(wait);
}, "Event Timing only times certain types of trusted event.");
</script>
</html>