Bug 1595597: Part 2 - Make test_postMessage_override Fission-compatible. r=mccr8
authorKris Maglione <maglione.k@gmail.com>
Mon, 11 Nov 2019 23:21:00 +0000
changeset 501535 656958c4362d1cc04e0eb37b02d13ee5f25524cb
parent 501534 aa6d07508d28b0f9be071a8736956e82648d4e9a
child 501536 9f2aadd2ad8fd807d8c152f8f5a9279fa9da70c1
push id36794
push useraciure@mozilla.com
push dateTue, 12 Nov 2019 09:43:07 +0000
treeherdermozilla-central@5f0b392beadb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1595597
milestone72.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 1595597: Part 2 - Make test_postMessage_override Fission-compatible. r=mccr8 Differential Revision: https://phabricator.services.mozilla.com/D52572
dom/tests/mochitest/whatwg/mochitest.ini
dom/tests/mochitest/whatwg/postMessage_override_helper.html
dom/tests/mochitest/whatwg/test_postMessage_override.html
--- a/dom/tests/mochitest/whatwg/mochitest.ini
+++ b/dom/tests/mochitest/whatwg/mochitest.ini
@@ -25,17 +25,16 @@ support-files =
 skip-if = toolkit == 'android' #bug 894914 - wrong data - got FAIL, expected message
 [test_postMessage_hash.html]
 [test_postMessage.html]
 [test_postMessage_idn.xhtml]
 [test_postMessage_joined.html]
 [test_postMessage_onOther.html]
 [test_postMessage_origin.xhtml]
 [test_postMessage_override.html]
-skip-if = fission # Fails intermittently under Fission.
 [test_postMessage_special.xhtml]
 [test_postMessage_structured_clone.html]
 [test_postMessage_throw.html]
 [test_postMessage_transfer.html]
 [test_postMessage_userpass.html]
 [test_bug500328.html]
 skip-if = true # bug 696306
 support-files = file_bug500328_1.html file_bug500328_2.html
--- a/dom/tests/mochitest/whatwg/postMessage_override_helper.html
+++ b/dom/tests/mochitest/whatwg/postMessage_override_helper.html
@@ -1,37 +1,32 @@
 <!DOCTYPE html>
 <html>
 <head>
   <title>Overriding postMessage and dispatchEvent bindings</title>
   <script type="application/javascript">
-    window.postMessage = function (evt)
-    {
+    window.postMessage = function (evt) {
       window.parent.postMessage("FAIL overridden postMessage called", "*");
     };
 
     var count = 0;
 
-    function receiveMessage(evt)
-    {
+    function receiveMessage(evt) {
       count++;
-      if (count == 1)
-      {
-        window.dispatchEvent = function(evt)
-        {
+      if (count == 2) {
+        window.dispatchEvent = function(evt) {
           window.parent.postMessage("FAIL", "*");
           throw "dispatchEvent threw";
         };
       }
 
       window.parent.postMessage(evt.data, "http://mochi.test:8888");
     }
-    
-    function setup()
-    {
+
+    function setup() {
       var target = document.getElementById("location");
       target.textContent = location.hostname + ":" + (location.port || 80);
     }
 
     window.addEventListener("message", receiveMessage);
 
     window.addEventListener("load", setup);
   </script>
--- a/dom/tests/mochitest/whatwg/test_postMessage_override.html
+++ b/dom/tests/mochitest/whatwg/test_postMessage_override.html
@@ -1,103 +1,47 @@
 <!DOCTYPE html>
 <html>
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage
 -->
 <head>
   <title>postMessage override test</title>
-  <script src="/tests/SimpleTest/SimpleTest.js"></script>        
+  <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 
 <iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_override_helper.html"></iframe>
 
 
 <pre id="test">
 <script class="testbody" type="application/javascript">
 /** Test for Bug 387706 **/
 
 SimpleTest.waitForExplicitFinish();
 
-var count = 0;
+async function run() {
+  function ping(win, msg) {
+    return new Promise(resolve => {
+      window.addEventListener("message", evt => {
+        is(evt.source, win, "Response should come from the correct window");
+        is(evt.data, msg, "Should get the correct response");
+        resolve();
+      }, { once: true });
 
-function test(callback)
-{
-  try
-  {
-    count++;
-    switch (count)
-    {
-      case 1:
-        window.frames[0].postMessage("PASS 1", "http://example.org:8000");
-        break;
-
-      case 2:
-        window.frames[0].postMessage("PASS 2", "http://example.org:8000");
-        break;
-  
-      default:
-        ok(false, "unexpected");
-    }
-  }
-  catch (e)
-  {
-    ok(false, "error running test " + count + ": " + e);
+      win.postMessage(msg, "http://example.org:8000");
+    });
   }
 
-  // Waiting for sent postMessage event to be processed...
-  setTimeout(function()
-  {
-    // Waiting for responding postMessage event to be processed...
-    setTimeout(function()
-    {
-      // We have our response!
-      callback();
-    }, 0);
-  }, 0);
-}
-
-function messageReceiver(evt)
-{
-  var expect;
-
-  switch (count)
-  {
-    case 1:
-      expect = "PASS 1";
-      break;
-
-    case 2:
-      expect = "PASS 2";
-      break;
-
-    default:
-      expect = "unexpected";
-      break;
-  }
-
-  is(evt.data, expect,
-     "uh-oh, we (" + count + ") didn't get the right postMessage!");
-}
-
-window.addEventListener("message", messageReceiver);
-
-function run()
-{
-  test(function()
-  {
-    test(function()
-    {
-      SimpleTest.finish();
-    }, 0);
-  });
+  await ping(frames[0], "PASS 1");
+  await ping(frames[0], "PASS 2");
+  SimpleTest.finish();
 }
 
 window.addEventListener("load", run);
 </script>
 </pre>
 </body>
 </html>