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_aboutCertError.js]
skip-if = fission
[browser_aboutCertError_clockSkew.js]
[browser_aboutCertError_exception.js]
[browser_aboutCertError_mitm.js]

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

@ -37,16 +37,14 @@ add_task(async function checkReturnToAboutHome() {
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"
@ -110,17 +108,21 @@ add_task(async function checkReturnToPreviousPage() {
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");
returnButton.click();
let bc = browser.browsingContext;
if (useFrame) {
bc = bc.getChildren()[0];
}
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.canGoForward, true, "webNavigation.canGoForward");
@ -151,40 +153,37 @@ add_task(async function checkAdvancedDetails() {
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",
@ -192,34 +191,26 @@ add_task(async function checkAdvancedDetails() {
);
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;
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(BAD_CERT), "Correct URL found");
ok(
@ -249,33 +240,31 @@ add_task(async function checkAdvancedDetailsForHSTS() {
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(
@ -288,34 +277,27 @@ add_task(async function checkAdvancedDetailsForHSTS() {
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(
@ -347,17 +329,15 @@ add_task(async function checkUnknownIssuerLearnMoreLink() {
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);
@ -370,32 +350,26 @@ add_task(async function checkCautionClass() {
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"
);
});
@ -417,14 +391,14 @@ add_task(async function checkViewCertificate() {
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;
@ -435,12 +409,11 @@ add_task(async function checkViewCertificate() {
"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");
@ -454,7 +427,7 @@ add_task(async function checkViewCertificate() {
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"
@ -463,7 +436,7 @@ add_task(async function checkViewCertificate() {
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"
@ -483,17 +456,15 @@ add_task(async function checkBadStsCertHeadline() {
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"),
@ -518,11 +489,11 @@ add_task(async function checkSandboxedIframe() {
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"
);
@ -534,12 +505,12 @@ add_task(async function checkSandboxedIframe() {
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);
});

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

@ -34,30 +34,27 @@ function getPEMString(cert) {
);
}
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) {