bug 1688703 - avoid leaks in browser_openTabAndSendCertInfo.js r? draft
authorDana Keeler <dkeeler@mozilla.com>
Thu, 15 Apr 2021 13:41:05 -0700
changeset 3667560 3a1688e7bbc9bf6c6fa7398743584f8733269e6f
parent 3667559 0e771652aeedfe05d1eafd2136366b1d7ee42b6f
child 3667561 c11d7ae1a96c8a8f24a0953f5c79b94a5b05b31f
push id683111
push userdkeeler@mozilla.com
push dateMon, 19 Apr 2021 16:18:48 +0000
treeherdertry@c11d7ae1a96c [default view] [failures only]
bugs1688703
milestone89.0a1
bug 1688703 - avoid leaks in browser_openTabAndSendCertInfo.js r?
toolkit/components/certviewer/tests/browser/browser_openTabAndSendCertInfo.js
--- a/toolkit/components/certviewer/tests/browser/browser_openTabAndSendCertInfo.js
+++ b/toolkit/components/certviewer/tests/browser/browser_openTabAndSendCertInfo.js
@@ -26,23 +26,29 @@ function checkSpec(spec) {
 }
 
 function checksCertTab(tabsCount) {
   Assert.equal(gBrowser.tabs.length, tabsCount + 1, "New tab was opened");
   let spec = gBrowser.tabs[tabsCount].linkedBrowser.documentURI.spec;
   checkSpec(spec);
 }
 
-async function checkCertChain() {
-  await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function() {
+async function checkCertChain(browser) {
+  await SpecialPowers.spawn(browser, [], async function() {
     let certificateTabs;
     await ContentTaskUtils.waitForCondition(() => {
-      certificateTabs = content.document
-        .querySelector("certificate-section")
-        .shadowRoot.querySelectorAll(".certificate-tab");
+      let certificateSection = content.document.querySelector(
+        "certificate-section"
+      );
+      if (!certificateSection) {
+        return false;
+      }
+      certificateTabs = certificateSection.shadowRoot.querySelectorAll(
+        ".certificate-tab"
+      );
       return certificateTabs.length;
     }, "Found certificate tabs.");
 
     Assert.greaterOrEqual(
       certificateTabs.length,
       1,
       "Certificate chain tabs shown"
     );
@@ -100,16 +106,18 @@ add_task(async function openFromPopUp() 
     await BrowserTestUtils.browserLoaded(browser, false, spec =>
       spec.startsWith("about:certificate")
     );
   }
 
   let spec = browser.currentURI.spec;
   checkSpec(spec);
 
+  await checkCertChain(browser);
+
   await BrowserTestUtils.closeWindow(topWin); // closes about:certificate
   win.document.getElementById("download_cert").cancelDialog();
   await BrowserTestUtils.windowClosed(win);
 });
 
 add_task(async function testBadCert() {
   info("Testing bad cert");
 
@@ -134,16 +142,17 @@ add_task(async function testBadCert() {
       false,
       "viewCertificate should be clickable"
     );
 
     viewCertificate.click();
   });
   await loaded;
   checksCertTab(tabsCount);
+  await checkCertChain(gBrowser.selectedBrowser);
 
   gBrowser.removeCurrentTab(); // closes about:certificate
   gBrowser.removeCurrentTab(); // closes https://expired.example.com/
 });
 
 add_task(async function testBadCertIframe() {
   info("Testing bad cert in an iframe");
 
@@ -169,16 +178,17 @@ add_task(async function testBadCertIfram
       false,
       "viewCertificate should be clickable"
     );
 
     viewCertificate.click();
   });
   await loaded;
   checksCertTab(tabsCount);
+  await checkCertChain(gBrowser.selectedBrowser);
 
   gBrowser.removeCurrentTab(); // closes about:certificate
   gBrowser.removeCurrentTab(); // closes https://expired.example.com/
 });
 
 add_task(async function testGoodCert() {
   info("Testing page info");
   let url = "https://example.com/";
@@ -202,16 +212,17 @@ add_task(async function testGoodCert() {
       () => BrowserTestUtils.is_visible(viewCertButton),
       "view cert button should be visible."
     );
 
     let loaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
     checkAndClickButton(pageInfo.document, "security-view-cert");
     await loaded;
 
+    await checkCertChain(gBrowser.selectedBrowser);
     pageInfo.close();
   });
   checksCertTab(tabsCount);
 
   gBrowser.removeCurrentTab(); // closes about:certificate
 });
 
 add_task(async function testPreferencesCert() {
@@ -251,12 +262,12 @@ add_task(async function testPreferencesC
     let viewButton = doc.getElementById("mine_viewButton");
     Assert.equal(viewButton.disabled, false, "Should enable view button");
 
     let loaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
     viewButton.click();
     await loaded;
 
     checksCertTab(tabsCount);
-    await checkCertChain();
+    await checkCertChain(gBrowser.selectedBrowser);
   });
   gBrowser.removeCurrentTab(); // closes about:certificate
 });