Skip to content

Commit

Permalink
[EventTiming] Report events without event handlers
Browse files Browse the repository at this point in the history
This CL allows reporting events without event handlers. In particular,
this implies that slow clicks cause slow mousedown events, so the tests
are modified accordingly.

Bug: 823744
Change-Id: I9578519ae538496404bb220001d3ca97565b7bd7
  • Loading branch information
npm1 authored and chromium-wpt-export-bot committed Dec 7, 2018
1 parent 6a51887 commit 4b1e031
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 28 deletions.
7 changes: 4 additions & 3 deletions event-timing/event-timing-bufferbeforeonload.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<meta charset=utf-8 />
<title>Event Timing: buffer long-latency events before onload</title>
<button id='button' onclick='clickDelay()'>Generate a 'click' event</button>
<button id='button' onmousedown='clickDelay()'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand All @@ -27,7 +27,7 @@
}

function validateEntries() {
const entries = performance.getEntriesByName('click', 'event');
const entries = performance.getEntriesByName('mousedown', 'event');

const entriesBeforeOnload = entries.filter(
e => e.startTime < onloadStart);
Expand Down Expand Up @@ -69,7 +69,8 @@
const observerPromise = new Promise((resolve, reject) => {
let entryCount = 0;
new PerformanceObserver(entryList => {
entryCount += entryList.getEntries().length;
entryCount += entryList.getEntries().filter(
entry => entry.name === 'mousedown').length;
if (entryCount >= 2)
resolve();
}).observe({ entryTypes: ['event'] });
Expand Down
4 changes: 2 additions & 2 deletions event-timing/event-timing-crossiframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</head>

<body>
<button id='button' onclick='1'>Generate a 'click' event</button>
<button id='button'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand All @@ -22,7 +22,7 @@
let onloadStart;

function validateEntries() {
const entries = performance.getEntriesByName('click', 'event');
const entries = performance.getEntriesByName('mousedown', 'event');

assert_equals(entries.length, 1,
"Observer of main frames should only capture main-frame event-timing entries."
Expand Down
7 changes: 4 additions & 3 deletions event-timing/event-timing-observethenonload.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta charset=utf-8 />
<title>Event Timing: Performance observers can observe long-latency events
</title>
<button id='button' onclick='1'>Generate a 'click' event</button>
<button id='button'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand Down Expand Up @@ -77,7 +77,8 @@
async_test(function(t) {
const observerPromise = new Promise((resolve, reject) => {
new PerformanceObserver(function(entryList) {
observedEntries = observedEntries.concat(entryList.getEntries());
observedEntries = observedEntries.concat(entryList.getEntries().filter(
entry => entry.name === 'mousedown'));
if (observedEntries.length < 2) return;
resolve(observedEntries);
}).observe({ entryTypes: ['event'] });
Expand All @@ -93,7 +94,7 @@
Promise.all([observerPromise, bufferPromise]).then((results) => {
timeAfterSecondClick = performance.now();
t.step(verifyObserverEntries.bind(null, results[0]));
t.step(verifyBuffer.bind(null, performance.getEntriesByName('click', 'event')));
t.step(verifyBuffer.bind(null, performance.getEntriesByName('mousedown', 'event')));
t.done();
});
});
Expand Down
5 changes: 3 additions & 2 deletions event-timing/event-timing-onloadthenobserve-firstInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<meta charset=utf-8 />
<title>Event Timing: buffer long-latency events before onload</title>
<button id='button' onclick='1'>Generate a 'click' event</button>
<button id='button'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand All @@ -23,7 +23,8 @@
let numFirstInputObserved = 0;
let numEventsObserved = 0;
new PerformanceObserver(t.step_func((entryList, obs) => {
const observedEntries = entryList.getEntries();
const observedEntries = entryList.getEntries().filter(
entry => entry.name === 'mousedown');
numEventsObserved += observedEntries.filter(entry =>
entry.entryType == 'event').length;
numFirstInputObserved += observedEntries.filter(entry =>
Expand Down
7 changes: 4 additions & 3 deletions event-timing/event-timing-onloadthenobserve.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>Event Timing: long-latency events after onload and before observer
registration are lost
</title>
<button id='button' onclick='1'>Generate a 'click' event</button>
<button id='button'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand All @@ -18,7 +18,7 @@

function verifyBufferAndObserverEntries(observedEntries) {
// Verify buffer entries
const bufferedEntries = performance.getEntriesByName('click', 'event');
const bufferedEntries = performance.getEntriesByName('mousedown', 'event');
const bufferedEntriesBeforeObserver = bufferedEntries.filter(e => e.startTime <
observerStart);
assert_equals(bufferedEntries.length, 0,
Expand All @@ -42,7 +42,8 @@
function startObserver(t) {
new PerformanceObserver(t.step_func_done((entryList, obs) => {
callbackTime = performance.now();
const observedEntries = entryList.getEntries();
const observedEntries = entryList.getEntries().filter(
entry => entry.name === 'mousedown');
verifyBufferAndObserverEntries(observedEntries);
})).observe({ entryTypes: ['event'] });
observerStart = performance.now();
Expand Down
7 changes: 4 additions & 3 deletions event-timing/event-timing-only-observe-firstInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<meta charset=utf-8 />
<title>Event Timing: only observe the first input</title>
<button id='button' onclick='1'>Generate a 'click' event</button>
<button id='button'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand All @@ -24,10 +24,11 @@
new PerformanceObserver(t.step_func((entryList) => {
assert_false(hasObservedFirstInput);
hasObservedFirstInput = true;
const observedEntries = entryList.getEntries();
const observedEntries = entryList.getEntries().filter(
entry => entry.name === 'mousedown');
assert_equals(observedEntries.length, 1);
assert_equals(observedEntries[0].entryType, 'firstInput');
assert_equals(observedEntries[0].name, 'click');
assert_equals(observedEntries[0].name, 'mousedown');
})).observe({ entryTypes: ['firstInput'] });
on_event(window, 'load', () => {
clickAndBlockMain('button').then(() => {
Expand Down
4 changes: 2 additions & 2 deletions event-timing/event-timing-retrievability.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<meta charset=utf-8>
<title>Event Timing: make sure event-timing entries are retrievable by existing perf APIs.</title>
<button id='button' onclick='1'>Generate a 'click' event</button>
<button id='button'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script src=/resources/testdriver.js></script>
Expand All @@ -13,7 +13,7 @@

<script>
function validateEntries() {
const entriesByName = performance.getEntriesByName('click', 'event');
const entriesByName = performance.getEntriesByName('mousedown', 'event');
const entriesByType = performance.getEntriesByType('event');
const allEntries = performance.getEntries();
assert_equals(entriesByName.length, 1, 'event-timing entry should be retrievable by getEntriesByName');
Expand Down
2 changes: 1 addition & 1 deletion event-timing/event-timing-retrieve-firstInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
assert_equals(performance.getEntriesByType('firstInput').length, 1,
"There should be a firstInput entry in the performance timeline");
const entry = performance.getEntriesByType('firstInput')[0];
assert_equals(entry.name, 'click');
assert_equals(entry.name, 'mousedown');
assert_equals(entry.entryType, 'firstInput');
assert_greater_than(entry.duration, 50,
"The first input was a long one.");
Expand Down
9 changes: 5 additions & 4 deletions event-timing/event-timing-timingconditions.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<meta charset=utf-8 />
<title>Event Timing only times certain types of trusted event.
</title>
<button id='button' onclick='mainThreadBusy(60)'
<button id='button' onmousedown='mainThreadBusy(60)'
onfocus='mainThreadBusy(60)'>Generate a 'click' event</button>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
Expand All @@ -23,7 +23,7 @@
function untrustedClickAndBlockMain(id) {
const target = document.getElementById(id);
// Block mainthread in the callback, as dispatchEvent() is a sync call.
target.dispatchEvent(new MouseEvent('click'));
target.dispatchEvent(new MouseEvent('mousedown'));
}

function trustedFocusAndBlockMain(id) {
Expand All @@ -36,11 +36,12 @@
async_test(function(t) {
new PerformanceObserver(t.step_func_done(entryList => {
const observerCallbackTime = performance.now();
const entries = entryList.getEntries();
const entries = entryList.getEntries().filter(
entry => entry.name === 'mousedown');
assert_equals(entries.length, 1,
"Should only observe one entry: " +
JSON.stringify(entries) + ".");
assert_equals(entries[0].name, 'click',
assert_equals(entries[0].name, 'mousedown',
"The observed entry should be a click");
assert_less_than(entries[0].startTime, observerCallbackTime,
"The startTime should be before observerCallbackTime");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<!DOCType html>
<html>
<script src=event-timing-support.js></script>
<button id='button_child_frame' onclick='2'>Generate a 'click' event</button>
<button id='button_child_frame'>Generate a 'click' event</button>
<img src=slow-image.py>
<script>
const clickTimeMin = performance.now();
clickAndBlockMain('button_child_frame');
const processingStartMin = performance.now();
const observerPromise = new Promise((resolve, reject) => {
new PerformanceObserver((entryList) => {
resolve(entryList.getEntries());
resolve(entryList.getEntries().filter(entry => entry.name === 'mousedown'));
}).observe({ entryTypes: ['event'] });
});
window.addEventListener('load', e => {
Expand Down
6 changes: 3 additions & 3 deletions event-timing/resources/event-timing-support.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ function clickOnElement(id, callback) {
mainThreadBusy(60);
if (callback)
callback();
element.removeEventListener("click", clickHandler);
element.removeEventListener("mousedown", clickHandler);
};
element.addEventListener("click", clickHandler);
element.addEventListener("mousedown", clickHandler);
test_driver.click(element);
}

Expand All @@ -27,7 +27,7 @@ function mainThreadBusy(duration) {
// the timings of the 'firstInput' entry should be equal to those of this entry.
function verifyClickEvent(entry, is_first=false) {
assert_true(entry.cancelable);
assert_equals(entry.name, 'click');
assert_equals(entry.name, 'mousedown');
assert_equals(entry.entryType, 'event');
assert_greater_than(entry.duration, 50,
"The entry's duration should be greater than 50ms.");
Expand Down

0 comments on commit 4b1e031

Please sign in to comment.