From 2857a921848a4177aa1566414c28e4e28de2405a Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Fri, 26 Mar 2021 08:27:51 +0000 Subject: [PATCH] Bug 1698449: Update test browser_resource_uri.js r=mossop Differential Revision: https://phabricator.services.mozilla.com/D108832 --- .../browser_resource_uri.js | 33 +++++++++++++++++-- .../non-system-principal/test.html | 5 +-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/dom/l10n/tests/mochitest/document_l10n/non-system-principal/browser_resource_uri.js b/dom/l10n/tests/mochitest/document_l10n/non-system-principal/browser_resource_uri.js index 00433c531482..36bcf3b2987e 100644 --- a/dom/l10n/tests/mochitest/document_l10n/non-system-principal/browser_resource_uri.js +++ b/dom/l10n/tests/mochitest/document_l10n/non-system-principal/browser_resource_uri.js @@ -29,20 +29,45 @@ registerCleanupFunction(() => { }); }); +const kChildPage = getRootDirectory(gTestPath) + "test.html"; + +const kAboutPagesRegistered = Promise.all([ + BrowserTestUtils.registerAboutPage( + registerCleanupFunction, + "test-about-l10n-child", + kChildPage, + Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD | + Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT | + Ci.nsIAboutModule.URI_CONTENT_LINKABLE | + Ci.nsIAboutModule.ALLOW_SCRIPT + ), +]); + add_task(async () => { // Bug 1640333 - windows fails (sometimes) to ever get document.l10n.ready // if e10s process caching is enabled await SpecialPowers.pushPrefEnv({ - set: [["dom.ipc.processPrelaunch.enabled", false]], + set: [ + ["dom.ipc.processPrelaunch.enabled", false], + ["dom.security.skip_about_page_has_csp_assert", true], + ], }); + await kAboutPagesRegistered; await BrowserTestUtils.withNewTab( - "resource://l10n-test/test.html", + "about:test-about-l10n-child", async browser => { await SpecialPowers.spawn(browser, [], async function() { let document = content.document; let window = document.defaultView; - let { customMsg, l10nArgs } = await document.testsReadyPromise; + await document.testsReadyPromise; + + let principal = SpecialPowers.wrap(document).nodePrincipal; + is( + principal.spec, + "about:test-about-l10n-child", + "correct content principal" + ); let desc = document.getElementById("main-desc"); @@ -57,10 +82,12 @@ add_task(async () => { // Test for l10n.getAttributes let label = document.getElementById("label1"); + let l10nArgs = document.l10n.getAttributes(label); is(l10nArgs.id, "subtitle"); is(l10nArgs.args.name, "Firefox"); // Test for manual value formatting + let customMsg = document.getElementById("customMessage").textContent; is(customMsg, "This is a custom message formatted from JS."); // Since we applied the `data-l10n-id` attribute diff --git a/dom/l10n/tests/mochitest/document_l10n/non-system-principal/test.html b/dom/l10n/tests/mochitest/document_l10n/non-system-principal/test.html index 3b6784ed6b2b..5d91f3da46f8 100644 --- a/dom/l10n/tests/mochitest/document_l10n/non-system-principal/test.html +++ b/dom/l10n/tests/mochitest/document_l10n/non-system-principal/test.html @@ -22,8 +22,8 @@ ); const customMsg = await document.l10n.formatValue("custom-message"); - const l10nArgs = document.l10n.getAttributes(label); - resolve({customMsg, l10nArgs}); + document.getElementById("customMessage").textContent = customMsg; + resolve(); }, {once: true}); }); @@ -32,5 +32,6 @@

+