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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Neil Deakin 2019-11-18 14:29:31 +00:00
Родитель a1ff10a14a
Коммит 72f98da7dc
3 изменённых файлов: 175 добавлений и 208 удалений

Просмотреть файл

@ -10,7 +10,6 @@ prefs =
browser.newtabpage.activity-stream.improvesearch.handoffToAwesomebar=false browser.newtabpage.activity-stream.improvesearch.handoffToAwesomebar=false
[browser_aboutCertError.js] [browser_aboutCertError.js]
skip-if = fission
[browser_aboutCertError_clockSkew.js] [browser_aboutCertError_clockSkew.js]
[browser_aboutCertError_exception.js] [browser_aboutCertError_exception.js]
[browser_aboutCertError_mitm.js] [browser_aboutCertError_mitm.js]

Просмотреть файл

@ -37,16 +37,14 @@ add_task(async function checkReturnToAboutHome() {
is(entries.length, 1, "there is one shistory entry"); is(entries.length, 1, "there is one shistory entry");
info("Clicking the go back button on about:certerror"); info("Clicking the go back button on about:certerror");
await ContentTask.spawn(browser, { frame: useFrame }, async function({ let bc = browser.browsingContext;
frame, if (useFrame) {
}) { bc = bc.getChildren()[0];
let doc = frame }
? content.document.querySelector("iframe").contentDocument await SpecialPowers.spawn(bc, [useFrame], async function(subFrame) {
: content.document; let returnButton = content.document.getElementById("returnButton");
if (!subFrame) {
let returnButton = doc.getElementById("returnButton"); Assert.equal(
if (!frame) {
is(
returnButton.getAttribute("autofocus"), returnButton.getAttribute("autofocus"),
"true", "true",
"returnButton has autofocus" "returnButton has autofocus"
@ -110,17 +108,21 @@ add_task(async function checkReturnToPreviousPage() {
is(entries.length, 2, "there are two shistory entries"); is(entries.length, 2, "there are two shistory entries");
info("Clicking the go back button on about:certerror"); info("Clicking the go back button on about:certerror");
await ContentTask.spawn(browser, { frame: useFrame }, async function({ let bc = browser.browsingContext;
frame, if (useFrame) {
}) { bc = bc.getChildren()[0];
let doc = frame }
? content.document.querySelector("iframe").contentDocument
: content.document;
let returnButton = doc.getElementById("returnButton");
returnButton.click();
await ContentTaskUtils.waitForEvent(this, "pageshow", true); let pageShownPromise = BrowserTestUtils.waitForContentEvent(
browser,
"pageshow",
true
);
await SpecialPowers.spawn(bc, [useFrame], async function(subFrame) {
let returnButton = content.document.getElementById("returnButton");
returnButton.click();
}); });
await pageShownPromise;
is(browser.webNavigation.canGoBack, false, "!webNavigation.canGoBack"); is(browser.webNavigation.canGoBack, false, "!webNavigation.canGoBack");
is(browser.webNavigation.canGoForward, true, "webNavigation.canGoForward"); is(browser.webNavigation.canGoForward, true, "webNavigation.canGoForward");
@ -151,40 +153,37 @@ add_task(async function checkAdvancedDetails() {
let tab = await openErrorPage(BAD_CERT, useFrame); let tab = await openErrorPage(BAD_CERT, useFrame);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
let message = await ContentTask.spawn( let bc = browser.browsingContext;
browser, if (useFrame) {
{ frame: useFrame }, bc = bc.getChildren()[0];
async function({ frame }) { }
let doc = frame
? content.document.querySelector("iframe").contentDocument
: content.document;
let shortDescText = doc.getElementById("errorShortDescText"); let message = await SpecialPowers.spawn(bc, [], async function() {
info("Main error text: " + shortDescText.textContent); let doc = content.document;
ok( let shortDescText = doc.getElementById("errorShortDescText");
shortDescText.textContent.includes("expired.example.com"), Assert.ok(
"Should list hostname in error message." shortDescText.textContent.includes("expired.example.com"),
); "Should list hostname in error message."
);
let exceptionButton = doc.getElementById("exceptionDialogButton"); let exceptionButton = doc.getElementById("exceptionDialogButton");
ok( Assert.ok(
!exceptionButton.disabled, !exceptionButton.disabled,
"Exception button is not disabled by default." "Exception button is not disabled by default."
); );
let advancedButton = doc.getElementById("advancedButton"); let advancedButton = doc.getElementById("advancedButton");
advancedButton.click(); advancedButton.click();
// Wait until fluent sets the errorCode inner text. // Wait until fluent sets the errorCode inner text.
let el; let el;
await ContentTaskUtils.waitForCondition(() => { await ContentTaskUtils.waitForCondition(() => {
el = doc.getElementById("errorCode"); el = doc.getElementById("errorCode");
return el.textContent != ""; return el.textContent != "";
}, "error code has been set inside the advanced button panel"); }, "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( is(
message.textContent, message.textContent,
"SEC_ERROR_EXPIRED_CERTIFICATE", "SEC_ERROR_EXPIRED_CERTIFICATE",
@ -192,34 +191,26 @@ add_task(async function checkAdvancedDetails() {
); );
is(message.tagName, "a", "Error message is a link"); is(message.tagName, "a", "Error message is a link");
message = await ContentTask.spawn( message = await SpecialPowers.spawn(bc, [], async function() {
browser, let doc = content.document;
{ frame: useFrame }, let errorCode = doc.getElementById("errorCode");
async function({ frame }) { errorCode.click();
let win = frame let div = doc.getElementById("certificateErrorDebugInformation");
? content.document.querySelector("iframe").contentWindow let text = doc.getElementById("certificateErrorText");
: content;
let doc = win.document;
let errorCode = doc.getElementById("errorCode"); let serhelper = Cc[
errorCode.click(); "@mozilla.org/network/serialization-helper;1"
let div = doc.getElementById("certificateErrorDebugInformation"); ].getService(Ci.nsISerializationHelper);
let text = doc.getElementById("certificateErrorText"); let serializable = content.docShell.failedChannel.securityInfo
.QueryInterface(Ci.nsITransportSecurityInfo)
let serhelper = Cc[ .QueryInterface(Ci.nsISerializable);
"@mozilla.org/network/serialization-helper;1" let serializedSecurityInfo = serhelper.serializeToString(serializable);
].getService(Ci.nsISerializationHelper); return {
let serializable = win.docShell.failedChannel.securityInfo divDisplay: content.getComputedStyle(div).display,
.QueryInterface(Ci.nsITransportSecurityInfo) text: text.textContent,
.QueryInterface(Ci.nsISerializable); securityInfoAsString: serializedSecurityInfo,
let serializedSecurityInfo = serhelper.serializeToString(serializable); };
return { });
divDisplay: content.getComputedStyle(div).display,
text: text.textContent,
securityInfoAsString: serializedSecurityInfo,
};
}
);
isnot(message.divDisplay, "none", "Debug information is visible"); isnot(message.divDisplay, "none", "Debug information is visible");
ok(message.text.includes(BAD_CERT), "Correct URL found"); ok(message.text.includes(BAD_CERT), "Correct URL found");
ok( ok(
@ -249,33 +240,31 @@ add_task(async function checkAdvancedDetailsForHSTS() {
let tab = await openErrorPage(BAD_STS_CERT, useFrame); let tab = await openErrorPage(BAD_STS_CERT, useFrame);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
let message = await ContentTask.spawn( let bc = browser.browsingContext;
browser, if (useFrame) {
{ frame: useFrame }, bc = bc.getChildren()[0];
async function({ frame }) { }
let doc = frame
? content.document.querySelector("iframe").contentDocument
: content.document;
let advancedButton = doc.getElementById("advancedButton"); let message = await SpecialPowers.spawn(bc, [], async function() {
advancedButton.click(); let doc = content.document;
let advancedButton = doc.getElementById("advancedButton");
advancedButton.click();
// Wait until fluent sets the errorCode inner text. // Wait until fluent sets the errorCode inner text.
let ec; let ec;
await ContentTaskUtils.waitForCondition(() => { await ContentTaskUtils.waitForCondition(() => {
ec = doc.getElementById("errorCode"); ec = doc.getElementById("errorCode");
return ec.textContent != ""; return ec.textContent != "";
}, "error code has been set inside the advanced button panel"); }, "error code has been set inside the advanced button panel");
let cdl = doc.getElementById("cert_domain_link"); let cdl = doc.getElementById("cert_domain_link");
return { return {
ecTextContent: ec.textContent, ecTextContent: ec.textContent,
ecTagName: ec.tagName, ecTagName: ec.tagName,
cdlTextContent: cdl.textContent, cdlTextContent: cdl.textContent,
cdlTagName: cdl.tagName, cdlTagName: cdl.tagName,
}; };
} });
);
const badStsUri = Services.io.newURI(BAD_STS_CERT); const badStsUri = Services.io.newURI(BAD_STS_CERT);
is( is(
@ -288,34 +277,27 @@ add_task(async function checkAdvancedDetailsForHSTS() {
is(message.cdlTextContent, url, "Correct cert_domain_link contents found"); is(message.cdlTextContent, url, "Correct cert_domain_link contents found");
is(message.cdlTagName, "a", "cert_domain_link is a link"); is(message.cdlTagName, "a", "cert_domain_link is a link");
message = await ContentTask.spawn( message = await SpecialPowers.spawn(bc, [], async function() {
browser, let doc = content.document;
{ frame: useFrame },
async function({ frame }) {
let win = frame
? content.document.querySelector("iframe").contentWindow
: content;
let doc = win.document;
let errorCode = doc.getElementById("errorCode"); let errorCode = doc.getElementById("errorCode");
errorCode.click(); errorCode.click();
let div = doc.getElementById("certificateErrorDebugInformation"); let div = doc.getElementById("certificateErrorDebugInformation");
let text = doc.getElementById("certificateErrorText"); let text = doc.getElementById("certificateErrorText");
let serhelper = Cc[ let serhelper = Cc[
"@mozilla.org/network/serialization-helper;1" "@mozilla.org/network/serialization-helper;1"
].getService(Ci.nsISerializationHelper); ].getService(Ci.nsISerializationHelper);
let serializable = win.docShell.failedChannel.securityInfo let serializable = content.docShell.failedChannel.securityInfo
.QueryInterface(Ci.nsITransportSecurityInfo) .QueryInterface(Ci.nsITransportSecurityInfo)
.QueryInterface(Ci.nsISerializable); .QueryInterface(Ci.nsISerializable);
let serializedSecurityInfo = serhelper.serializeToString(serializable); let serializedSecurityInfo = serhelper.serializeToString(serializable);
return { return {
divDisplay: content.getComputedStyle(div).display, divDisplay: content.getComputedStyle(div).display,
text: text.textContent, text: text.textContent,
securityInfoAsString: serializedSecurityInfo, securityInfoAsString: serializedSecurityInfo,
}; };
} });
);
isnot(message.divDisplay, "none", "Debug information is visible"); isnot(message.divDisplay, "none", "Debug information is visible");
ok(message.text.includes(badStsUri.spec), "Correct URL found"); ok(message.text.includes(badStsUri.spec), "Correct URL found");
ok( ok(
@ -347,17 +329,15 @@ add_task(async function checkUnknownIssuerLearnMoreLink() {
let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame); let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
let href = await ContentTask.spawn( let bc = browser.browsingContext;
browser, if (useFrame) {
{ frame: useFrame }, bc = bc.getChildren()[0];
async function({ frame }) { }
let doc = frame
? content.document.querySelector("iframe").contentDocument let href = await SpecialPowers.spawn(bc, [], async function() {
: content.document; let learnMoreLink = content.document.getElementById("learnMoreLink");
let learnMoreLink = doc.getElementById("learnMoreLink"); return learnMoreLink.href;
return learnMoreLink.href; });
}
);
ok(href.endsWith("security-error"), "security-error in the Learn More URL"); ok(href.endsWith("security-error"), "security-error in the Learn More URL");
BrowserTestUtils.removeTab(gBrowser.selectedTab); BrowserTestUtils.removeTab(gBrowser.selectedTab);
@ -370,32 +350,26 @@ add_task(async function checkCautionClass() {
let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame); let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
await ContentTask.spawn(browser, { frame: useFrame }, async function({ let bc = browser.browsingContext;
frame, if (useFrame) {
}) { bc = bc.getChildren()[0];
let doc = frame }
? content.document.querySelector("iframe").contentDocument
: content.document; await SpecialPowers.spawn(bc, [useFrame], async function(subFrame) {
is( Assert.equal(
doc.body.classList.contains("caution"), content.document.body.classList.contains("caution"),
!frame, !subFrame,
`Cert error body has ${frame ? "no" : ""} caution class` `Cert error body has ${subFrame ? "no" : ""} caution class`
); );
}); });
BrowserTestUtils.removeTab(gBrowser.selectedTab); BrowserTestUtils.removeTab(gBrowser.selectedTab);
tab = await openErrorPage(BAD_STS_CERT, useFrame); tab = await openErrorPage(BAD_STS_CERT, useFrame);
browser = tab.linkedBrowser; bc = tab.linkedBrowser.browsingContext;
await SpecialPowers.spawn(bc, [], async function() {
await ContentTask.spawn(browser, { frame: useFrame }, async function({ Assert.ok(
frame, !content.document.body.classList.contains("caution"),
}) {
let doc = frame
? content.document.querySelector("iframe").contentDocument
: content.document;
ok(
!doc.body.classList.contains("caution"),
"Cert error body has no caution class" "Cert error body has no caution class"
); );
}); });
@ -417,14 +391,14 @@ add_task(async function checkViewCertificate() {
let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame); let tab = await openErrorPage(UNKNOWN_ISSUER, useFrame);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
let bc = browser.browsingContext;
if (useFrame) {
bc = bc.getChildren()[0];
}
let loaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true); let loaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
await ContentTask.spawn(browser, { frame: useFrame }, async function({ await SpecialPowers.spawn(bc, [], async function() {
frame, let viewCertificate = content.document.getElementById("viewCertificate");
}) {
let doc = frame
? content.document.querySelector("iframe").contentDocument
: content.document;
let viewCertificate = doc.getElementById("viewCertificate");
viewCertificate.click(); viewCertificate.click();
}); });
await loaded; await loaded;
@ -435,12 +409,11 @@ add_task(async function checkViewCertificate() {
"about:certificate is the new opened tab" "about:certificate is the new opened tab"
); );
await ContentTask.spawn( await SpecialPowers.spawn(
gBrowser.selectedTab.linkedBrowser, gBrowser.selectedTab.linkedBrowser,
null, [],
async function() { async function() {
let doc = content.document; let doc = content.document;
let certificateSection = await ContentTaskUtils.waitForCondition(() => { let certificateSection = await ContentTaskUtils.waitForCondition(() => {
return doc.querySelector("certificate-section"); return doc.querySelector("certificate-section");
}, "Certificate section found"); }, "Certificate section found");
@ -454,7 +427,7 @@ add_task(async function checkViewCertificate() {
let commonnameID = items[items.length - 1].shadowRoot let commonnameID = items[items.length - 1].shadowRoot
.querySelector("label") .querySelector("label")
.getAttribute("data-l10n-id"); .getAttribute("data-l10n-id");
is( Assert.equal(
commonnameID, commonnameID,
"certificate-viewer-common-name", "certificate-viewer-common-name",
"The correct item was selected" "The correct item was selected"
@ -463,7 +436,7 @@ add_task(async function checkViewCertificate() {
let commonnameValue = items[items.length - 1].shadowRoot.querySelector( let commonnameValue = items[items.length - 1].shadowRoot.querySelector(
".info" ".info"
).textContent; ).textContent;
is( Assert.equal(
commonnameValue, commonnameValue,
"self-signed.example.com", "self-signed.example.com",
"Shows the correct certificate in the page" "Shows the correct certificate in the page"
@ -483,17 +456,15 @@ add_task(async function checkBadStsCertHeadline() {
let tab = await openErrorPage(BAD_CERT, useFrame); let tab = await openErrorPage(BAD_CERT, useFrame);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
let titleContent = await ContentTask.spawn( let bc = browser.browsingContext;
browser, if (useFrame) {
{ frame: useFrame }, bc = bc.getChildren()[0];
async function({ frame }) { }
let doc = frame
? content.document.querySelector("iframe").contentDocument let titleContent = await SpecialPowers.spawn(bc, [], async function() {
: content.document; let titleText = content.document.querySelector(".title-text");
let titleText = doc.querySelector(".title-text"); return titleText.textContent;
return titleText.textContent; });
}
);
if (useFrame) { if (useFrame) {
ok( ok(
titleContent.endsWith("Security Issue"), titleContent.endsWith("Security Issue"),
@ -518,11 +489,11 @@ add_task(async function checkSandboxedIframe() {
let tab = await openErrorPage(BAD_CERT, useFrame, sandboxed); let tab = await openErrorPage(BAD_CERT, useFrame, sandboxed);
let browser = tab.linkedBrowser; let browser = tab.linkedBrowser;
await ContentTask.spawn(browser, {}, async function() { let bc = browser.browsingContext.getChildren()[0];
let doc = content.document.querySelector("iframe").contentDocument; await SpecialPowers.spawn(bc, [], async function() {
let doc = content.document;
let titleText = doc.querySelector(".title-text"); let titleText = doc.querySelector(".title-text");
ok( Assert.ok(
titleText.textContent.endsWith("Security Issue"), titleText.textContent.endsWith("Security Issue"),
"Title shows Did Not Connect: Potential Security Issue" "Title shows Did Not Connect: Potential Security Issue"
); );
@ -534,12 +505,12 @@ add_task(async function checkSandboxedIframe() {
return el.textContent != ""; return el.textContent != "";
}, "error code has been set inside the advanced button panel"); }, "error code has been set inside the advanced button panel");
is( Assert.equal(
el.textContent, el.textContent,
"SEC_ERROR_EXPIRED_CERTIFICATE", "SEC_ERROR_EXPIRED_CERTIFICATE",
"Correct error message found" "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); BrowserTestUtils.removeTab(gBrowser.selectedTab);
}); });

Просмотреть файл

@ -34,30 +34,27 @@ function getPEMString(cert) {
); );
} }
function injectErrorPageFrame(tab, src, sandboxed) { async function injectErrorPageFrame(tab, src, sandboxed) {
return ContentTask.spawn( let loadedPromise = BrowserTestUtils.browserLoaded(
tab.linkedBrowser, tab.linkedBrowser,
{ frameSrc: src, frameSandboxed: sandboxed }, true,
async function({ frameSrc, frameSandboxed }) { null,
let loaded = ContentTaskUtils.waitForEvent( true
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")
);
}
); );
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) { async function openErrorPage(src, useFrame, sandboxed) {