Bug 1698449: Update test browser_resource_uri.js r=mossop

Differential Revision: https://phabricator.services.mozilla.com/D108832
This commit is contained in:
Christoph Kerschbaumer 2021-03-26 08:27:51 +00:00
Родитель 64e255e33d
Коммит 2857a92184
2 изменённых файлов: 33 добавлений и 5 удалений

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

@ -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 () => { add_task(async () => {
// Bug 1640333 - windows fails (sometimes) to ever get document.l10n.ready // Bug 1640333 - windows fails (sometimes) to ever get document.l10n.ready
// if e10s process caching is enabled // if e10s process caching is enabled
await SpecialPowers.pushPrefEnv({ 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( await BrowserTestUtils.withNewTab(
"resource://l10n-test/test.html", "about:test-about-l10n-child",
async browser => { async browser => {
await SpecialPowers.spawn(browser, [], async function() { await SpecialPowers.spawn(browser, [], async function() {
let document = content.document; let document = content.document;
let window = document.defaultView; 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"); let desc = document.getElementById("main-desc");
@ -57,10 +82,12 @@ add_task(async () => {
// Test for l10n.getAttributes // Test for l10n.getAttributes
let label = document.getElementById("label1"); let label = document.getElementById("label1");
let l10nArgs = document.l10n.getAttributes(label);
is(l10nArgs.id, "subtitle"); is(l10nArgs.id, "subtitle");
is(l10nArgs.args.name, "Firefox"); is(l10nArgs.args.name, "Firefox");
// Test for manual value formatting // Test for manual value formatting
let customMsg = document.getElementById("customMessage").textContent;
is(customMsg, "This is a custom message formatted from JS."); is(customMsg, "This is a custom message formatted from JS.");
// Since we applied the `data-l10n-id` attribute // Since we applied the `data-l10n-id` attribute

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

@ -22,8 +22,8 @@
); );
const customMsg = await document.l10n.formatValue("custom-message"); const customMsg = await document.l10n.formatValue("custom-message");
const l10nArgs = document.l10n.getAttributes(label); document.getElementById("customMessage").textContent = customMsg;
resolve({customMsg, l10nArgs}); resolve();
}, {once: true}); }, {once: true});
}); });
</script> </script>
@ -32,5 +32,6 @@
<h1 id="main-desc" data-l10n-id="page-title"></h1> <h1 id="main-desc" data-l10n-id="page-title"></h1>
<p id="label1"></p> <p id="label1"></p>
<p id="customMessage"></p>
</body> </body>
</html> </html>