Make cross-origin-ancestor-activeelement-after-child-lose-focus.sub.html more robust.

This makes two changes to try to make the test
cross-origin-ancestor-activeelement-after-child-lose-focus.sub.html more
robust:
* It checks the message data in case postMessage is used by something
  else in WPT (although I think this is unlikely), to make sure that the
  message received is the one intended (that is sent by the subframe's
  subframe).
* It makes the subframe's subframe wait until load before focusing its
  input, on the theory that it might be possible that this focusing is
  happening too early to be effective.

My hope is that these might fix the test being flaky in Chromium CI.

Bug: 332068449
Change-Id: Idf70ba87a8559223f9dff7900cadca9ea56126e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5464001
Auto-Submit: David Baron <dbaron@chromium.org>
Commit-Queue: Di Zhang <dizhangg@chromium.org>
Reviewed-by: Di Zhang <dizhangg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1288995}
diff --git a/focus/cross-origin-ancestor-activeelement-after-child-lose-focus.sub.html b/focus/cross-origin-ancestor-activeelement-after-child-lose-focus.sub.html
index 99ea924..1b84b43 100644
--- a/focus/cross-origin-ancestor-activeelement-after-child-lose-focus.sub.html
+++ b/focus/cross-origin-ancestor-activeelement-after-child-lose-focus.sub.html
@@ -20,7 +20,11 @@
 
     const innerIFrame = outerIFrame.contentDocument.createElement("iframe");
 
-    window.onmessage = function() {
+    window.onmessage = function(event) {
+      if (event.data != "ready") {
+        return;
+      }
+
       // We receive an message when the innerIFrame is ready and its input is focused.
       // outerIframe is the ancestor of inner iframe, so the activeElement of
       // it should be the inner iframe.
diff --git a/focus/support/cross-origin-ancestor-activeelement-after-child-lose-focus-helper.html b/focus/support/cross-origin-ancestor-activeelement-after-child-lose-focus-helper.html
index 83d39d5..fe96614 100644
--- a/focus/support/cross-origin-ancestor-activeelement-after-child-lose-focus-helper.html
+++ b/focus/support/cross-origin-ancestor-activeelement-after-child-lose-focus-helper.html
@@ -2,8 +2,10 @@
 <body>
   <input />
   <script>
-    document.querySelector("input").focus();
-    window.parent.parent.postMessage("ready", '*');
+    window.onload = function() {
+      document.querySelector("input").focus();
+      window.parent.parent.postMessage("ready", '*');
+    }
   </script>
 </body>
 </html>