Bug 1640678 [wpt PR 23758] - [EventTiming] Use polling in performance.eventCounts test, a=testonly
authorNicolás Peña Moreno <npm@chromium.org>
Wed, 27 May 2020 21:36:48 +0000
changeset 533058 66dc5283c5b374b61bd32a772d0168a6371dc876
parent 533057 9d767e432fd5738efba8e735ec2a6b423c0aafe0
child 533059 fb8ebb0fddd580330c3e9bb005a88540a0424a18
push id37462
push usermalexandru@mozilla.com
push dateSat, 30 May 2020 09:46:43 +0000
treeherdermozilla-central@8aaca63ec5c6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1640678, 23758, 1074048, 2212497, 771778
milestone78.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1640678 [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: Yoav 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
testing/web-platform/tests/event-timing/resources/event-timing-test-utils.js
--- a/testing/web-platform/tests/event-timing/resources/event-timing-test-utils.js
+++ b/testing/web-platform/tests/event-timing/resources/event-timing-test-utils.js
@@ -177,38 +177,54 @@ function requiresListener(eventType) {
           'pointerup'
         ].includes(eventType);
 }
 
 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
 // counts will be larger.
 async function testEventType(t, eventType, looseCount=false) {
   assert_implements(window.EventCounts, "Event Counts isn't supported");
   assert_equals(performance.eventCounts.get(eventType), 0);
   const target = document.getElementById('target');
   if (requiresListener(eventType)) {
     target.addEventListener(eventType, () =>{});
   }
   assert_equals(performance.eventCounts.get(eventType), 0, 'No events yet.');
   // 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.
   target.addEventListener(eventType, () => {
     mainThreadBusy(durationThreshold + 4);
   });
   const observerPromise = new Promise(async resolve => {
     new PerformanceObserver(t.step_func(entryList => {
@@ -231,22 +247,17 @@ async function testEventType(t, eventTyp
           return;
       }
       verifyEvent(entry,
                   eventType,
                   'target',
                   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.
   let actionPromise = applyAction(eventType, target);
   return Promise.all([actionPromise, observerPromise]);
 }