зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1694882 - WebExtension alerts should show the extension name as the origin. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D107320
This commit is contained in:
Родитель
71a9cb53f9
Коммит
01ee7ce823
|
@ -8,6 +8,29 @@ const TEST_ROOT_CHROME = getRootDirectory(gTestPath);
|
|||
const TEST_DIALOG_PATH = TEST_ROOT_CHROME + "subdialog.xhtml";
|
||||
|
||||
const TEST_DATA_URI = "data:text/html,<body onload='alert(1)'>";
|
||||
const TEST_EXTENSION_DATA = {
|
||||
background() {
|
||||
// eslint-disable-next-line no-undef
|
||||
browser.test.sendMessage("url", browser.extension.getURL("alert.html"));
|
||||
},
|
||||
manifest: {
|
||||
name: "Test Extension",
|
||||
},
|
||||
files: {
|
||||
"alert.html": `<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>TabDialogBox Content Modal Test page</title>
|
||||
<script src="./alert.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>TabDialogBox Content Modal</h1>
|
||||
</body>
|
||||
</html>`,
|
||||
"alert.js": `window.addEventListener("load", () => alert("Hi"));`,
|
||||
},
|
||||
};
|
||||
const TEST_ORIGIN = "http://example.com";
|
||||
const TEST_PAGE =
|
||||
TEST_ROOT_CHROME.replace("chrome://mochitests/content", TEST_ORIGIN) +
|
||||
|
@ -72,6 +95,28 @@ add_task(async function test_tabdialog_null_principal_title() {
|
|||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Test origin text for an extension page.
|
||||
*/
|
||||
add_task(async function test_tabdialog_extension_title() {
|
||||
let extension = ExtensionTestUtils.loadExtension(TEST_EXTENSION_DATA);
|
||||
|
||||
await extension.startup();
|
||||
let url = await extension.awaitMessage("url");
|
||||
let dialogShown = BrowserTestUtils.waitForEvent(
|
||||
gBrowser,
|
||||
"DOMWillOpenModalDialog"
|
||||
);
|
||||
|
||||
await BrowserTestUtils.withNewTab(url, async function(browser) {
|
||||
info("Waiting for dialog to open.");
|
||||
await dialogShown;
|
||||
await checkOriginText(browser, "ScriptDlgHeading", "Test Extension");
|
||||
});
|
||||
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
/**
|
||||
* Test origin text for a regular page.
|
||||
*/
|
||||
|
|
|
@ -213,6 +213,8 @@
|
|||
#include "nsRefreshDriver.h"
|
||||
#include "Layers.h"
|
||||
|
||||
#include "mozilla/extensions/WebExtensionPolicy.h"
|
||||
|
||||
#include "mozilla/BasePrincipal.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
@ -4784,12 +4786,19 @@ void nsGlobalWindowOuter::MakeScriptDialogTitle(
|
|||
nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
|
||||
"ScriptDlgNullPrincipalHeading", aOutTitle);
|
||||
} else {
|
||||
nsresult rv = aSubjectPrincipal->GetExposablePrePath(prepath);
|
||||
if (NS_SUCCEEDED(rv) && !prepath.IsEmpty()) {
|
||||
NS_ConvertUTF8toUTF16 ucsPrePath(prepath);
|
||||
auto* addonPolicy = BasePrincipal::Cast(aSubjectPrincipal)->AddonPolicy();
|
||||
if (addonPolicy) {
|
||||
nsContentUtils::FormatLocalizedString(
|
||||
aOutTitle, nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
|
||||
"ScriptDlgHeading", ucsPrePath);
|
||||
"ScriptDlgHeading", addonPolicy->Name());
|
||||
} else {
|
||||
nsresult rv = aSubjectPrincipal->GetExposablePrePath(prepath);
|
||||
if (NS_SUCCEEDED(rv) && !prepath.IsEmpty()) {
|
||||
NS_ConvertUTF8toUTF16 ucsPrePath(prepath);
|
||||
nsContentUtils::FormatLocalizedString(
|
||||
aOutTitle, nsContentUtils::eCOMMON_DIALOG_PROPERTIES,
|
||||
"ScriptDlgHeading", ucsPrePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче