Commit 389b67ae authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by Commit Bot

[EventTiming] Use polling in performance.eventCounts test

It looks like actions.send() does not wait for the events to get
processed in order to resolve the promise, which means eventCounts may
not be populated by the time we begin testing it. Hence, in this CL we
perform a polling-based approach. Sample failure:
https://isolateserver.appspot.com/browse?namespace=default-gzip&digest=8e7df6aa16ccbffabef2b11c5f2d9aaa02d396c1&as=layout-test-results%5Cexternal%5Cwpt%5Cevent-timing%5Cmouseover-actual.txt

Bug: 1074048
Change-Id: I58629d66ad146fd435fc95fb875f21a96f5470a2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212497Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771778}
parent af66e562
...@@ -182,6 +182,26 @@ function notCancelable(eventType) { ...@@ -182,6 +182,26 @@ function notCancelable(eventType) {
return ['mouseenter', 'mouseleave', 'pointerenter', 'pointerleave'].includes(eventType); return ['mouseenter', 'mouseleave', 'pointerenter', 'pointerleave'].includes(eventType);
} }
// Tests the given |eventType|'s performance.eventCounts value. Since this is populated only when
// the event is processed, we check every 10 ms until we've found the |expectedCount|.
function testCounts(t, resolve, looseCount, eventType, expectedCount) {
const counts = performance.eventCounts.get(eventType);
if (counts < expectedCount) {
t.step_timeout(() => {
testCounts(t, resolve, looseCount, eventType, expectedCount);
}, 10);
return;
}
if (looseCount) {
assert_greater_than_equal(performance.eventCounts.get(eventType), expectedCount,
`Should have at least ${expectedCount} ${eventType} events`)
} else {
assert_equals(performance.eventCounts.get(eventType), expectedCount,
`Should have ${expectedCount} ${eventType} events`);
}
resolve();
}
// Tests the given |eventType| by creating events whose target are the element with id // Tests the given |eventType| by creating events whose target are the element with id
// 'target'. The test assumes that such element already exists. |looseCount| is set for // 'target'. The test assumes that such element already exists. |looseCount| is set for
// eventTypes for which events would occur for other elements besides the target, so the // eventTypes for which events would occur for other elements besides the target, so the
...@@ -197,13 +217,9 @@ async function testEventType(t, eventType, looseCount=false) { ...@@ -197,13 +217,9 @@ async function testEventType(t, eventType, looseCount=false) {
// Trigger two 'fast' events of the type. // Trigger two 'fast' events of the type.
await applyAction(eventType, target); await applyAction(eventType, target);
await applyAction(eventType, target); await applyAction(eventType, target);
if (looseCount) { await new Promise(t.step_func(resolve => {
assert_greater_than_equal(performance.eventCounts.get(eventType), 2, testCounts(t, resolve, looseCount, eventType, 2);
`Should have at least 2 ${eventType} events`) }));
} else {
assert_equals(performance.eventCounts.get(eventType), 2,
`Should have 2 ${eventType} events`);
}
// The durationThreshold used by the observer. A slow events needs to be slower than that. // The durationThreshold used by the observer. A slow events needs to be slower than that.
const durationThreshold = 16; const durationThreshold = 16;
// Now add an event handler to cause a slow event. // Now add an event handler to cause a slow event.
...@@ -236,14 +252,9 @@ async function testEventType(t, eventType, looseCount=false) { ...@@ -236,14 +252,9 @@ async function testEventType(t, eventType, looseCount=false) {
false /* isFirst */, false /* isFirst */,
durationThreshold, durationThreshold,
notCancelable(eventType)); notCancelable(eventType));
if (looseCount) { // Shouldn't need async testing here since we already got the observer entry, but might as
assert_greater_than_equal(performance.eventCounts.get(eventType), 3, // well reuse the method.
`Should have at least 3 ${eventType} events`) testCounts(t, resolve, looseCount, eventType, 3);
} else {
assert_equals(performance.eventCounts.get(eventType), 3,
`Should have 3 ${eventType} events`);
}
resolve();
})).observe({type: 'event', durationThreshold: durationThreshold}); })).observe({type: 'event', durationThreshold: durationThreshold});
}); });
// Cause a slow event. // Cause a slow event.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment