From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../test/popupNotifications/browser_displayURI.js | 159 +++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 browser/base/content/test/popupNotifications/browser_displayURI.js (limited to 'browser/base/content/test/popupNotifications/browser_displayURI.js') diff --git a/browser/base/content/test/popupNotifications/browser_displayURI.js b/browser/base/content/test/popupNotifications/browser_displayURI.js new file mode 100644 index 0000000000..c9e677cd45 --- /dev/null +++ b/browser/base/content/test/popupNotifications/browser_displayURI.js @@ -0,0 +1,159 @@ +/* + * Make sure that the correct origin is shown for permission prompts. + */ + +async function check(contentTask, options = {}) { + await BrowserTestUtils.withNewTab( + "https://test1.example.com/", + async function (browser) { + let popupShownPromise = waitForNotificationPanel(); + await SpecialPowers.spawn(browser, [], contentTask); + let panel = await popupShownPromise; + let notification = panel.children[0]; + let body = notification.querySelector(".popup-notification-body"); + ok( + body.innerHTML.includes("example.com"), + "Check that at least the eTLD+1 is present in the markup" + ); + } + ); + + let channel = NetUtil.newChannel({ + uri: getRootDirectory(gTestPath), + loadUsingSystemPrincipal: true, + }); + channel = channel.QueryInterface(Ci.nsIFileChannel); + + await BrowserTestUtils.withNewTab( + channel.file.path, + async function (browser) { + let popupShownPromise = waitForNotificationPanel(); + await SpecialPowers.spawn(browser, [], contentTask); + let panel = await popupShownPromise; + let notification = panel.children[0]; + let body = notification.querySelector(".popup-notification-body"); + if ( + notification.id == "geolocation-notification" || + notification.id == "xr-notification" + ) { + ok( + body.innerHTML.includes("local file"), + `file:// URIs should be displayed as local file.` + ); + } else { + ok( + body.innerHTML.includes("Unknown origin"), + "file:// URIs should be displayed as unknown origin." + ); + } + } + ); + + if (!options.skipOnExtension) { + // Test the scenario also on the extension page if not explicitly unsupported + // (e.g. an extension page can't be navigated on a blob URL). + let extension = ExtensionTestUtils.loadExtension({ + manifest: { + name: "Test Extension Name", + }, + background() { + let { browser } = this; + browser.test.sendMessage( + "extension-tab-url", + browser.runtime.getURL("extension-tab-page.html") + ); + }, + files: { + "extension-tab-page.html": ``, + }, + }); + + await extension.startup(); + let extensionURI = await extension.awaitMessage("extension-tab-url"); + + await BrowserTestUtils.withNewTab(extensionURI, async function (browser) { + let popupShownPromise = waitForNotificationPanel(); + await SpecialPowers.spawn(browser, [], contentTask); + let panel = await popupShownPromise; + let notification = panel.children[0]; + let body = notification.querySelector(".popup-notification-body"); + ok( + body.innerHTML.includes("Test Extension Name"), + "Check the the extension name is present in the markup" + ); + }); + + await extension.unload(); + } +} + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["media.navigator.permission.fake", true], + ["media.navigator.permission.force", true], + ["dom.vr.always_support_vr", true], + ], + }); +}); + +add_task(async function test_displayURI_geo() { + await check(async function () { + content.navigator.geolocation.getCurrentPosition(() => {}); + }); +}); + +const kVREnabled = SpecialPowers.getBoolPref("dom.vr.enabled"); +if (kVREnabled) { + add_task(async function test_displayURI_xr() { + await check(async function () { + content.navigator.getVRDisplays(); + }); + }); +} + +add_task(async function test_displayURI_camera() { + await check(async function () { + content.navigator.mediaDevices.getUserMedia({ video: true, fake: true }); + }); +}); + +add_task(async function test_displayURI_geo_blob() { + await check( + async function () { + let text = + ""; + let blob = new Blob([text], { type: "text/html" }); + let url = content.URL.createObjectURL(blob); + content.location.href = url; + }, + { skipOnExtension: true } + ); +}); + +if (kVREnabled) { + add_task(async function test_displayURI_xr_blob() { + await check( + async function () { + let text = ""; + let blob = new Blob([text], { type: "text/html" }); + let url = content.URL.createObjectURL(blob); + content.location.href = url; + }, + { skipOnExtension: true } + ); + }); +} + +add_task(async function test_displayURI_camera_blob() { + await check( + async function () { + let text = + ""; + let blob = new Blob([text], { type: "text/html" }); + let url = content.URL.createObjectURL(blob); + content.location.href = url; + }, + { skipOnExtension: true } + ); +}); -- cgit v1.2.3