Bug 1635306 [wpt PR 23393] - Add rAF delays before cross-origin clicks to fix flakiness., a=testonly
authorMustaq Ahmed <mustaq@google.com>
Wed, 13 May 2020 09:41:03 +0000
changeset 530025 2b16450fca689e9c6f77a7ae1a14e3f0e9912560
parent 530024 81572d467873741a07973db4a2b35f9777772503
child 530026 fdaa51024719d3153fd075a2b3e18c6c5009e97c
push id116003
push userwptsync@mozilla.com
push dateThu, 14 May 2020 19:04:08 +0000
treeherderautoland@7baa72e0d62c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1635306, 23393, 1064422, 1066178, 1066190, 2174887, 765543
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 1635306 [wpt PR 23393] - Add rAF delays before cross-origin clicks to fix flakiness., a=testonly Automatic update from web-platform-tests Add rAF delays before cross-origin clicks to fix flakiness. For cross-origin frames in WPTs, just waiting for all frames to load is not enough because cross-origin frame's hit-test data may not be ready by that time for the click to work correctly. This caused flakiness in all three cross-origin tests for user-activation. This CL adds rAF delays (after frame load completion) so that the clicks can get through correctly. Other changes: switched all async tests into sync tests nested inside a single async test to make the code easier to follow. Bug: 1064422, 1066178, 1066190 Change-Id: I853ff032c8050203abc72d89f0d6276af5102beb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174887 Reviewed-by: Navid Zolghadr <nzolghadr@chromium.org> Commit-Queue: Mustaq Ahmed <mustaq@chromium.org> Cr-Commit-Position: refs/heads/master@{#765543} -- wpt-commits: 6eea984f808b5c47fc506bced9b40372652d0c0e wpt-pr: 23393
testing/web-platform/tests/html/user-activation/consumption-crossorigin.sub.tentative.html
testing/web-platform/tests/html/user-activation/consumption-sameorigin.tentative.html
testing/web-platform/tests/html/user-activation/navigation-state-reset-crossorigin.sub.tentative.html
testing/web-platform/tests/html/user-activation/navigation-state-reset-sameorigin.tentative.html
testing/web-platform/tests/html/user-activation/propagation-crossorigin.sub.tentative.html
testing/web-platform/tests/html/user-activation/propagation-sameorigin.tentative.html
testing/web-platform/tests/html/user-activation/resources/utils.js
--- a/testing/web-platform/tests/html/user-activation/consumption-crossorigin.sub.tentative.html
+++ b/testing/web-platform/tests/html/user-activation/consumption-crossorigin.sub.tentative.html
@@ -4,108 +4,94 @@
    https://github.com/whatwg/html/issues/1983
 -->
 <html>
 <head>
   <script src="/resources/testharness.js"></script>
   <script src="/resources/testharnessreport.js"></script>
   <script src="/resources/testdriver.js"></script>
   <script src="/resources/testdriver-vendor.js"></script>
+  <script src="resources/utils.js"></script>
   <script>
     // Frame layout:
     // top=origin0:this-file [
     //   child1=origin1:child-one.html,
     //   child-xo=origin2:consumption-crossorigin-child.html [
     //     gchild=origin3:child-two.html
     //   ]
     // ]
