Bug 1317900 - address intermittent failure in test_ext_unload_frame.html r=aswan
authorRob Wu <rob@robwu.nl>
Wed, 23 Aug 2017 16:31:14 +0200
changeset 428232 15cfcee45b87afce49e31eed12c11474e4a7b38d
parent 428231 1518f8954ba2c76f68518c53674399145c8f375b
child 428233 d8a45e6819f5f12abd7e4bdec94030a8e7a88f2a
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1317900
milestone57.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 1317900 - address intermittent failure in test_ext_unload_frame.html r=aswan MozReview-Commit-ID: 8ySNL64KLmO
toolkit/components/extensions/test/mochitest/test_ext_unload_frame.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_unload_frame.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_unload_frame.html
@@ -55,18 +55,29 @@ function connect_background() {
       browser.test.assertFalse(disconnected, "Should get message before disconnect");
       browser.test.assertEq("from frame", msg, "Expected message from frame");
     });
 
     port.postMessage("reply to closing frame");
   });
 }
 function connect_contentScript(testType) {
+  let isUnloading = false;
+  addEventListener("pagehide", () => { isUnloading = true; }, {once: true});
+
   let port = browser.runtime.connect({name: "port from frame"});
   port.onMessage.addListener(msg => {
+    // The background page sends a reply as soon as we call runtime.connect().
+    // It is possible that the reply reaches this frame before the
+    // window.close() request has been processed.
+    if (!isUnloading) {
+      browser.test.log(`Ignorting unexpected reply ("${msg}") because the page is not being unloaded.`);
+      return;
+    }
+
     // The frame has been removed, so we should not get a reply.
     browser.test.fail(`Unexpected reply: ${msg}`);
   });
   port.postMessage("from frame");
 
   // Removing the frame or window should disconnect the port.
   if (testType == "frame") {
     frameElement.remove();