Bug 1596315, use SpecialPowers.spawn instead of ContentTask.spawn so the content steps can run in a child iframe process, enable test for fission, r=nhnt11
authorNeil Deakin <neil@mozilla.com>
Mon, 18 Nov 2019 14:29:31 +0000
changeset 502415 abc0f2a2d5c6e62b3665de6dcaabd03f427fd623
parent 502414 ca19f048cd8dadec73b8214cbc4e8b5455f44c7b
child 502416 9afdb269ce04e3673bddf950f96a2b7f1306b55a
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnhnt11
bugs1596315
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 1596315, use SpecialPowers.spawn instead of ContentTask.spawn so the content steps can run in a child iframe process, enable test for fission, r=nhnt11 Differential Revision: https://phabricator.services.mozilla.com/D53019
browser/base/content/test/about/browser.ini
browser/base/content/test/about/browser_aboutCertError.js
browser/base/content/test/about/head.js
--- a/browser/base/content/test/about/browser.ini
+++ b/browser/base/content/test/about/browser.ini
@@ -5,17 +5,16 @@ support-files =
   searchSuggestionEngine.sjs
   searchSuggestionEngine.xml
   POSTSearchEngine.xml
   dummy_page.html
 prefs =
   browser.newtabpage.activity-stream.improvesearch.handoffToAwesomebar=false
 
 [browser_aboutCertError.js]
-skip-if = fission
 [browser_aboutCertError_clockSkew.js]
 [browser_aboutCertError_exception.js]
 [browser_aboutCertError_mitm.js]
 [browser_aboutCertError_noSubjectAltName.js]
 [browser_aboutHome_search_POST.js]
 [browser_aboutHome_search_composing.js]
 [browser_aboutHome_search_searchbar.js]
 [browser_aboutHome_search_suggestion.js]
