Bug 1677474 - wpt test; draft
authorEdgar Chen <echen@mozilla.com>
Wed, 17 Feb 2021 13:09:03 +0000
changeset 3545288 060e8340f4916c04571a459af4bdf39596930e0a
parent 3493724 bbeb977d067618b974721e83fab5e5455c1b3a9d
child 3545289 e4d47d943ce622b4adad46e6bbae2ee970d3b4bd
push id656174
push userreviewbot
push dateWed, 17 Feb 2021 13:09:47 +0000
treeherdertry@e4d47d943ce6 [default view] [failures only]
bugs1677474
milestone87.0a1
Bug 1677474 - wpt test; Summary: Differential Revision: https://phabricator.services.mozilla.com/D104538 Test Plan: Reviewers: Subscribers: Bug #: 1677474 Differential Diff: PHID-DIFF-l5mk5e2ogoexaeo4hyh6
testing/web-platform/tests/focus/focus-event-after-iframe-gets-focus.html
testing/web-platform/tests/focus/support/focus-event-after-different-site-iframe-gets-focus-outer.sub.html
testing/web-platform/tests/focus/support/focus-event-after-iframe-gets-focus-inner.html
testing/web-platform/tests/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-middle.sub.html
testing/web-platform/tests/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-outer.sub.html
testing/web-platform/tests/focus/support/focus-event-after-same-site-iframe-gets-focus-outer.html
copy from testing/web-platform/tests/focus/focus-event-after-focusing-iframes.html
copy to testing/web-platform/tests/focus/focus-event-after-iframe-gets-focus.html
--- a/testing/web-platform/tests/focus/focus-event-after-focusing-iframes.html
+++ b/testing/web-platform/tests/focus/focus-event-after-iframe-gets-focus.html
@@ -1,11 +1,11 @@
 <!doctype html>
 <meta charset=utf-8>