-    let test_parent_initial = async_test("Parent frame initial state");
-    let test_parent_final = async_test("Parent frame final state");
-
-    let test_child1_initial = async_test("Child1 frame initial state");
-    let test_child1_final = async_test("Child1 frame final state");
-
-    let test_child_xo_initial = async_test("Child2 frame initial state");
-    let test_child_xo_final = async_test("Child2 frame final state");
-
-    let test_gchild_initial = async_test("Grandchild frame initial state");
-    let test_gchild_final = async_test("Grand child frame final state");
+    let consumption_test = async_test("Consumption test");
 
     let num_children_to_load = 3;
     let num_children_to_report = 3;
 
     function finishLoadPhase() {
-        test_parent_initial.step(() => {
-            assert_true(num_children_to_load == 0);
+        assert_true(num_children_to_load == 0);
+
+        test(() => {
             assert_false(navigator.userActivation.isActive);
             assert_false(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_initial.done();
+        }, "Parent frame initial state");
 
-        test_driver.click(document.getElementById("child1"));
+        delayByFrames(() => test_driver.click(document.getElementById("child1")), 5);
         // The click at "child-xo" happens after receiving "child-one-clicked" msg.
     }
 
     function finishReportPhase() {
-        test_parent_final.step(() => {
-            assert_true(num_children_to_report == 0);
+        assert_true(num_children_to_report == 0);
+
+        test(() => {
             assert_false(navigator.userActivation.isActive);
             assert_true(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_final.done();
-        // End of all tests.
+        }, "Parent frame final state");
+
+        consumption_test.done();
     }
 
     window.addEventListener("message", event => {
         var msg = JSON.parse(event.data);
 
         if (msg.type == 'child-one-loaded') {
-            test_child1_initial.step(() => {
-                assert_false(msg.isActive);
-                assert_false(msg.hasBeenActive);
-            });
-            test_child1_initial.done();
-        } else if (msg.type == 'child-crossorigin-loaded') {
-            test_child_xo_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child_xo_initial.done();
-        } else if (msg.type == 'child-two-loaded') {
-            test_gchild_initial.step(() => {
+            }, "Child1 frame initial state");
+        } else if (msg.type == 'child-crossorigin-loaded') {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_gchild_initial.done();
+            }, "Child2 frame initial state");
+        } else if (msg.type == 'child-two-loaded') {
+            test(() => {
+                assert_false(msg.isActive);
+                assert_false(msg.hasBeenActive);
+            }, "Grandchild frame initial state");
         } else if (msg.type == 'child-one-clicked') {
             test_driver.click(document.getElementById("child-xo"));
         } else if (msg.type == 'child-one-report') {
-            test_child1_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child1_final.done();
+            }, "Child1 frame final state");
         } else if (msg.type == 'child-crossorigin-report') {
             // This msg was triggered by a user click followed by a window.open().
-            test_child_xo_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child_xo_final.done();
+            }, "Child2 frame final state");
 
             // Ask remaining frames to report states.
             let ask_report = JSON.stringify({"type": "report"});
             frames[0].postMessage(ask_report, "*");
             frames[1].frames[0].postMessage(ask_report, "*");
         } else if (msg.type == 'child-two-report') {
-            test_gchild_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_gchild_final.done();
+            }, "Grand child frame final state");
         }
 
         // Phase switching.
         if (msg.type.endsWith("-loaded")) {
             if (--num_children_to_load == 0)
                 finishLoadPhase();
         } else if (msg.type.endsWith("-report")) {
             if (--num_children_to_report == 0)
--- a/testing/web-platform/tests/html/user-activation/consumption-sameorigin.tentative.html
+++ b/testing/web-platform/tests/html/user-activation/consumption-sameorigin.tentative.html
@@ -12,97 +12,82 @@
   <script>
     // Frame layout:
     // top=this-file [
     //   child1=child-one.html,
     //   child-so=consumption-sameorigin-child.html [
     //     gchild=child-two.html
     //   ]
     // ]
-    let test_parent_initial = async_test("Parent frame initial state");
-    let test_parent_final = async_test("Parent frame final state");
-
-    let test_child1_initial = async_test("Child1 frame initial state");
-    let test_child1_final = async_test("Child1 frame final state");
-
-    let test_child_so_initial = async_test("Child2 frame initial state");
-    let test_child_so_final = async_test("Child2 frame final state");
-
-    let test_gchild_initial = async_test("Grandchild frame initial state");
-    let test_gchild_final = async_test("Grand child frame final state");
+    let consumption_test = async_test("Consumption test");
 
     let num_children_to_load = 3;
     let num_children_to_report = 3;
 
     function finishLoadPhase() {
-        test_parent_initial.step(() => {
-            assert_true(num_children_to_load == 0);
+        assert_true(num_children_to_load == 0);
+
+        test(() => {
             assert_false(navigator.userActivation.isActive);
             assert_false(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_initial.done();
+        }, "Parent frame initial state");
 
         test_driver.click(document.getElementById("child-so"));
     }
 
     function finishReportPhase() {
-        test_parent_final.step(() => {
-            assert_true(num_children_to_report == 0);
+        assert_true(num_children_to_report == 0);
+
+        test(() => {
             assert_false(navigator.userActivation.isActive);
             assert_true(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_final.done();
-        // End of all tests.
+        }, "Parent frame final state");
+
+        consumption_test.done();
     }
 
     window.addEventListener("message", event => {
         var msg = JSON.parse(event.data);
 
         if (msg.type == 'child-one-loaded') {
-            test_child1_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child1_initial.done();
+            }, "Child1 frame initial state");
         } else if (msg.type == 'child-sameorigin-loaded') {
-            test_child_so_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child_so_initial.done();
+            }, "Child2 frame initial state");
         } else if (msg.type == 'child-two-loaded') {
-            test_gchild_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_gchild_initial.done();
+            }, "Grandchild frame initial state");
         } else if (msg.type == 'child-one-report') {
-            test_child1_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child1_final.done();
+            }, "Child1 frame final state");
         } else if (msg.type == 'child-sameorigin-report') {
             // This msg was triggered by a user click followed by a window.open().
-            test_child_so_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child_so_final.done();
+            }, "Child2 frame final state");
 
             // Ask remaining frames to report states.
             let ask_report = JSON.stringify({"type": "report"});
             frames[0].postMessage(ask_report, "*");
             frames[1].frames[0].postMessage(ask_report, "*");
         } else if (msg.type == 'child-two-report') {
-            test_gchild_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_gchild_final.done();
+            }, "Grand child frame final state");
         }
 
         // Phase switching.
         if (msg.type.endsWith("-loaded")) {
             if (--num_children_to_load == 0)
                 finishLoadPhase();
         } else if (msg.type.endsWith("-report")) {
             if (--num_children_to_report == 0)
--- a/testing/web-platform/tests/html/user-activation/navigation-state-reset-crossorigin.sub.tentative.html
+++ b/testing/web-platform/tests/html/user-activation/navigation-state-reset-crossorigin.sub.tentative.html
@@ -1,19 +1,20 @@
 <!DOCTYPE html>
 <!--
    Tentative due to:
    https://github.com/whatwg/html/issues/1983
 -->
 <html>
 <head>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/testdriver.js"></script>
-<script src="/resources/testdriver-vendor.js"></script>
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <script src="/resources/testdriver.js"></script>
+  <script src="/resources/testdriver-vendor.js"></script>
+  <script src="resources/utils.js"></script>
 </head>
 <body>
   <h1>Post-navigation activation state in child</h1>
   <p>Tests that navigating a cross-origin child frame resets its activation states.</p>
   <ol id="instructions">
     <li>Click inside the yellow area.
   </ol>
   <iframe id="child" width="200" height="50"
@@ -25,17 +26,17 @@
       window.addEventListener("message", t.step_func(event => {
           var msg = JSON.parse(event.data);
           if (msg.type == 'child-one-loaded') {
               assert_false(navigator.userActivation.isActive);
               assert_false(navigator.userActivation.hasBeenActive);
               assert_false(msg.isActive);
               assert_false(msg.hasBeenActive);
 
-              test_driver.click(child);
+              delayByFrames(() => test_driver.click(child), 5);
           } else if (msg.type == 'child-one-clicked') {
               assert_true(navigator.userActivation.isActive);
               assert_true(navigator.userActivation.hasBeenActive);
               assert_true(msg.isActive);
               assert_true(msg.hasBeenActive);
 
               child.src = "http://{{domains[www2]}}:{{ports[http][0]}}/html/user-activation/resources/child-two.html";
           } else if (msg.type == 'child-two-loaded') {
--- a/testing/web-platform/tests/html/user-activation/navigation-state-reset-sameorigin.tentative.html
+++ b/testing/web-platform/tests/html/user-activation/navigation-state-reset-sameorigin.tentative.html
@@ -1,19 +1,19 @@
 <!DOCTYPE html>
 <!--
    Tentative due to:
    https://github.com/whatwg/html/issues/1983
 -->
 <html>
 <head>
-<script src="/resources/testharness.js"></script>
-<script src="/resources/testharnessreport.js"></script>
-<script src="/resources/testdriver.js"></script>
-<script src="/resources/testdriver-vendor.js"></script>
+  <script src="/resources/testharness.js"></script>
+  <script src="/resources/testharnessreport.js"></script>
+  <script src="/resources/testdriver.js"></script>
+  <script src="/resources/testdriver-vendor.js"></script>
 </head>
 <body>
   <h1>Post-navigation activation state in child</h1>
   <p>Tests that navigating a same-origin child frame resets its activation states.</p>
   <ol id="instructions">
     <li>Click inside the yellow area.
   </ol>
   <iframe id="child" width="200" height="50"
--- a/testing/web-platform/tests/html/user-activation/propagation-crossorigin.sub.tentative.html
+++ b/testing/web-platform/tests/html/user-activation/propagation-crossorigin.sub.tentative.html
@@ -4,105 +4,91 @@
    https://github.com/whatwg/html/issues/1983
 -->
 <html>
 <head>
   <script src="/resources/testharness.js"></script>
   <script src="/resources/testharnessreport.js"></script>
   <script src="/resources/testdriver.js"></script>
   <script src="/resources/testdriver-vendor.js"></script>
+  <script src="resources/utils.js"></script>
   <script>
     // Frame layout:
     // top=origin0:this-file [
     //   child1=origin1:child-one.html,
     //   child-xo=origin2:propagation-crossorigin-child.html [
     //     gchild=origin3:child-two.html
     //   ]
     // ]
-    let test_parent_initial = async_test("Parent frame initial state");
-    let test_parent_final = async_test("Parent frame final state");
-
-    let test_child1_initial = async_test("Child1 frame initial state");
-    let test_child1_final = async_test("Child1 frame final state");
-
-    let test_child_xo_initial = async_test("Child2 frame initial state");
-    let test_child_xo_final = async_test("Child2 frame final state");
-
-    let test_gchild_initial = async_test("Grandchild frame initial state");
-    let test_gchild_final = async_test("Grand child frame final state");
+    let propagation_test = async_test("Propagation test");
 
     let num_children_to_load = 3;
     let num_children_to_report = 3;
 
     function finishLoadPhase() {
-        test_parent_initial.step(() => {
-            assert_true(num_children_to_load == 0);
+        assert_true(num_children_to_load == 0);
+
+        test(() => {
             assert_false(navigator.userActivation.isActive);
             assert_false(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_initial.done();
+        }, "Parent frame initial state");
 
-        test_driver.click(document.getElementById("child-xo"));
+        delayByFrames(() => test_driver.click(document.getElementById("child-xo")), 5);
     }
 
     function finishReportPhase() {
-        test_parent_final.step(() => {
-            assert_true(num_children_to_report == 0);
+        assert_true(num_children_to_report == 0);
+
+        test(() => {
             assert_true(navigator.userActivation.isActive);
             assert_true(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_final.done();
-        // End of all tests.
+        }, "Parent frame final state");
+
+        propagation_test.done();
     }
 
     window.addEventListener("message", event => {
         var msg = JSON.parse(event.data);
 
         if (msg.type == 'child-one-loaded') {
-            test_child1_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child1_initial.done();
+            }, "Child1 frame initial state");
         } else if (msg.type == 'child-crossorigin-loaded') {
-            test_child_xo_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child_xo_initial.done();
+            }, "Child2 frame initial state");
         } else if (msg.type == 'child-two-loaded') {
-            test_gchild_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_gchild_initial.done();
+            }, "Grandchild frame initial state");
         } else if (msg.type == 'child-one-report') {
-            test_child1_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child1_final.done();
+            }, "Child1 frame final state");
         } else if (msg.type == 'child-crossorigin-report') {
             // This msg was triggered by a user click.
-            test_child_xo_final.step(() => {
+            test(() => {
                 assert_true(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child_xo_final.done();
+            }, "Child2 frame final state");
 
             // Ask remaining frames to report states.
             let ask_report = JSON.stringify({"type": "report"});
             frames[0].postMessage(ask_report, "*");
             frames[1].frames[0].postMessage(ask_report, "*");
         } else if (msg.type == 'child-two-report') {
-            test_gchild_final.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_gchild_final.done();
+            }, "Grand child frame final state");
         }
 
         // Phase switching.
         if (msg.type.endsWith("-loaded")) {
             if (--num_children_to_load == 0)
                 finishLoadPhase();
         } else if (msg.type.endsWith("-report")) {
             if (--num_children_to_report == 0)
--- a/testing/web-platform/tests/html/user-activation/propagation-sameorigin.tentative.html
+++ b/testing/web-platform/tests/html/user-activation/propagation-sameorigin.tentative.html
@@ -12,97 +12,82 @@
   <script>
     // Frame layout:
     // top=this-file [
     //   child1=child-one.html,
     //   child-so=propagation-sameorigin-child.html [
     //     gchild=child-two.html
     //   ]
     // ]
-    let test_parent_initial = async_test("Parent frame initial state");
-    let test_parent_final = async_test("Parent frame final state");
-
-    let test_child1_initial = async_test("Child1 frame initial state");
-    let test_child1_final = async_test("Child1 frame final state");
-
-    let test_child_so_initial = async_test("Child2 frame initial state");
-    let test_child_so_final = async_test("Child2 frame final state");
-
-    let test_gchild_initial = async_test("Grandchild frame initial state");
-    let test_gchild_final = async_test("Grand child frame final state");
+    let propagation_test = async_test("Propagation test");
 
     let num_children_to_load = 3;
     let num_children_to_report = 3;
 
     function finishLoadPhase() {
-        test_parent_initial.step(() => {
-            assert_true(num_children_to_load == 0);
+        assert_true(num_children_to_load == 0);
+
+        test(() => {
             assert_false(navigator.userActivation.isActive);
             assert_false(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_initial.done();
+        }, "Parent frame initial state");
 
         test_driver.click(document.getElementById("child-so"));
     }
 
     function finishReportPhase() {
-        test_parent_final.step(() => {
-            assert_true(num_children_to_report == 0);
+        assert_true(num_children_to_report == 0);
+
+        test(() => {
             assert_true(navigator.userActivation.isActive);
             assert_true(navigator.userActivation.hasBeenActive);
-        });
-        test_parent_final.done();
-        // End of all tests.
+        }, "Parent frame final state");
+
+        propagation_test.done();
     }
 
     window.addEventListener("message", event => {
         var msg = JSON.parse(event.data);
 
         if (msg.type == 'child-one-loaded') {
-            test_child1_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child1_initial.done();
+            }, "Child1 frame initial state");
         } else if (msg.type == 'child-sameorigin-loaded') {
-            test_child_so_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_child_so_initial.done();
+            }, "Child2 frame initial state");
         } else if (msg.type == 'child-two-loaded') {
-            test_gchild_initial.step(() => {
+            test(() => {
                 assert_false(msg.isActive);
                 assert_false(msg.hasBeenActive);
-            });
-            test_gchild_initial.done();
+            }, "Grandchild frame initial state");
         } else if (msg.type == 'child-one-report') {
-            test_child1_final.step(() => {
+            test(() => {
                 assert_true(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child1_final.done();
+            }, "Child1 frame final state");
         } else if (msg.type == 'child-sameorigin-report') {
             // This msg was triggered by a user click.
-            test_child_so_final.step(() => {
+            test(() => {
                 assert_true(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_child_so_final.done();
+            }, "Child2 frame final state");
 
             // Ask remaining frames to report states.
             let ask_report = JSON.stringify({"type": "report"});
             frames[0].postMessage(ask_report, "*");
             frames[1].frames[0].postMessage(ask_report, "*");
         } else if (msg.type == 'child-two-report') {
-            test_gchild_final.step(() => {
+            test(() => {
                 assert_true(msg.isActive);
                 assert_true(msg.hasBeenActive);
-            });
-            test_gchild_final.done();
+            }, "Grand child frame final state");
         }
 
         // Phase switching.
         if (msg.type.endsWith("-loaded")) {
             if (--num_children_to_load == 0)
                 finishLoadPhase();
         } else if (msg.type.endsWith("-report")) {
             if (--num_children_to_report == 0)
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/tests/html/user-activation/resources/utils.js
@@ -0,0 +1,9 @@
+function delayByFrames(f, num_frames) {
+  function recurse(depth) {
+    if (depth == 0)
+      f();
+    else
+      requestAnimationFrame(() => recurse(depth-1));
+  }
+  recurse(num_frames);
+}