Bug 1635342 [wpt PR 23400] - [EventTiming] Add a test for auxclick, a=testonly
authorNicolás Peña Moreno <npm@chromium.org>
Wed, 13 May 2020 09:41:13 +0000
changeset 531076 a6b58a4d95a4e77f5d8771905942705b5cda9022
parent 531075 90ea5be3fa3ef4be7847b783155231506971200b
child 531077 25769222be5a26beafa3a1a51fbf3254b16fce9b
push id37435
push userapavel@mozilla.com
push dateWed, 20 May 2020 15:28:23 +0000
treeherdermozilla-central@5415da14ec9a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1635342, 23400, 543598, 2181147, 765537
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 1635342 [wpt PR 23400] - [EventTiming] Add a test for auxclick, a=testonly Automatic update from web-platform-tests [EventTiming] Add a test for auxclick This CL adds a helper function to add a test for an event type. The test will add two fast events of the event type and one slow one and test that the eventCounts as well as the entry in the PerformanceObserver for the slow event. Bug: 543598 Change-Id: I37da66424e7ea353b99787c578b26e3322cd984e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2181147 Commit-Queue: Nicolás Peña Moreno <npm@chromium.org> Reviewed-by: Yoav Weiss <yoavweiss@chromium.org> Cr-Commit-Position: refs/heads/master@{#765537} -- wpt-commits: 471e15e649002cb334f8b89d8b4a9ebb5122e437 wpt-pr: 23400
testing/web-platform/tests/event-timing/auxclick.html
testing/web-platform/tests/event-timing/resources/event-timing-test-utils.js
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/event-timing/auxclick.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8 />
+<title>Event Timing auxclick.</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script src=/resources/testdriver.js></script>
+<script src=/resources/testdriver-actions.js></script>
+<script src=/resources/testdriver-vendor.js></script>
+<script src=resources/event-timing-test-utils.js></script>
+<div id='target'>Click me</div>
+<button id='button'>Click me</button>
+<script>
+  promise_test(async t => {
+    return testEventType(t, 'auxclick');
+  })
+</script>
+</html>
--- 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
@@ -17,19 +17,19 @@ function mainThreadBusy(duration) {
   const now = performance.now();
   while (performance.now() < now + duration);
 }
 
 // This method should receive an entry of type 'event'. |isFirst| is true only when we want
 // to check that the event also happens to correspond to the first event. In this case, the
 // timings of the 'first-input' entry should be equal to those of this entry. |minDuration|
 // is used to compared against entry.duration.
-function verifyClickEvent(entry, targetId, isFirst=false, minDuration=104) {
+function verifyEvent(entry, eventType, targetId, isFirst=false, minDuration=104) {
   assert_true(entry.cancelable);
-  assert_equals(entry.name, 'mousedown');
+  assert_equals(entry.name, eventType);
   assert_equals(entry.entryType, 'event');
   assert_greater_than_equal(entry.duration, minDuration,
       "The entry's duration should be greater than or equal to " + minDuration + " ms.");
   assert_greater_than(entry.processingStart, entry.startTime,
       "The entry's processingStart should be greater than startTime.");
   assert_greater_than_equal(entry.processingEnd, entry.processingStart,
       "The entry's processingEnd must be at least as large as processingStart.");
   // |duration| is a number rounded to the nearest 8 ms, so add 4 to get a lower bound
@@ -47,16 +47,20 @@ function verifyClickEvent(entry, targetI
     assert_equals(firstInput.processingStart, entry.processingStart);
     assert_equals(firstInput.processingEnd, entry.processingEnd);
     assert_equals(firstInput.cancelable, entry.cancelable);
   }
   if (targetId)
     assert_equals(entry.target, document.getElementById(targetId));
 }
 
+function verifyClickEvent(entry, targetId, isFirst=false, minDuration=104) {
+  verifyEvent(entry, 'mousedown', targetId, isFirst, minDuration);
+}
+
 function wait() {
   return new Promise((resolve, reject) => {
     step_timeout(() => {
       resolve();
     }, 0);
   });
 }
 
@@ -111,9 +115,58 @@ async function testDuration(t, id, numEn
       } else {
         // We can just directly call test_driver when |fastDur| is 0.
         await test_driver.click(document.getElementById(id));
       }
     }
     resolve();
   });
   return Promise.all([observerPromise, clicksPromise]);
+}
+
+function applyAction(actions, eventType, target) {
+  if (eventType === 'auxclick') {
+    actions.pointerMove(0, 0, {origin: target})
+    .pointerDown({button: actions.ButtonType.MIDDLE})
+    .pointerUp({button: actions.ButtonType.MIDDLE});
+  } else {
+    assert_unreached('The event type ' + eventType + ' is not supported.');
+  }
+}
+
+// Tests the given |eventType| by creating events whose target are the element with id 'target'.
+// The test assumes that such element already exists.
+async function testEventType(t, eventType) {
+  assert_implements(window.EventCounts, "Event Counts isn't supported");
+  assert_equals(performance.eventCounts.get(eventType), 0);
+  const target = document.getElementById('target');
+  const actions = new test_driver.Actions();
+  // Trigger two 'fast' events of the type.
+  applyAction(actions, eventType, target);
+  applyAction(actions, eventType, target);
+  await actions.send();
+  assert_equals(performance.eventCounts.get('auxclick'), 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);
+  });
+  return new Promise(async resolve => {
+    new PerformanceObserver(t.step_func(entryList => {
+      let eventTypeEntries = entryList.getEntriesByName(eventType);
+      if (eventTypeEntries.length === 0)
+        return;
+
+      assert_equals(eventTypeEntries.length, 1);
+      verifyEvent(eventTypeEntries[0],
+                  eventType,
+                  'target',
+                  false /* isFirst */,
+                  durationThreshold);
+      assert_equals(performance.eventCounts.get(eventType), 3);
+      resolve();
+    })).observe({type: 'event', durationThreshold: durationThreshold});
+    // Cause a slow event.
+    applyAction(actions, eventType, target);
+    actions.send();
+  });
 }
\ No newline at end of file