From 8fefbe08c107a0c366c00e4e5c382906573cf7a5 Mon Sep 17 00:00:00 2001 From: James Teh Date: Tue, 12 Oct 2021 23:43:06 +0000 Subject: [PATCH] Bug 1734540: Use document.body.innerHTML instead of document.write in chrome-document-builder.html. r=eeejay This is a follow-up to my original patch. It turns out that there is an assertion preventing use of document.write in privileged contexts which my original patch triggered. Instead, set document.body.innerHTML. Differential Revision: https://phabricator.services.mozilla.com/D128159 --- .../browser/chrome-document-builder.html | 10 +++-- accessible/tests/browser/shared-head.js | 37 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/accessible/tests/browser/chrome-document-builder.html b/accessible/tests/browser/chrome-document-builder.html index 074cc5a7adec..69d15cea158e 100644 --- a/accessible/tests/browser/chrome-document-builder.html +++ b/accessible/tests/browser/chrome-document-builder.html @@ -1,5 +1,8 @@ + + +Accessibility Test + diff --git a/accessible/tests/browser/shared-head.js b/accessible/tests/browser/shared-head.js index 9eff1bfefa0b..28c680f3c0c9 100644 --- a/accessible/tests/browser/shared-head.js +++ b/accessible/tests/browser/shared-head.js @@ -413,23 +413,16 @@ function snippetToURL(doc, options = {}) { doc = wrapWithIFrame(doc, options); } - const fullDoc = ` - - - Accessibility Test - - ${doc} - `; + const encodedDoc = encodeURIComponent( + ` + + + Accessibility Test + + ${doc} + ` + ); - if (options.chrome) { - // Load with a chrome:// URL so this loads as a chrome document in the - // parent process. - const url = new URL(`${CURRENT_DIR}chrome-document-builder.html`); - url.searchParams.append("html", fullDoc); - return url.href; - } - - const encodedDoc = encodeURIComponent(fullDoc); return `data:text/html;charset=utf-8,${encodedDoc}`; } @@ -438,11 +431,17 @@ function accessibleTask(doc, task, options = {}) { gIsRemoteIframe = options.remoteIframe; gIsIframe = options.iframe || gIsRemoteIframe; let url; - if (options.chrome && doc.endsWith("html")) { + if (options.chrome) { // Load with a chrome:// URL so this loads as a chrome document in the // parent process. - url = `${CURRENT_DIR}${doc}`; - } else if (!options.chrome && doc.endsWith("html") && !gIsIframe) { + if (doc.endsWith("html")) { + url = `${CURRENT_DIR}${doc}`; + } else { + const urlObj = new URL(`${CURRENT_DIR}chrome-document-builder.html`); + urlObj.searchParams.append("html", doc); + url = urlObj.href; + } + } else if (doc.endsWith("html") && !gIsIframe) { url = `${CURRENT_CONTENT_DIR}${doc}`; } else { url = snippetToURL(doc, options);