bug 1312161 - Ensure cleanup when match_about_blank test fails, r?kmag draft 1312161-m_a_b-intermittent
authorTomislav Jovanovic <tomica@gmail.com>
Sat, 22 Oct 2016 16:34:23 +0200
changeset 428313 3abf250b4713b6fd731cee88f1aa548a6567c457
parent 428241 5639a9f476d08f300c079117e61697f5026b6367
child 534717 895b9fd65410d9dfed0c919e8838b6b713533ea2
push id33291
push userbmo:tomica@gmail.com
push dateSun, 23 Oct 2016 03:56:34 +0000
reviewerskmag
bugs1312161
milestone52.0a1
bug 1312161 - Ensure cleanup when match_about_blank test fails, r?kmag MozReview-Commit-ID: HVy7Lm3CM6H
toolkit/components/extensions/test/mochitest/test_ext_contentscript_about_blank.html
--- a/toolkit/components/extensions/test/mochitest/test_ext_contentscript_about_blank.html
+++ b/toolkit/components/extensions/test/mochitest/test_ext_contentscript_about_blank.html
@@ -64,23 +64,31 @@ add_task(function* test_contentscript_ab
       browser.test.sendMessage(`${script}:${kind}`);
     });
   }
 
   const PATH = "tests/toolkit/components/extensions/test/mochitest/file_with_about_blank.html";
   const extension = ExtensionTestUtils.loadExtension({manifest, files, background});
   yield extension.startup();
 
+  let win;
+  SimpleTest.registerCleanupFunction(() => {
+    if (win && !win.closed) {
+      win.close();
+    }
+    return extension.unload();
+  });
+
   let count = 0;
   extension.onMessage("script", script => {
     info(`script ran: ${script}`);
     count++;
   });
 
-  let win = window.open("http://example.com/" + PATH);
+  win = window.open("http://example.com/" + PATH);
   yield Promise.all([
     extension.awaitMessage("all:top"),
     extension.awaitMessage("all:about:blank"),
     extension.awaitMessage("all:about:srcdoc"),
   ]);
   is(count, 3, "exactly 3 scripts ran");
   win.close();
 
@@ -103,15 +111,13 @@ add_task(function* test_contentscript_ab
   let a_b = win.document.getElementById("a_b");
   style = a_b.contentWindow.getComputedStyle(a_b.contentDocument.body);
   is(style.color, "rgb(255, 0, 0)", "about:blank iframe text color is red");
   is(style.backgroundColor, "transparent", "about:blank iframe background is transparent");
   is(style.textAlign, "right", "about:blank text is right-aligned");
 
   is(count, 10, "exactly 7 more scripts ran");
   win.close();
-
-  yield extension.unload();
 });
 </script>
 
 </body>
 </html>