Commit 98a5aa00 authored by Nicolás Peña Moreno's avatar Nicolás Peña Moreno Committed by moz-wptsync-bot
Browse files

Bug 16406787 [wpt PR 23758] - [EventTiming] Use polling in performance.eventCounts test, a=testonly

Automatic update from web-platform-tests
[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/+/2212497

Reviewed-by: default avatarYoav Weiss <yoavweiss@chromium.org>
Commit-Queue: Nicolás Peña Moreno <npm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771778}

--

wpt-commits: 546dd707ac9440acfc40a326837a1e4032e0a2ff
wpt-pr: 23758
parent fb378298
......@@ -182,6 +182,26 @@ function notCancelable(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
// '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
......@@ -197,13 +217,9 @@ async function testEventType(t, eventType, looseCount=false) {
// Trigger two 'fast' events of the type.
await applyAction(eventType, target);
await applyAction(eventType, target);
if (looseCount) {
assert_greater_than_equal(performance.eventCounts.get(eventType), 2,
`Should have at least 2 ${eventType} events`)
} else {
assert_equals(performance.eventCounts.get(eventType), 2,
`Should have 2 ${eventType} events`);
}
await new Promise(t.step_func(resolve => {
testCounts(t, resolve, looseCount, eventType, 2);
}));
// The durationThreshold used by the observer. A slow events needs to be slower than that.
const durationThreshold = 16;
// Now add an event handler to cause a slow event.
......@@ -236,14 +252,9 @@ async function testEventType(t, eventType, looseCount=false) {
false /* isFirst */,
durationThreshold,
notCancelable(eventType));
if (looseCount) {
assert_greater_than_equal(performance.eventCounts.get(eventType), 3,
`Should have at least 3 ${eventType} events`)
} else {
assert_equals(performance.eventCounts.get(eventType), 3,
`Should have 3 ${eventType} events`);
}
resolve();
// Shouldn't need async testing here since we already got the observer entry, but might as
// well reuse the method.
testCounts(t, resolve, looseCount, eventType, 3);
})).observe({type: 'event', durationThreshold: durationThreshold});
});
// Cause a slow event.
......
Supports Markdown
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