Reland "Populate pointerId, pointerType for contextmenu event"

This is a reland of a6d69d5243dd02afbd8ef02e5a5c557dd8c4a9e9

I believe the reason for the test failures when this landed
the first time was related to how pointerId was populated
for the contextmenu pointer event.
With crrev.com/c/2889205 landed, we have a robust way to
associate the gesture event sequence with the corresponding
pointer event sequence.
This CL uses the approach in crrev.com/c/2889205 to populate
the pointerId for the contextmenu pointer event.

Original change's description:
> Populate pointerId, pointerType for contextmenu event
>
> For contextmenu as a pointer event pointerId and pointerType
> were not populated.
>
> In this CL we are populating pointerId/pointerType for contextmenu
> coming from touch and mouse.
> For touch we use a similar approach to crrev.com/c/2800231
> for populating pointerId,pointerType for clicks generated in
> GestureManager::HandleGestureTap.
> The main change will be in EventHandler::SendContextMenuEvent
> where we'll be passing id and pointer type to the call to
> MouseEventManager::DispatchMouseEvent. This in turn will
> populate pointerId and pointerType correctly when the contextmenu
> PointerEvent is created.
>
> Bug: 1150442,1150441
> TEST: external/wpt/pointerevents/pointerevent_contextmenu_is_a_pointerevent.html
> Change-Id: If2408d9cf0d5f00b08efcf2236ff7933472972ce
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2874026
> Commit-Queue: Liviu Tinta <liviutinta@chromium.org>
> Reviewed-by: Robert Flack <flackr@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#881145}

Bug: 1150442,1150441,1207709
Change-Id: Iffaa60373a3811a10f54ff123e64850801450883
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3101585
Commit-Queue: Liviu Tinta <liviutinta@chromium.org>
Reviewed-by: Mustaq Ahmed <mustaq@chromium.org>
Reviewed-by: Robert Flack <flackr@chromium.org>
Cr-Commit-Position: refs/heads/main@{#916130}
diff --git a/pointerevents/pointerevent_contextmenu_is_a_pointerevent.html b/pointerevents/pointerevent_contextmenu_is_a_pointerevent.html
index 8a82083..9cdb33c 100644
--- a/pointerevents/pointerevent_contextmenu_is_a_pointerevent.html
+++ b/pointerevents/pointerevent_contextmenu_is_a_pointerevent.html
@@ -1,5 +1,7 @@
 <!DOCTYPE HTML>
 <title>contexmenu is a PointerEvent</title>
+<meta name="variant" content="?mouse">
+<meta name="variant" content="?touch">
 <link rel="help" href="https://github.com/w3c/pointerevents/pull/317">
 <script src="/resources/testharness.js"></script>
 <script src="/resources/testharnessreport.js"></script>
@@ -13,17 +15,35 @@
 'use strict';
 let contextmenuTest = async_test("contextmenu is a PointerEvent");
 let target = document.getElementById("target");
+let pointerdownPointerId, pointerdownPointerType;
+let inputSource = location.search.substring(1);
 
 target.addEventListener("contextmenu", contextmenuTest.step_func((e)=>{
   assert_equals(e.constructor, window.PointerEvent, "contextmenu should use a PointerEvent constructor");
   assert_true(e instanceof PointerEvent, "contextmenu should be a PointerEvent");
-  // TODO(crbug.com/1150441,crbug.com/1150442): Test pointerId, pointerType are properly populated from the pointer event stream
+  assert_equals(e.pointerId, pointerdownPointerId, "contextmenu's pointerId should match the pointerId of the pointer event that triggers it");
+    assert_equals(e.pointerType, pointerdownPointerType, "contextmenu's pointerType should match the pointerType of the pointer event that triggers it");
 }));
+target.addEventListener("pointerdown", e=>{
+  pointerdownPointerId = e.pointerId;
+  pointerdownPointerType = e.pointerType;
+});
 
 let eventWatcher = new EventWatcher(contextmenuTest, target, ["contextmenu"]);
 let actions = new test_driver.Actions();
-actions = actions.pointerMove(0,0, {origin:target})
-  .pointerDown({button:actions.ButtonType.RIGHT})
-  .pointerUp({button:actions.ButtonType.RIGHT});
+if(inputSource === "mouse"){
+  actions = actions.pointerMove(0,0, {origin:target})
+    .pointerDown({button:actions.ButtonType.RIGHT})
+    .pointerUp({button:actions.ButtonType.RIGHT});
+}else if(inputSource === "touch"){
+  // TODO: We might be able to test "pen" just like "touch" except for setting
+  // the pointerType.
+  let testPointer = "touchTestPointer";
+  actions.addPointer(testPointer, "touch")
+         .pointerMove(0,0, {origin:target})
+         .pointerDown({sourceName:testPointer})
+         .pause(1500, "pointer", {sourceName:testPointer})
+         .pointerUp({sourceName:testPointer});
+}
 Promise.all([eventWatcher.wait_for("contextmenu"), actions.send()]).then(()=>contextmenuTest.done());
 </script>