Fenced frame: attempt to de-flake tab-focus test.

This test involves clicks, which tends to be flaky with fenced frames.
Attempt to fix the flakes by using the |multiClick()| helper function.
This will hopefully improve the reliability, but there might be more
flake sources that will need their own separate fixes.

Bug: 339232490
Change-Id: I856c656776b86b89d10534b6965a870d738d74ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5719100
Commit-Queue: Liam Brady <lbrady@google.com>
Reviewed-by: Andrew Verge <averge@chromium.org>
Commit-Queue: Andrew Verge <averge@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1329126}
diff --git a/third_party/blink/web_tests/wpt_internal/fenced_frame/resources/utils.js b/third_party/blink/web_tests/wpt_internal/fenced_frame/resources/utils.js
index de06985..e578b0f8 100644
--- a/third_party/blink/web_tests/wpt_internal/fenced_frame/resources/utils.js
+++ b/third_party/blink/web_tests/wpt_internal/fenced_frame/resources/utils.js
@@ -603,3 +603,19 @@
     document.head.appendChild(second_meta);
   }
 }
+
+// Clicking in WPT tends to be flaky (https://crbug.com/1066891), so you may
+// need to click multiple times to have an effect. This function clicks at
+// coordinates `{x, y}` relative to `click_origin`, by default 3 times. Should
+// not be used for tests where multiple clicks have distinct impact on the state
+// of the page, but rather to bruteforce through flakes that rely on only one
+// click.
+async function multiClick(x, y, click_origin, times = 3) {
+  for (let i = 0; i < times; i++) {
+    let actions = new test_driver.Actions();
+    await actions.pointerMove(x, y, {origin: click_origin})
+        .pointerDown()
+        .pointerUp()
+        .send();
+  }
+}
diff --git a/third_party/blink/web_tests/wpt_internal/fenced_frame/tab-focus.https.html b/third_party/blink/web_tests/wpt_internal/fenced_frame/tab-focus.https.html
index e4eaaf1..d64fec7 100644
--- a/third_party/blink/web_tests/wpt_internal/fenced_frame/tab-focus.https.html
+++ b/third_party/blink/web_tests/wpt_internal/fenced_frame/tab-focus.https.html
@@ -50,17 +50,8 @@
     // TODO(crbug.com/1289792) This is needed due to a bug in the experimental
     // flag BlockingFocusWithoutUserActivation for cross-origin iframes,
     // or any other frame where user activations are isolated.
-    var actions = new test_driver.Actions();
     var fencedframe = document.body.getElementsByTagName('fencedframe')[0]
-    await actions.pointerMove(0, 0, {origin: fencedframe})
-                 .pointerDown()
-                 .pointerUp()
-                 .send();
-
-    await actions.pointerMove(0, 0, {origin: document.body})
-                 .pointerDown()
-                 .pointerUp()
-                 .send();
+    await multiClick(10, 10, fencedframe);
 
     document.getElementById('input').focus();
     testRunner.setBrowserHandlesFocus(true);