--- a/browser/base/content/test/about/browser_aboutCertError.js
+++ b/browser/base/content/test/about/browser_aboutCertError.js
@@ -32,26 +32,24 @@ add_task(async function checkReturnToAbo
 
     // Populate the shistory entries manually, since it happens asynchronously
     // and the following tests will be too soon otherwise.
     await TabStateFlusher.flush(browser);
     let { entries } = JSON.parse(SessionStore.getTabState(tab));
     is(entries.length, 1, "there is one shistory entry");
 
     info("Clicking the go back button on about:certerror");
-    await ContentTask.spawn(browser, { frame: useFrame }, async function({
-      frame,
-    }) {
-      let doc = frame
-        ? content.document.querySelector("iframe").contentDocument
-        : content.document;
-
-      let returnButton = doc.getElementById("returnButton");
-      if (!frame) {
-        is(
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
+    await SpecialPowers.spawn(bc, [useFrame], async function(subFrame) {
+      let returnButton = content.document.getElementById("returnButton");
+      if (!subFrame) {
+        Assert.equal(
           returnButton.getAttribute("autofocus"),
           "true",
           "returnButton has autofocus"
         );
       }
       // Note that going back to about:newtab might cause a process flip, if
       // the browser is configured to run about:newtab in its own special
       // content process.
@@ -105,27 +103,31 @@ add_task(async function checkReturnToPre
 
     // Populate the shistory entries manually, since it happens asynchronously
     // and the following tests will be too soon otherwise.
     await TabStateFlusher.flush(browser);
     let { entries } = JSON.parse(SessionStore.getTabState(tab));
     is(entries.length, 2, "there are two shistory entries");
 
     info("Clicking the go back button on about:certerror");
-    await ContentTask.spawn(browser, { frame: useFrame }, async function({
-      frame,
-    }) {
-      let doc = frame
-        ? content.document.querySelector("iframe").contentDocument
-        : content.document;
-      let returnButton = doc.getElementById("returnButton");
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
+
+    let pageShownPromise = BrowserTestUtils.waitForContentEvent(
+      browser,
+      "pageshow",
+      true
+    );
+    await SpecialPowers.spawn(bc, [useFrame], async function(subFrame) {
+      let returnButton = content.document.getElementById("returnButton");
       returnButton.click();
-
-      await ContentTaskUtils.waitForEvent(this, "pageshow", true);
     });
+    await pageShownPromise;
 
     is(browser.webNavigation.canGoBack, false, "!webNavigation.canGoBack");
     is(browser.webNavigation.canGoForward, true, "webNavigation.canGoForward");
     is(gBrowser.currentURI.spec, GOOD_PAGE, "Went back");
 
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
   }
 });
@@ -146,85 +148,74 @@ add_task(async function checkAppBuildIDI
 add_task(async function checkAdvancedDetails() {
   info(
     "Loading a bad cert page and verifying the main error and advanced details section"
   );
   for (let useFrame of [false, true]) {
     let tab = await openErrorPage(BAD_CERT, useFrame);
     let browser = tab.linkedBrowser;
 
-    let message = await ContentTask.spawn(
-      browser,
-      { frame: useFrame },
-      async function({ frame }) {
-        let doc = frame
-          ? content.document.querySelector("iframe").contentDocument
-          : content.document;
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
 
-        let shortDescText = doc.getElementById("errorShortDescText");
-        info("Main error text: " + shortDescText.textContent);
-        ok(
-          shortDescText.textContent.includes("expired.example.com"),
-          "Should list hostname in error message."
-        );
+    let message = await SpecialPowers.spawn(bc, [], async function() {
+      let doc = content.document;
+      let shortDescText = doc.getElementById("errorShortDescText");
+      Assert.ok(
+        shortDescText.textContent.includes("expired.example.com"),
+        "Should list hostname in error message."
+      );
 
-        let exceptionButton = doc.getElementById("exceptionDialogButton");
-        ok(
-          !exceptionButton.disabled,
-          "Exception button is not disabled by default."
-        );
+      let exceptionButton = doc.getElementById("exceptionDialogButton");
+      Assert.ok(
+        !exceptionButton.disabled,
+        "Exception button is not disabled by default."
+      );
 
-        let advancedButton = doc.getElementById("advancedButton");
-        advancedButton.click();
+      let advancedButton = doc.getElementById("advancedButton");
+      advancedButton.click();
 
-        // Wait until fluent sets the errorCode inner text.
-        let el;
-        await ContentTaskUtils.waitForCondition(() => {
-          el = doc.getElementById("errorCode");
-          return el.textContent != "";
-        }, "error code has been set inside the advanced button panel");
+      // Wait until fluent sets the errorCode inner text.
+      let el;
+      await ContentTaskUtils.waitForCondition(() => {
+        el = doc.getElementById("errorCode");
+        return el.textContent != "";
+      }, "error code has been set inside the advanced button panel");
 
-        return { textContent: el.textContent, tagName: el.tagName };
-      }
-    );
+      return { textContent: el.textContent, tagName: el.tagName };
+    });
     is(
       message.textContent,
       "SEC_ERROR_EXPIRED_CERTIFICATE",
       "Correct error message found"
     );
     is(message.tagName, "a", "Error message is a link");
 
-    message = await ContentTask.spawn(
-      browser,
-      { frame: useFrame },
-      async function({ frame }) {
-        let win = frame
-          ? content.document.querySelector("iframe").contentWindow
-          : content;
-        let doc = win.document;
-
-        let errorCode = doc.getElementById("errorCode");
-        errorCode.click();
-        let div = doc.getElementById("certificateErrorDebugInformation");
-        let text = doc.getElementById("certificateErrorText");
+    message = await SpecialPowers.spawn(bc, [], async function() {
+      let doc = content.document;
+      let errorCode = doc.getElementById("errorCode");
+      errorCode.click();
+      let div = doc.getElementById("certificateErrorDebugInformation");
+      let text = doc.getElementById("certificateErrorText");
 
-        let serhelper = Cc[
-          "@mozilla.org/network/serialization-helper;1"
-        ].getService(Ci.nsISerializationHelper);
-        let serializable = win.docShell.failedChannel.securityInfo
-          .QueryInterface(Ci.nsITransportSecurityInfo)
-          .QueryInterface(Ci.nsISerializable);
-        let serializedSecurityInfo = serhelper.serializeToString(serializable);
-        return {
-          divDisplay: content.getComputedStyle(div).display,
-          text: text.textContent,
-          securityInfoAsString: serializedSecurityInfo,
-        };
-      }
-    );
+      let serhelper = Cc[
+        "@mozilla.org/network/serialization-helper;1"
+      ].getService(Ci.nsISerializationHelper);
+      let serializable = content.docShell.failedChannel.securityInfo
+        .QueryInterface(Ci.nsITransportSecurityInfo)
+        .QueryInterface(Ci.nsISerializable);
+      let serializedSecurityInfo = serhelper.serializeToString(serializable);
+      return {
+        divDisplay: content.getComputedStyle(div).display,
+        text: text.textContent,
+        securityInfoAsString: serializedSecurityInfo,
+      };
+    });
     isnot(message.divDisplay, "none", "Debug information is visible");
     ok(message.text.includes(BAD_CERT), "Correct URL found");
     ok(
       message.text.includes("Certificate has expired"),
       "Correct error message found"
     );
     ok(
       message.text.includes("HTTP Strict Transport Security: false"),
@@ -244,83 +235,74 @@ add_task(async function checkAdvancedDet
 add_task(async function checkAdvancedDetailsForHSTS() {
   info(
     "Loading a bad STS cert page and verifying the advanced details section"
   );
   for (let useFrame of [false, true]) {
     let tab = await openErrorPage(BAD_STS_CERT, useFrame);
     let browser = tab.linkedBrowser;
 
-    let message = await ContentTask.spawn(
-      browser,
-      { frame: useFrame },
-      async function({ frame }) {
-        let doc = frame
-          ? content.document.querySelector("iframe").contentDocument
-          : content.document;
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
 
-        let advancedButton = doc.getElementById("advancedButton");
-        advancedButton.click();
+    let message = await SpecialPowers.spawn(bc, [], async function() {
+      let doc = content.document;
+      let advancedButton = doc.getElementById("advancedButton");
+      advancedButton.click();
 
-        // Wait until fluent sets the errorCode inner text.
-        let ec;
-        await ContentTaskUtils.waitForCondition(() => {
-          ec = doc.getElementById("errorCode");
-          return ec.textContent != "";
-        }, "error code has been set inside the advanced button panel");
+      // Wait until fluent sets the errorCode inner text.
+      let ec;
+      await ContentTaskUtils.waitForCondition(() => {
+        ec = doc.getElementById("errorCode");
+        return ec.textContent != "";
+      }, "error code has been set inside the advanced button panel");
 
-        let cdl = doc.getElementById("cert_domain_link");
-        return {
-          ecTextContent: ec.textContent,
-          ecTagName: ec.tagName,
-          cdlTextContent: cdl.textContent,
-          cdlTagName: cdl.tagName,
-        };
-      }
-    );
+      let cdl = doc.getElementById("cert_domain_link");
+      return {
+        ecTextContent: ec.textContent,
+        ecTagName: ec.tagName,
+        cdlTextContent: cdl.textContent,
+        cdlTagName: cdl.tagName,
+      };
+    });
 
     const badStsUri = Services.io.newURI(BAD_STS_CERT);
     is(
       message.ecTextContent,
       "SSL_ERROR_BAD_CERT_DOMAIN",
       "Correct error message found"
     );
     is(message.ecTagName, "a", "Error message is a link");
     const url = badStsUri.prePath.slice(badStsUri.prePath.indexOf(".") + 1);
     is(message.cdlTextContent, url, "Correct cert_domain_link contents found");
     is(message.cdlTagName, "a", "cert_domain_link is a link");
 
-    message = await ContentTask.spawn(
-      browser,
-      { frame: useFrame },
-      async function({ frame }) {
-        let win = frame
-          ? content.document.querySelector("iframe").contentWindow
-          : content;
-        let doc = win.document;
+    message = await SpecialPowers.spawn(bc, [], async function() {
+      let doc = content.document;
 
-        let errorCode = doc.getElementById("errorCode");
-        errorCode.click();
-        let div = doc.getElementById("certificateErrorDebugInformation");
-        let text = doc.getElementById("certificateErrorText");
+      let errorCode = doc.getElementById("errorCode");
+      errorCode.click();
+      let div = doc.getElementById("certificateErrorDebugInformation");
+      let text = doc.getElementById("certificateErrorText");
 
-        let serhelper = Cc[
-          "@mozilla.org/network/serialization-helper;1"
-        ].getService(Ci.nsISerializationHelper);
-        let serializable = win.docShell.failedChannel.securityInfo
-          .QueryInterface(Ci.nsITransportSecurityInfo)
-          .QueryInterface(Ci.nsISerializable);
-        let serializedSecurityInfo = serhelper.serializeToString(serializable);
-        return {
-          divDisplay: content.getComputedStyle(div).display,
-          text: text.textContent,
-          securityInfoAsString: serializedSecurityInfo,
-        };
-      }
-    );
+      let serhelper = Cc[
+        "@mozilla.org/network/serialization-helper;1"
+      ].getService(Ci.nsISerializationHelper);
+      let serializable = content.docShell.failedChannel.securityInfo
+        .QueryInterface(Ci.nsITransportSecurityInfo)
+        .QueryInterface(Ci.nsISerializable);
+      let serializedSecurityInfo = serhelper.serializeToString(serializable);
+      return {
+        divDisplay: content.getComputedStyle(div).display,
+        text: text.textContent,
+        securityInfoAsString: serializedSecurityInfo,
+      };
+    });
     isnot(message.divDisplay, "none", "Debug information is visible");
     ok(message.text.includes(badStsUri.spec), "Correct URL found");
     ok(
       message.text.includes(
         "requested domain name does not match the server\u2019s certificate"
       ),
       "Correct error message found"
     );
@@ -342,65 +324,57 @@ add_task(async function checkAdvancedDet
 add_task(async function checkUnknownIssuerLearnMoreLink() {
   info(
     "Loading a cert error for self-signed pages and checking the correct link is shown"
   );
   for (let useFrame of [false, true]) {
     let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
     let browser = tab.linkedBrowser;
 
-    let href = await ContentTask.spawn(
-      browser,
-      { frame: useFrame },
-      async function({ frame }) {
-        let doc = frame
-          ? content.document.querySelector("iframe").contentDocument
-          : content.document;
-        let learnMoreLink = doc.getElementById("learnMoreLink");
-        return learnMoreLink.href;
-      }
-    );
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
+
+    let href = await SpecialPowers.spawn(bc, [], async function() {
+      let learnMoreLink = content.document.getElementById("learnMoreLink");
+      return learnMoreLink.href;
+    });
     ok(href.endsWith("security-error"), "security-error in the Learn More URL");
 
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
   }
 });
 
 add_task(async function checkCautionClass() {
   info("Checking that are potentially more dangerous get a 'caution' class");
   for (let useFrame of [false, true]) {
     let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
     let browser = tab.linkedBrowser;
 
-    await ContentTask.spawn(browser, { frame: useFrame }, async function({
-      frame,
-    }) {
-      let doc = frame
-        ? content.document.querySelector("iframe").contentDocument
-        : content.document;
-      is(
-        doc.body.classList.contains("caution"),
-        !frame,
-        `Cert error body has ${frame ? "no" : ""} caution class`
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
+
+    await SpecialPowers.spawn(bc, [useFrame], async function(subFrame) {
+      Assert.equal(
+        content.document.body.classList.contains("caution"),
+        !subFrame,
+        `Cert error body has ${subFrame ? "no" : ""} caution class`
       );
     });
 
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
 
     tab = await openErrorPage(BAD_STS_CERT, useFrame);
-    browser = tab.linkedBrowser;
-
-    await ContentTask.spawn(browser, { frame: useFrame }, async function({
-      frame,
-    }) {
-      let doc = frame
-        ? content.document.querySelector("iframe").contentDocument
-        : content.document;
-      ok(
-        !doc.body.classList.contains("caution"),
+    bc = tab.linkedBrowser.browsingContext;
+    await SpecialPowers.spawn(bc, [], async function() {
+      Assert.ok(
+        !content.document.body.classList.contains("caution"),
         "Cert error body has no caution class"
       );
     });
 
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
   }
 });
 
@@ -412,63 +386,62 @@ add_task(async function checkViewCertifi
   for (let useFrame of [true, false]) {
     if (useFrame) {
       // Bug #1573502
       continue;
     }
     let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
     let browser = tab.linkedBrowser;
 
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
+
     let loaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
-    await ContentTask.spawn(browser, { frame: useFrame }, async function({
-      frame,
-    }) {
-      let doc = frame
-        ? content.document.querySelector("iframe").contentDocument
-        : content.document;
-      let viewCertificate = doc.getElementById("viewCertificate");
+    await SpecialPowers.spawn(bc, [], async function() {
+      let viewCertificate = content.document.getElementById("viewCertificate");
       viewCertificate.click();
     });
     await loaded;
 
     let spec = gBrowser.selectedTab.linkedBrowser.documentURI.spec;
     Assert.ok(
       spec.startsWith("about:certificate"),
       "about:certificate is the new opened tab"
     );
 
-    await ContentTask.spawn(
+    await SpecialPowers.spawn(
       gBrowser.selectedTab.linkedBrowser,
-      null,
+      [],
       async function() {
         let doc = content.document;
-
         let certificateSection = await ContentTaskUtils.waitForCondition(() => {
           return doc.querySelector("certificate-section");
         }, "Certificate section found");
 
         let infoGroup = certificateSection.shadowRoot.querySelector(
           "info-group"
         );
         Assert.ok(infoGroup, "infoGroup found");
 
         let items = infoGroup.shadowRoot.querySelectorAll("info-item");
         let commonnameID = items[items.length - 1].shadowRoot
           .querySelector("label")
           .getAttribute("data-l10n-id");
-        is(
+        Assert.equal(
           commonnameID,
           "certificate-viewer-common-name",
           "The correct item was selected"
         );
 
         let commonnameValue = items[items.length - 1].shadowRoot.querySelector(
           ".info"
         ).textContent;
-        is(
+        Assert.equal(
           commonnameValue,
           "self-signed.example.com",
           "Shows the correct certificate in the page"
         );
       }
     );
     BrowserTestUtils.removeTab(gBrowser.selectedTab); // closes about:certificate
     BrowserTestUtils.removeTab(gBrowser.selectedTab);
@@ -478,27 +451,25 @@ add_task(async function checkViewCertifi
 add_task(async function checkBadStsCertHeadline() {
   info(
     "Loading a bad sts cert error page and checking that the correct headline is shown"
   );
   for (let useFrame of [false, true]) {
     let tab = await openErrorPage(BAD_CERT, useFrame);
     let browser = tab.linkedBrowser;
 
-    let titleContent = await ContentTask.spawn(
-      browser,
-      { frame: useFrame },
-      async function({ frame }) {
-        let doc = frame
-          ? content.document.querySelector("iframe").contentDocument
-          : content.document;
-        let titleText = doc.querySelector(".title-text");
-        return titleText.textContent;
-      }
-    );
+    let bc = browser.browsingContext;
+    if (useFrame) {
+      bc = bc.getChildren()[0];
+    }
+
+    let titleContent = await SpecialPowers.spawn(bc, [], async function() {
+      let titleText = content.document.querySelector(".title-text");
+      return titleText.textContent;
+    });
     if (useFrame) {
       ok(
         titleContent.endsWith("Security Issue"),
         "Did Not Connect: Potential Security Issue"
       );
     } else {
       ok(
         titleContent.endsWith("Risk Ahead"),
@@ -513,33 +484,33 @@ add_task(async function checkSandboxedIf
   info(
     "Loading a bad sts cert error in a sandboxed iframe and check that the correct headline is shown"
   );
   let useFrame = true;
   let sandboxed = true;
   let tab = await openErrorPage(BAD_CERT, useFrame, sandboxed);
   let browser = tab.linkedBrowser;
 
-  await ContentTask.spawn(browser, {}, async function() {
-    let doc = content.document.querySelector("iframe").contentDocument;
-
+  let bc = browser.browsingContext.getChildren()[0];
+  await SpecialPowers.spawn(bc, [], async function() {
+    let doc = content.document;
     let titleText = doc.querySelector(".title-text");
-    ok(
+    Assert.ok(
       titleText.textContent.endsWith("Security Issue"),
       "Title shows Did Not Connect: Potential Security Issue"
     );
 
     // Wait until fluent sets the errorCode inner text.
     let el;
     await ContentTaskUtils.waitForCondition(() => {
       el = doc.getElementById("errorCode");
       return el.textContent != "";
     }, "error code has been set inside the advanced button panel");
 
-    is(
+    Assert.equal(
       el.textContent,
       "SEC_ERROR_EXPIRED_CERTIFICATE",
       "Correct error message found"
     );
-    is(el.tagName, "a", "Error message is a link");
+    Assert.equal(el.tagName, "a", "Error message is a link");
   });
   BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
--- a/browser/base/content/test/about/head.js
+++ b/browser/base/content/test/about/head.js
@@ -29,40 +29,37 @@ function getPEMString(cert) {
   var wrapped = derb64.replace(/(\S{64}(?!$))/g, "$1\r\n");
   return (
     "-----BEGIN CERTIFICATE-----\r\n" +
     wrapped +
     "\r\n-----END CERTIFICATE-----\r\n"
   );
 }
 
-function injectErrorPageFrame(tab, src, sandboxed) {
-  return ContentTask.spawn(
+async function injectErrorPageFrame(tab, src, sandboxed) {
+  let loadedPromise = BrowserTestUtils.browserLoaded(
     tab.linkedBrowser,
-    { frameSrc: src, frameSandboxed: sandboxed },
-    async function({ frameSrc, frameSandboxed }) {
-      let loaded = ContentTaskUtils.waitForEvent(
-        content.wrappedJSObject,
-        "DOMFrameContentLoaded"
-      );
-      let iframe = content.document.createElement("iframe");
-      iframe.src = frameSrc;
-      if (frameSandboxed) {
-        iframe.setAttribute("sandbox", "allow-scripts");
-      }
-      content.document.body.appendChild(iframe);
-      await loaded;
-      // We will have race conditions when accessing the frame content after setting a src,
-      // so we can't wait for AboutNetErrorLoad. Let's wait for the certerror class to
-      // appear instead (which should happen at the same time as AboutNetErrorLoad).
-      await ContentTaskUtils.waitForCondition(() =>
-        iframe.contentDocument.body.classList.contains("certerror")
-      );
+    true,
+    null,
+    true
+  );
+
+  await SpecialPowers.spawn(tab.linkedBrowser, [src, sandboxed], async function(
+    frameSrc,
+    frameSandboxed
+  ) {
+    let iframe = content.document.createElement("iframe");
+    iframe.src = frameSrc;
+    if (frameSandboxed) {
+      iframe.setAttribute("sandbox", "allow-scripts");
     }
-  );
+    content.document.body.appendChild(iframe);
+  });
+
+  await loadedPromise;
 }
 
 async function openErrorPage(src, useFrame, sandboxed) {
   let dummyPage =
     getRootDirectory(gTestPath).replace(
       "chrome://mochitests/content",
       "https://example.com"
     ) + "dummy_page.html";