-<title>Test focus event after focusing iframe</title>
+<title>Test focus event after iframe gets focus</title>
 <script src=/resources/testharness.js></script>
 <script src=/resources/testharnessreport.js></script>
 <script>
 function waitForEvent(target, event, checkFn) {
   return new Promise(resolve => {
     target.addEventListener(event, e => {
       if (checkFn && !checkFn(e)) {
         return;
@@ -29,27 +29,32 @@ async function getLog(w) {
   }, 0);
   await waitForEvent(window, "message", (e) => {
     log = e.data;
     return true;
   });
   return log;
 }
 
-async function runTest(t, url) {
+async function runTest(t, url, expectResult) {
   let w = window.open(url);
   t.add_cleanup(() => { w.close(); });
   await waitForEvent(window, "message", e => e.data === "ready");
   focusIframe(w);
-  assert_equals(await getLog(w), 'outerlog:willfocusiframe,windowblur,didfocusiframe,innerlog:windowfocus,');
-  focusIframe(w);
-  assert_equals(await getLog(w), 'outerlog:willfocusiframe,windowblur,didfocusiframe,willfocusiframe,didfocusiframe,innerlog:windowfocus,');
+  assert_equals(await getLog(w), expectResult);
 }
 
 promise_test(async t => {
-  await runTest(t, "support/focus-event-after-focusing-different-site-iframes-outer.sub.html");
-}, "Check focus event after focusing different site iframe");
+  await runTest(t, "support/focus-event-after-same-site-iframe-gets-focus-outer.html",
+                "outerlog:windowblur,innerlog:willfocuswindow,windowfocus,didfocuswindow,");
+}, "Check focus event after same site iframe gets focus");
 
 promise_test(async t => {
-  await runTest(t, "support/focus-event-after-focusing-same-site-iframes-outer.html");
-}, "Check focus event after focusing same site iframe");
+  await runTest(t, "support/focus-event-after-different-site-iframe-gets-focus-outer.sub.html",
+                "outerlog:windowblur,innerlog:willfocuswindow,windowfocus,didfocuswindow,");
+}, "Check focus event after different site iframe gets focus");
+
+promise_test(async t => {
+  await runTest(t, "support/focus-event-after-innermost-different-site-iframe-gets-focus-outer.sub.html",
+                "outerlog:windowblur,middlelog:innerlog:willfocuswindow,windowfocus,didfocuswindow,");
+}, "Check focus event after innermost different site iframe gets focus");
 
 </script>
copy from testing/web-platform/tests/focus/support/focus-event-after-focusing-different-site-iframes-outer.sub.html
copy to testing/web-platform/tests/focus/support/focus-event-after-different-site-iframe-gets-focus-outer.sub.html
--- a/testing/web-platform/tests/focus/support/focus-event-after-focusing-different-site-iframes-outer.sub.html
+++ b/testing/web-platform/tests/focus/support/focus-event-after-different-site-iframe-gets-focus-outer.sub.html
@@ -1,21 +1,19 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Focus event after focusing different site iframes outer</title>
-<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-focusing-iframes-inner.html"></iframe>
+<title>Focus event after different site iframe gets focus outer</title>
+<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-iframe-gets-focus-inner.html"></iframe>
 <script>
 let outerlog = "outerlog:";
 
 let iframe = document.querySelector("iframe");
 window.onmessage = function(e) {
   if (e.data == "focus") {
-    outerlog += "willfocusiframe,";
-    iframe.focus();
-    outerlog += "didfocusiframe,";
+    iframe.contentWindow.postMessage("focus", "*");
   } else if (e.data == "getlog") {
     iframe.contentWindow.postMessage("getlog", "*");
   } else {
     opener.postMessage(outerlog + e.data, "*");
   }
 };
 
 window.onload = function() {
copy from testing/web-platform/tests/focus/support/focus-event-after-focusing-iframes-inner.html
copy to testing/web-platform/tests/focus/support/focus-event-after-iframe-gets-focus-inner.html
--- a/testing/web-platform/tests/focus/support/focus-event-after-focusing-iframes-inner.html
+++ b/testing/web-platform/tests/focus/support/focus-event-after-iframe-gets-focus-inner.html
@@ -5,17 +5,21 @@
   <title>Focus event inner document</title>
 </head>
 <body>
 <h1>Inner</h1>
 <script>
 let innerlog = "innerlog:";
 
 window.onmessage = function(e) {
-  if (e.data == "getlog") {
+  if (e.data == "focus") {
+    innerlog += "willfocuswindow,";
+    window.focus();
+    innerlog += "didfocuswindow,";
+  } else if (e.data == "getlog") {
     parent.postMessage(innerlog, "*");
   }
 };
 
 window.onfocus = function() {
   innerlog += "windowfocus,";
 };
 
copy from testing/web-platform/tests/focus/support/focus-event-after-focusing-different-site-iframes-outer.sub.html
copy to testing/web-platform/tests/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-middle.sub.html
--- a/testing/web-platform/tests/focus/support/focus-event-after-focusing-different-site-iframes-outer.sub.html
+++ b/testing/web-platform/tests/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-middle.sub.html
@@ -1,32 +1,27 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Focus event after focusing different site iframes outer</title>
-<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-focusing-iframes-inner.html"></iframe>
+<title>Focus event after different site iframe gets focus middle</title>
+<h1>Middle</h1><br>
+<iframe src="http://{{hosts[][www]}}:{{ports[http][1]}}/focus/support/focus-event-after-iframe-gets-focus-inner.html"></iframe>
 <script>
-let outerlog = "outerlog:";
+let middlelog = "middlelog:";
 
 let iframe = document.querySelector("iframe");
 window.onmessage = function(e) {
   if (e.data == "focus") {
-    outerlog += "willfocusiframe,";
-    iframe.focus();
-    outerlog += "didfocusiframe,";
+    iframe.contentWindow.postMessage("focus", "*");
   } else if (e.data == "getlog") {
     iframe.contentWindow.postMessage("getlog", "*");
   } else {
-    opener.postMessage(outerlog + e.data, "*");
+    parent.postMessage(middlelog + e.data, "*");
   }
 };
 
-window.onload = function() {
-  window.onfocus = function() {
-    outerlog += "windowfocus,";
-  };
+window.onfocus = function() {
+  middlelog += "windowfocus,";
+};
 
-  window.onblur = function() {
-    outerlog += "windowblur,";
-  };
-
-  opener.postMessage("ready", "*");
+window.onblur = function() {
+  middlelog += "windowblur,";
 };
 </script>
copy from testing/web-platform/tests/focus/support/focus-event-after-focusing-different-site-iframes-outer.sub.html
copy to testing/web-platform/tests/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-outer.sub.html
--- a/testing/web-platform/tests/focus/support/focus-event-after-focusing-different-site-iframes-outer.sub.html
+++ b/testing/web-platform/tests/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-outer.sub.html
@@ -1,21 +1,19 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Focus event after focusing different site iframes outer</title>
-<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-focusing-iframes-inner.html"></iframe>
+<title>Focus event after innermost different site iframe gets focus outer</title>
+<iframe src="http://{{hosts[alt][www]}}:{{ports[http][0]}}/focus/support/focus-event-after-innermost-different-site-iframe-gets-focus-middle.sub.html"></iframe>
 <script>
 let outerlog = "outerlog:";
 
 let iframe = document.querySelector("iframe");
 window.onmessage = function(e) {
   if (e.data == "focus") {
-    outerlog += "willfocusiframe,";
-    iframe.focus();
-    outerlog += "didfocusiframe,";
+    iframe.contentWindow.postMessage("focus", "*");
   } else if (e.data == "getlog") {
     iframe.contentWindow.postMessage("getlog", "*");
   } else {
     opener.postMessage(outerlog + e.data, "*");
   }
 };
 
 window.onload = function() {
copy from testing/web-platform/tests/focus/support/focus-event-after-focusing-same-site-iframes-outer.html
copy to testing/web-platform/tests/focus/support/focus-event-after-same-site-iframe-gets-focus-outer.html
--- a/testing/web-platform/tests/focus/support/focus-event-after-focusing-same-site-iframes-outer.html
+++ b/testing/web-platform/tests/focus/support/focus-event-after-same-site-iframe-gets-focus-outer.html
@@ -1,21 +1,19 @@
 <!doctype html>
 <meta charset="utf-8">
-<title>Focus event after focusing same site iframes outer</title>
-<iframe src="focus-event-after-focusing-iframes-inner.html"></iframe>
+<title>Focus event after same site iframe gets focus outer</title>
+<iframe src="focus-event-after-iframe-gets-focus-inner.html"></iframe>
 <script>
 let outerlog = "outerlog:";
 
 let iframe = document.querySelector("iframe");
 window.onmessage = function(e) {
   if (e.data == "focus") {
-    outerlog += "willfocusiframe,";
-    document.querySelector("iframe").focus();
-    outerlog += "didfocusiframe,";
+    iframe.contentWindow.postMessage("focus", "*");
   } else if (e.data == "getlog") {
     iframe.contentWindow.postMessage("getlog", "*");
   } else {
     opener.postMessage(outerlog + e.data, "*");
   }
 };
 
 window.onload = function() {