summaryrefslogtreecommitdiffstats
path: root/browser/base/content/test/pageinfo
diff options
context:
space:
mode:
Diffstat (limited to 'browser/base/content/test/pageinfo')
-rw-r--r--browser/base/content/test/pageinfo/all_images.html15
-rw-r--r--browser/base/content/test/pageinfo/browser.ini27
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js89
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_iframe_media.js31
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_image_info.js57
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_images.js93
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_permissions.js258
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_rtl.js28
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_security.js354
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_separate_private.js49
-rw-r--r--browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js34
-rw-r--r--browser/base/content/test/pageinfo/iframes.html8
-rw-r--r--browser/base/content/test/pageinfo/image.html5
-rw-r--r--browser/base/content/test/pageinfo/svg_image.html11
14 files changed, 1059 insertions, 0 deletions
diff --git a/browser/base/content/test/pageinfo/all_images.html b/browser/base/content/test/pageinfo/all_images.html
new file mode 100644
index 0000000000..c246e25519
--- /dev/null
+++ b/browser/base/content/test/pageinfo/all_images.html
@@ -0,0 +1,15 @@
+<html>
+ <head>
+ <title>Test for media tab</title>
+ <link rel='shortcut icon' href='dummy_icon.ico'>
+ </head>
+ <body style='background-image:url(about:logo?a);'>
+ <img src='dummy_image.gif'>
+ <ul>
+ <li style='list-style:url(about:logo?b);'>List Item 1</li>
+ </ul>
+ <div style='-moz-border-image: url(about:logo?c) 20 20 20 20;'>test</div>
+ <a href='' style='cursor: url(about:logo?d),default;'>test link</a>
+ <object type='image/svg+xml' width=20 height=20 data='dummy_object.svg'></object>
+ </body>
+</html>");
diff --git a/browser/base/content/test/pageinfo/browser.ini b/browser/base/content/test/pageinfo/browser.ini
new file mode 100644
index 0000000000..c109c6bf66
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser.ini
@@ -0,0 +1,27 @@
+[DEFAULT]
+
+[browser_pageinfo_firstPartyIsolation.js]
+support-files =
+ image.html
+ ../general/audio.ogg
+ ../general/moz.png
+ ../general/video.ogg
+[browser_pageinfo_iframe_media.js]
+support-files =
+ iframes.html
+[browser_pageinfo_image_info.js]
+skip-if = (os == 'linux') # bug 1161699
+[browser_pageinfo_images.js]
+support-files =
+ all_images.html
+[browser_pageinfo_permissions.js]
+[browser_pageinfo_rtl.js]
+[browser_pageinfo_security.js]
+https_first_disabled = true
+support-files =
+ ../general/moz.png
+[browser_pageinfo_separate_private.js]
+[browser_pageinfo_svg_image.js]
+support-files =
+ svg_image.html
+ ../general/title_test.svg
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js b/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js
new file mode 100644
index 0000000000..b280242b40
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_firstPartyIsolation.js
@@ -0,0 +1,89 @@
+const Cm = Components.manager;
+
+async function testFirstPartyDomain(pageInfo) {
+ const EXPECTED_DOMAIN = "example.com";
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+ info("pageInfo initialized");
+ let tree = pageInfo.document.getElementById("imagetree");
+ Assert.ok(!!tree, "should have imagetree element");
+
+ // i=0: <img>
+ // i=1: <video>
+ // i=2: <audio>
+ for (let i = 0; i < 3; i++) {
+ info("imagetree select " + i);
+ tree.view.selection.select(i);
+ tree.ensureRowIsVisible(i);
+ tree.focus();
+
+ let preview = pageInfo.document.getElementById("thepreviewimage");
+ info("preview.src=" + preview.src);
+
+ // For <img>, we will query imgIRequest.imagePrincipal later, so we wait
+ // for load event. For <audio> and <video>, so far we only can get
+ // the triggeringprincipal attribute on the node, so we simply wait for
+ // loadstart.
+ if (i == 0) {
+ await BrowserTestUtils.waitForEvent(preview, "load");
+ } else {
+ await BrowserTestUtils.waitForEvent(preview, "loadstart");
+ }
+
+ info("preview load " + i);
+
+ // Originally thepreviewimage is loaded with SystemPrincipal, therefore
+ // it won't have origin attributes, now we've changed to loadingPrincipal
+ // to the content in bug 1376971, it should have firstPartyDomain set.
+ if (i == 0) {
+ let req = preview.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
+ Assert.equal(
+ req.imagePrincipal.originAttributes.firstPartyDomain,
+ EXPECTED_DOMAIN,
+ "imagePrincipal should have firstPartyDomain set to " + EXPECTED_DOMAIN
+ );
+ }
+
+ // Check the node has the attribute 'triggeringprincipal'.
+ let loadingPrincipalStr = preview.getAttribute("triggeringprincipal");
+ let loadingPrincipal = E10SUtils.deserializePrincipal(loadingPrincipalStr);
+ Assert.equal(
+ loadingPrincipal.originAttributes.firstPartyDomain,
+ EXPECTED_DOMAIN,
+ "loadingPrincipal should have firstPartyDomain set to " + EXPECTED_DOMAIN
+ );
+ }
+}
+
+async function test() {
+ waitForExplicitFinish();
+
+ Services.prefs.setBoolPref("privacy.firstparty.isolate", true);
+ registerCleanupFunction(function () {
+ Services.prefs.clearUserPref("privacy.firstparty.isolate");
+ });
+
+ let url =
+ "https://example.com/browser/browser/base/content/test/pageinfo/image.html";
+ gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
+ let loadPromise = BrowserTestUtils.browserLoaded(
+ gBrowser.selectedBrowser,
+ false,
+ url
+ );
+ BrowserTestUtils.loadURIString(gBrowser.selectedBrowser, url);
+ await loadPromise;
+
+ // Pass a dummy imageElement, if there isn't an imageElement, pageInfo.js
+ // will do a preview, however this sometimes will cause intermittent failures,
+ // see bug 1403365.
+ let pageInfo = BrowserPageInfo(url, "mediaTab", {});
+ info("waitForEvent pageInfo");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+
+ info("calling testFirstPartyDomain");
+ await testFirstPartyDomain(pageInfo);
+
+ pageInfo.close();
+ gBrowser.removeCurrentTab();
+ finish();
+}
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_iframe_media.js b/browser/base/content/test/pageinfo/browser_pageinfo_iframe_media.js
new file mode 100644
index 0000000000..3040474f31
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_iframe_media.js
@@ -0,0 +1,31 @@
+/* Check proper media data retrieval in case of iframe */
+
+const TEST_PATH = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ "http://example.com"
+);
+
+add_task(async function test_all_images_mentioned() {
+ await BrowserTestUtils.withNewTab(
+ TEST_PATH + "iframes.html",
+ async function () {
+ let pageInfo = BrowserPageInfo(
+ gBrowser.selectedBrowser.currentURI.spec,
+ "mediaTab"
+ );
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+
+ let imageTree = pageInfo.document.getElementById("imagetree");
+ let imageRowsNum = imageTree.view.rowCount;
+
+ ok(imageTree, "Image tree is null (media tab is broken)");
+ ok(
+ imageRowsNum == 2,
+ "Number of media items listed: " + imageRowsNum + ", should be 2"
+ );
+
+ pageInfo.close();
+ }
+ );
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js b/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js
new file mode 100644
index 0000000000..374cd5f032
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_image_info.js
@@ -0,0 +1,57 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ **/
+
+const URI =
+ "data:text/html," +
+ "<style type='text/css'>%23test-image,%23not-test-image {background-image: url('about:logo?c');}</style>" +
+ "<img src='about:logo?b' height=300 width=350 alt=2 id='not-test-image'>" +
+ "<img src='about:logo?b' height=300 width=350 alt=2>" +
+ "<img src='about:logo?a' height=200 width=250>" +
+ "<img src='about:logo?b' height=200 width=250 alt=1>" +
+ "<img src='about:logo?b' height=100 width=150 alt=2 id='test-image'>";
+
+add_task(async function () {
+ let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URI);
+ let browser = tab.linkedBrowser;
+
+ let imageInfo = await SpecialPowers.spawn(browser, [], async () => {
+ let testImg = content.document.getElementById("test-image");
+
+ return {
+ src: testImg.src,
+ currentSrc: testImg.currentSrc,
+ width: testImg.width,
+ height: testImg.height,
+ imageText: testImg.title || testImg.alt,
+ };
+ });
+
+ let pageInfo = BrowserPageInfo(
+ browser.currentURI.spec,
+ "mediaTab",
+ imageInfo
+ );
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+
+ let pageInfoImg = pageInfo.document.getElementById("thepreviewimage");
+ await BrowserTestUtils.waitForEvent(pageInfoImg, "load");
+ Assert.equal(
+ pageInfoImg.src,
+ imageInfo.src,
+ "selected image has the correct source"
+ );
+ Assert.equal(
+ pageInfoImg.width,
+ imageInfo.width,
+ "selected image has the correct width"
+ );
+ Assert.equal(
+ pageInfoImg.height,
+ imageInfo.height,
+ "selected image has the correct height"
+ );
+ pageInfo.close();
+ BrowserTestUtils.removeTab(tab);
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_images.js b/browser/base/content/test/pageinfo/browser_pageinfo_images.js
new file mode 100644
index 0000000000..5cb4c79bf3
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_images.js
@@ -0,0 +1,93 @@
+/* Check proper image url retrieval from all kinds of elements/styles */
+
+const TEST_PATH = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ // eslint-disable-next-line @microsoft/sdl/no-insecure-url
+ "http://example.com"
+);
+
+add_task(async function test_all_images_mentioned() {
+ await BrowserTestUtils.withNewTab(
+ TEST_PATH + "all_images.html",
+ async function () {
+ let pageInfo = BrowserPageInfo(
+ gBrowser.selectedBrowser.currentURI.spec,
+ "mediaTab"
+ );
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+
+ let imageTree = pageInfo.document.getElementById("imagetree");
+ let imageRowsNum = imageTree.view.rowCount;
+
+ ok(imageTree, "Image tree is null (media tab is broken)");
+
+ ok(
+ imageRowsNum == 7,
+ "Number of images listed: " + imageRowsNum + ", should be 7"
+ );
+
+ // Check that select all works
+ imageTree.focus();
+ ok(
+ !pageInfo.document.getElementById("cmd_copy").hasAttribute("disabled"),
+ "copy is enabled"
+ );
+ ok(
+ !pageInfo.document
+ .getElementById("cmd_selectAll")
+ .hasAttribute("disabled"),
+ "select all is enabled"
+ );
+ pageInfo.goDoCommand("cmd_selectAll");
+ is(imageTree.view.selection.count, 7, "all rows selected");
+
+ pageInfo.close();
+ }
+ );
+});
+
+add_task(async function test_view_image_info() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["browser.menu.showViewImageInfo", true]],
+ });
+
+ await BrowserTestUtils.withNewTab(
+ TEST_PATH + "all_images.html",
+
+ async function (browser) {
+ let contextMenu = document.getElementById("contentAreaContextMenu");
+ let viewImageInfo = document.getElementById("context-viewimageinfo");
+
+ let imageInfo = await SpecialPowers.spawn(browser, [], async () => {
+ let testImg = content.document.querySelector("img");
+ return {
+ src: testImg.src,
+ };
+ });
+
+ await BrowserTestUtils.synthesizeMouseAtCenter(
+ "img",
+ { type: "contextmenu", button: 2 },
+ browser
+ );
+
+ await BrowserTestUtils.waitForEvent(contextMenu, "popupshown");
+
+ let promisePageInfoLoaded = BrowserTestUtils.domWindowOpened().then(win =>
+ BrowserTestUtils.waitForEvent(win, "page-info-init")
+ );
+
+ contextMenu.activateItem(viewImageInfo);
+
+ let pageInfo = (await promisePageInfoLoaded).target.ownerGlobal;
+ let pageInfoImg = pageInfo.document.getElementById("thepreviewimage");
+
+ Assert.equal(
+ pageInfoImg.src,
+ imageInfo.src,
+ "selected image is the correct"
+ );
+ await BrowserTestUtils.closeWindow(pageInfo);
+ }
+ );
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_permissions.js b/browser/base/content/test/pageinfo/browser_pageinfo_permissions.js
new file mode 100644
index 0000000000..7e3e83b60d
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_permissions.js
@@ -0,0 +1,258 @@
+const { PermissionTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/PermissionTestUtils.sys.mjs"
+);
+
+const TEST_ORIGIN = "https://example.com";
+const TEST_ORIGIN_CERT_ERROR = "https://expired.example.com";
+const LOW_TLS_VERSION = "https://tls1.example.com/";
+
+async function testPermissions(defaultPermission) {
+ await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function (browser) {
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+
+ let defaultCheckbox = await TestUtils.waitForCondition(() =>
+ pageInfo.document.getElementById("geoDef")
+ );
+ let radioGroup = pageInfo.document.getElementById("geoRadioGroup");
+ let defaultRadioButton = pageInfo.document.getElementById(
+ "geo#" + defaultPermission
+ );
+ let blockRadioButton = pageInfo.document.getElementById("geo#2");
+
+ ok(defaultCheckbox.checked, "The default checkbox should be checked.");
+
+ PermissionTestUtils.add(
+ gBrowser.currentURI,
+ "geo",
+ Services.perms.DENY_ACTION
+ );
+
+ ok(!defaultCheckbox.checked, "The default checkbox should not be checked.");
+
+ defaultCheckbox.checked = true;
+ defaultCheckbox.dispatchEvent(new Event("command"));
+
+ ok(
+ !PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo"),
+ "Checking the default checkbox should reset the permission."
+ );
+
+ defaultCheckbox.checked = false;
+ defaultCheckbox.dispatchEvent(new Event("command"));
+
+ ok(
+ !PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo"),
+ "Unchecking the default checkbox should pick the default permission."
+ );
+ is(
+ radioGroup.selectedItem,
+ defaultRadioButton,
+ "The unknown radio button should be selected."
+ );
+
+ radioGroup.selectedItem = blockRadioButton;
+ blockRadioButton.dispatchEvent(new Event("command"));
+
+ is(
+ PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo")
+ .capability,
+ Services.perms.DENY_ACTION,
+ "Selecting a value in the radio group should set the corresponding permission"
+ );
+
+ radioGroup.selectedItem = defaultRadioButton;
+ defaultRadioButton.dispatchEvent(new Event("command"));
+
+ ok(
+ !PermissionTestUtils.getPermissionObject(gBrowser.currentURI, "geo"),
+ "Selecting the default value should reset the permission."
+ );
+ ok(defaultCheckbox.checked, "The default checkbox should be checked.");
+
+ pageInfo.close();
+ PermissionTestUtils.remove(gBrowser.currentURI, "geo");
+ });
+}
+
+// Test displaying website permissions on certificate error pages.
+add_task(async function test_CertificateError() {
+ let browser;
+ let pageLoaded;
+ await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ () => {
+ gBrowser.selectedTab = BrowserTestUtils.addTab(
+ gBrowser,
+ TEST_ORIGIN_CERT_ERROR
+ );
+ browser = gBrowser.selectedBrowser;
+ pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
+ },
+ false
+ );
+
+ await pageLoaded;
+
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN_CERT_ERROR, "permTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let permissionTab = pageInfo.document.getElementById("permTab");
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(permissionTab),
+ "Permission tab should be visible."
+ );
+
+ let hostText = pageInfo.document.getElementById("hostText");
+ let permList = pageInfo.document.getElementById("permList");
+ let excludedPermissions = pageInfo.window.getExcludedPermissions();
+ let permissions = SitePermissions.listPermissions().filter(
+ p =>
+ SitePermissions.getPermissionLabel(p) != null &&
+ !excludedPermissions.includes(p)
+ );
+
+ await TestUtils.waitForCondition(
+ () => hostText.value === browser.currentURI.displayPrePath,
+ `Value of owner should be "${browser.currentURI.displayPrePath}" instead got "${hostText.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => permList.childElementCount === permissions.length,
+ `Value of verifier should be ${permissions.length}, instead got ${permList.childElementCount}.`
+ );
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test displaying website permissions on network error pages.
+add_task(async function test_NetworkError() {
+ // Setup for TLS error
+ Services.prefs.setIntPref("security.tls.version.max", 3);
+ Services.prefs.setIntPref("security.tls.version.min", 3);
+
+ let browser;
+ let pageLoaded;
+ await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ () => {
+ gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, LOW_TLS_VERSION);
+ browser = gBrowser.selectedBrowser;
+ pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
+ },
+ false
+ );
+
+ await pageLoaded;
+
+ let pageInfo = BrowserPageInfo(LOW_TLS_VERSION, "permTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let permissionTab = pageInfo.document.getElementById("permTab");
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(permissionTab),
+ "Permission tab should be visible."
+ );
+
+ let hostText = pageInfo.document.getElementById("hostText");
+ let permList = pageInfo.document.getElementById("permList");
+ let excludedPermissions = pageInfo.window.getExcludedPermissions();
+ let permissions = SitePermissions.listPermissions().filter(
+ p =>
+ SitePermissions.getPermissionLabel(p) != null &&
+ !excludedPermissions.includes(p)
+ );
+
+ await TestUtils.waitForCondition(
+ () => hostText.value === browser.currentURI.displayPrePath,
+ `Value of host should be should be "${browser.currentURI.displayPrePath}" instead got "${hostText.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => permList.childElementCount === permissions.length,
+ `Value of permissions list should be ${permissions.length}, instead got ${permList.childElementCount}.`
+ );
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test some standard operations in the permission tab.
+add_task(async function test_geo_permission() {
+ await testPermissions(Services.perms.UNKNOWN_ACTION);
+});
+
+// Test some standard operations in the permission tab, falling back to a custom
+// default permission instead of UNKNOWN.
+add_task(async function test_default_geo_permission() {
+ await SpecialPowers.pushPrefEnv({
+ set: [["permissions.default.geo", SitePermissions.ALLOW]],
+ });
+ await testPermissions(Services.perms.ALLOW_ACTION);
+});
+
+// Test special behavior for cookie permissions.
+add_task(async function test_cookie_permission() {
+ await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function (browser) {
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN, "permTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+
+ let defaultCheckbox = await TestUtils.waitForCondition(() =>
+ pageInfo.document.getElementById("cookieDef")
+ );
+ let radioGroup = pageInfo.document.getElementById("cookieRadioGroup");
+ let allowRadioButton = pageInfo.document.getElementById("cookie#1");
+ let blockRadioButton = pageInfo.document.getElementById("cookie#2");
+
+ ok(defaultCheckbox.checked, "The default checkbox should be checked.");
+
+ defaultCheckbox.checked = false;
+ defaultCheckbox.dispatchEvent(new Event("command"));
+
+ is(
+ PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
+ SitePermissions.ALLOW,
+ "Unchecking the default checkbox should pick the default permission."
+ );
+ is(
+ radioGroup.selectedItem,
+ allowRadioButton,
+ "The unknown radio button should be selected."
+ );
+
+ radioGroup.selectedItem = blockRadioButton;
+ blockRadioButton.dispatchEvent(new Event("command"));
+
+ is(
+ PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
+ SitePermissions.BLOCK,
+ "Selecting a value in the radio group should set the corresponding permission"
+ );
+
+ radioGroup.selectedItem = allowRadioButton;
+ allowRadioButton.dispatchEvent(new Event("command"));
+
+ is(
+ PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
+ SitePermissions.ALLOW,
+ "Selecting a value in the radio group should set the corresponding permission"
+ );
+ ok(!defaultCheckbox.checked, "The default checkbox should not be checked.");
+
+ defaultCheckbox.checked = true;
+ defaultCheckbox.dispatchEvent(new Event("command"));
+
+ is(
+ PermissionTestUtils.testPermission(gBrowser.currentURI, "cookie"),
+ SitePermissions.UNKNOWN,
+ "Checking the default checkbox should reset the permission."
+ );
+ is(
+ radioGroup.selectedItem,
+ null,
+ "For cookies, no item should be selected when the checkbox is checked."
+ );
+
+ pageInfo.close();
+ PermissionTestUtils.remove(gBrowser.currentURI, "cookie");
+ });
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_rtl.js b/browser/base/content/test/pageinfo/browser_pageinfo_rtl.js
new file mode 100644
index 0000000000..d0c06a03ff
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_rtl.js
@@ -0,0 +1,28 @@
+async function testPageInfo() {
+ await BrowserTestUtils.withNewTab(
+ "https://example.com",
+ async function (browser) {
+ let pageInfo = BrowserPageInfo();
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+ is(
+ getComputedStyle(pageInfo.document.documentElement).direction,
+ "rtl",
+ "Should be RTL"
+ );
+ ok(true, "Didn't assert or crash");
+ pageInfo.close();
+ }
+ );
+}
+
+add_task(async function test_page_info_rtl() {
+ await SpecialPowers.pushPrefEnv({ set: [["intl.l10n.pseudo", "bidi"]] });
+
+ for (let useOverlayScrollbars of [0, 1]) {
+ info("Testing with overlay scrollbars: " + useOverlayScrollbars);
+ await SpecialPowers.pushPrefEnv({
+ set: [["ui.useOverlayScrollbars", useOverlayScrollbars]],
+ });
+ await testPageInfo();
+ }
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_security.js b/browser/base/content/test/pageinfo/browser_pageinfo_security.js
new file mode 100644
index 0000000000..0a8c57a46d
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_security.js
@@ -0,0 +1,354 @@
+ChromeUtils.defineESModuleGetters(this, {
+ DownloadUtils: "resource://gre/modules/DownloadUtils.sys.mjs",
+ SiteDataTestUtils: "resource://testing-common/SiteDataTestUtils.sys.mjs",
+});
+
+const TEST_ORIGIN = "https://example.com";
+// eslint-disable-next-line @microsoft/sdl/no-insecure-url
+const TEST_HTTP_ORIGIN = "http://example.com";
+const TEST_SUB_ORIGIN = "https://test1.example.com";
+const REMOVE_DIALOG_URL =
+ "chrome://browser/content/preferences/dialogs/siteDataRemoveSelected.xhtml";
+const TEST_ORIGIN_CERT_ERROR = "https://expired.example.com";
+
+const TEST_PATH = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content",
+ "https://example.com"
+);
+
+// Test opening the correct certificate information when clicking "Show certificate".
+add_task(async function test_ShowCertificate() {
+ let tab1 = await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_ORIGIN);
+ let tab2 = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ TEST_SUB_ORIGIN
+ );
+
+ let pageInfo = BrowserPageInfo(TEST_SUB_ORIGIN, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let pageInfoDoc = pageInfo.document;
+ let securityTab = pageInfoDoc.getElementById("securityTab");
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(securityTab),
+ "Security tab should be visible."
+ );
+
+ async function openAboutCertificate() {
+ let loaded = BrowserTestUtils.waitForNewTab(gBrowser, null, true);
+ let viewCertButton = pageInfoDoc.getElementById("security-view-cert");
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(viewCertButton),
+ "view cert button should be visible."
+ );
+ viewCertButton.click();
+ await loaded;
+
+ await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () {
+ let certificateSection = await ContentTaskUtils.waitForCondition(() => {
+ return content.document.querySelector("certificate-section");
+ }, "Certificate section found");
+
+ let commonName = certificateSection.shadowRoot
+ .querySelector(".subject-name")
+ .shadowRoot.querySelector(".common-name")
+ .shadowRoot.querySelector(".info").textContent;
+ is(commonName, "example.com", "Should have the same common name.");
+ });
+
+ gBrowser.removeCurrentTab(); // closes about:certificate
+ }
+
+ await openAboutCertificate();
+
+ gBrowser.selectedTab = tab1;
+
+ await openAboutCertificate();
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(tab1);
+ BrowserTestUtils.removeTab(tab2);
+});
+
+// Test displaying website identity information when loading images.
+add_task(async function test_image() {
+ let url = TEST_PATH + "moz.png";
+ await BrowserTestUtils.openNewForegroundTab(gBrowser, url);
+
+ let pageInfo = BrowserPageInfo(url, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let pageInfoDoc = pageInfo.document;
+ let securityTab = pageInfoDoc.getElementById("securityTab");
+
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(securityTab),
+ "Security tab should be visible."
+ );
+
+ let owner = pageInfoDoc.getElementById("security-identity-owner-value");
+ let verifier = pageInfoDoc.getElementById("security-identity-verifier-value");
+ let domain = pageInfoDoc.getElementById("security-identity-domain-value");
+
+ await TestUtils.waitForCondition(
+ () => owner.value === "This website does not supply ownership information.",
+ `Value of owner should be should be "This website does not supply ownership information." instead got "${owner.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => verifier.value === "Mozilla Testing",
+ `Value of verifier should be "Mozilla Testing", instead got "${verifier.value}".`
+ );
+
+ let browser = gBrowser.selectedBrowser;
+
+ await TestUtils.waitForCondition(
+ () => domain.value === browser.currentURI.displayHost,
+ `Value of domain should be ${browser.currentURI.displayHost}, instead got "${domain.value}".`
+ );
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test displaying website identity information on certificate error pages.
+add_task(async function test_CertificateError() {
+ let browser;
+ let pageLoaded;
+ await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ () => {
+ gBrowser.selectedTab = BrowserTestUtils.addTab(
+ gBrowser,
+ TEST_ORIGIN_CERT_ERROR
+ );
+ browser = gBrowser.selectedBrowser;
+ pageLoaded = BrowserTestUtils.waitForErrorPage(browser);
+ },
+ false
+ );
+
+ await pageLoaded;
+
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN_CERT_ERROR, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let pageInfoDoc = pageInfo.document;
+ let securityTab = pageInfoDoc.getElementById("securityTab");
+
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(securityTab),
+ "Security tab should be visible."
+ );
+
+ let owner = pageInfoDoc.getElementById("security-identity-owner-value");
+ let verifier = pageInfoDoc.getElementById("security-identity-verifier-value");
+ let domain = pageInfoDoc.getElementById("security-identity-domain-value");
+
+ await TestUtils.waitForCondition(
+ () => owner.value === "This website does not supply ownership information.",
+ `Value of owner should be should be "This website does not supply ownership information." instead got "${owner.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => verifier.value === "Not specified",
+ `Value of verifier should be "Not specified", instead got "${verifier.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => domain.value === browser.currentURI.displayHost,
+ `Value of domain should be ${browser.currentURI.displayHost}, instead got "${domain.value}".`
+ );
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test displaying website identity information on http pages.
+add_task(async function test_SecurityHTTP() {
+ await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_HTTP_ORIGIN);
+
+ let pageInfo = BrowserPageInfo(TEST_HTTP_ORIGIN, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let pageInfoDoc = pageInfo.document;
+ let securityTab = pageInfoDoc.getElementById("securityTab");
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(securityTab),
+ "Security tab should be visible."
+ );
+
+ let owner = pageInfoDoc.getElementById("security-identity-owner-value");
+ let verifier = pageInfoDoc.getElementById("security-identity-verifier-value");
+ let domain = pageInfoDoc.getElementById("security-identity-domain-value");
+
+ await TestUtils.waitForCondition(
+ () => owner.value === "This website does not supply ownership information.",
+ `Value of owner should be should be "This website does not supply ownership information." instead got "${owner.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => verifier.value === "Not specified",
+ `Value of verifier should be "Not specified", instead got "${verifier.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => domain.value === gBrowser.selectedBrowser.currentURI.displayHost,
+ `Value of domain should be ${gBrowser.selectedBrowser.currentURI.displayHost}, instead got "${domain.value}".`
+ );
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test displaying valid certificate information in page info.
+add_task(async function test_ValidCert() {
+ await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_ORIGIN);
+
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let pageInfoDoc = pageInfo.document;
+ let securityTab = pageInfoDoc.getElementById("securityTab");
+ await TestUtils.waitForCondition(
+ () => BrowserTestUtils.is_visible(securityTab),
+ "Security tab should be visible."
+ );
+
+ let owner = pageInfoDoc.getElementById("security-identity-owner-value");
+ let verifier = pageInfoDoc.getElementById("security-identity-verifier-value");
+ let domain = pageInfoDoc.getElementById("security-identity-domain-value");
+
+ await TestUtils.waitForCondition(
+ () => owner.value === "This website does not supply ownership information.",
+ `Value of owner should be "This website does not supply ownership information.", got "${owner.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => verifier.value === "Mozilla Testing",
+ `Value of verifier should be "Mozilla Testing", got "${verifier.value}".`
+ );
+
+ await TestUtils.waitForCondition(
+ () => domain.value === gBrowser.selectedBrowser.currentURI.displayHost,
+ `Value of domain should be ${gBrowser.selectedBrowser.currentURI.displayHost}, instead got "${domain.value}".`
+ );
+
+ pageInfo.close();
+ BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});
+
+// Test displaying and removing quota managed data.
+add_task(async function test_SiteData() {
+ await SiteDataTestUtils.addToIndexedDB(TEST_ORIGIN);
+
+ await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function (browser) {
+ let totalUsage = await SiteDataTestUtils.getQuotaUsage(TEST_ORIGIN);
+ Assert.greater(totalUsage, 0, "The total usage should not be 0");
+
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+ let pageInfoDoc = pageInfo.document;
+
+ let label = pageInfoDoc.getElementById("security-privacy-sitedata-value");
+ let clearButton = pageInfoDoc.getElementById("security-clear-sitedata");
+
+ let size = DownloadUtils.convertByteUnits(totalUsage);
+
+ // The usage details are filled asynchronously, so we assert that they're present by
+ // waiting for them to be filled in.
+ // We only wait for the right unit to appear, since this number is intermittently
+ // varying by slight amounts on infra machines.
+ await TestUtils.waitForCondition(
+ () => label.textContent.includes(size[1]),
+ "Should show site data usage in the security section."
+ );
+ let siteDataUpdated = TestUtils.topicObserved(
+ "sitedatamanager:sites-updated"
+ );
+
+ let removeDialogPromise = BrowserTestUtils.promiseAlertDialogOpen(
+ "accept",
+ REMOVE_DIALOG_URL
+ );
+ clearButton.click();
+ await removeDialogPromise;
+
+ await siteDataUpdated;
+
+ totalUsage = await SiteDataTestUtils.getQuotaUsage(TEST_ORIGIN);
+ is(totalUsage, 0, "The total usage should be 0");
+
+ await TestUtils.waitForCondition(
+ () => label.textContent == "No",
+ "Should show no site data usage in the security section."
+ );
+
+ pageInfo.close();
+ });
+});
+
+// Test displaying and removing cookies.
+add_task(async function test_Cookies() {
+ // Add some test cookies.
+ SiteDataTestUtils.addToCookies({
+ origin: TEST_ORIGIN,
+ name: "test1",
+ value: "1",
+ });
+ SiteDataTestUtils.addToCookies({
+ origin: TEST_ORIGIN,
+ name: "test2",
+ value: "2",
+ });
+ SiteDataTestUtils.addToCookies({
+ origin: TEST_SUB_ORIGIN,
+ name: "test1",
+ value: "1",
+ });
+
+ await BrowserTestUtils.withNewTab(TEST_ORIGIN, async function (browser) {
+ let pageInfo = BrowserPageInfo(TEST_ORIGIN, "securityTab");
+ await BrowserTestUtils.waitForEvent(pageInfo, "load");
+
+ let pageInfoDoc = pageInfo.document;
+
+ let label = pageInfoDoc.getElementById("security-privacy-sitedata-value");
+ let clearButton = pageInfoDoc.getElementById("security-clear-sitedata");
+
+ // The usage details are filled asynchronously, so we assert that they're present by
+ // waiting for them to be filled in.
+ await TestUtils.waitForCondition(
+ () => label.textContent.includes("cookies"),
+ "Should show cookies in the security section."
+ );
+
+ let cookiesCleared = TestUtils.topicObserved(
+ "cookie-changed",
+ (subj, data) => data == "deleted"
+ );
+
+ let removeDialogPromise = BrowserTestUtils.promiseAlertDialogOpen(
+ "accept",
+ REMOVE_DIALOG_URL
+ );
+ clearButton.click();
+ await removeDialogPromise;
+
+ await cookiesCleared;
+
+ let uri = Services.io.newURI(TEST_ORIGIN);
+ is(
+ Services.cookies.countCookiesFromHost(uri.host),
+ 0,
+ "Cookies from the base domain should be cleared"
+ );
+
+ await TestUtils.waitForCondition(
+ () => label.textContent == "No",
+ "Should show no cookies in the security section."
+ );
+
+ pageInfo.close();
+ });
+});
+
+// Clean up in case we missed anything...
+add_task(async function cleanup() {
+ await SiteDataTestUtils.clear();
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_separate_private.js b/browser/base/content/test/pageinfo/browser_pageinfo_separate_private.js
new file mode 100644
index 0000000000..ac93b7ddb2
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_separate_private.js
@@ -0,0 +1,49 @@
+/**
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ **/
+
+add_task(async function () {
+ let tab = await BrowserTestUtils.openNewForegroundTab(
+ gBrowser,
+ "https://example.com"
+ );
+ let browser = tab.linkedBrowser;
+ let pageInfo = BrowserPageInfo(browser.currentURI.spec);
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+ Assert.strictEqual(
+ pageInfo.docShell.QueryInterface(Ci.nsILoadContext).usePrivateBrowsing,
+ false,
+ "non-private window opened private page info window"
+ );
+
+ let privateWindow = await BrowserTestUtils.openNewBrowserWindow({
+ private: true,
+ });
+ let privateTab = await BrowserTestUtils.openNewForegroundTab(
+ privateWindow.gBrowser,
+ "https://example.com"
+ );
+ let privateBrowser = privateTab.linkedBrowser;
+ let privatePageInfo = privateWindow.BrowserPageInfo(
+ privateBrowser.currentURI.spec
+ );
+ await BrowserTestUtils.waitForEvent(privatePageInfo, "page-info-init");
+ Assert.strictEqual(
+ privatePageInfo.docShell.QueryInterface(Ci.nsILoadContext)
+ .usePrivateBrowsing,
+ true,
+ "private window opened non-private page info window"
+ );
+
+ Assert.notEqual(
+ pageInfo,
+ privatePageInfo,
+ "private and non-private windows shouldn't have shared the same page info window"
+ );
+ pageInfo.close();
+ privatePageInfo.close();
+ BrowserTestUtils.removeTab(tab);
+ BrowserTestUtils.removeTab(privateTab);
+ await BrowserTestUtils.closeWindow(privateWindow);
+});
diff --git a/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js b/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js
new file mode 100644
index 0000000000..547c6158ad
--- /dev/null
+++ b/browser/base/content/test/pageinfo/browser_pageinfo_svg_image.js
@@ -0,0 +1,34 @@
+const URI =
+ "https://example.com/browser/browser/base/content/test/pageinfo/svg_image.html";
+
+add_task(async function () {
+ gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
+
+ BrowserTestUtils.loadURIString(gBrowser.selectedBrowser, URI);
+ await BrowserTestUtils.browserLoaded(gBrowser.selectedBrowser, false, URI);
+
+ const pageInfo = BrowserPageInfo(
+ gBrowser.selectedBrowser.currentURI.spec,
+ "mediaTab"
+ );
+ await BrowserTestUtils.waitForEvent(pageInfo, "page-info-init");
+
+ const imageTree = pageInfo.document.getElementById("imagetree");
+ const imageRowsNum = imageTree.view.rowCount;
+
+ ok(imageTree, "Image tree is null (media tab is broken)");
+
+ is(imageRowsNum, 1, "should have one image");
+
+ // Only bother running this if we've got the right number of rows.
+ if (imageRowsNum == 1) {
+ is(
+ imageTree.view.getCellText(0, imageTree.columns[0]),
+ "https://example.com/browser/browser/base/content/test/pageinfo/title_test.svg",
+ "The URL should be the svg image."
+ );
+ }
+
+ pageInfo.close();
+ gBrowser.removeCurrentTab();
+});
diff --git a/browser/base/content/test/pageinfo/iframes.html b/browser/base/content/test/pageinfo/iframes.html
new file mode 100644
index 0000000000..b29680cbd1
--- /dev/null
+++ b/browser/base/content/test/pageinfo/iframes.html
@@ -0,0 +1,8 @@
+<html>
+ <head>
+ <title>Test for media tab with iframe</title>
+ </head>
+ <body style='background-image:url(about:logo?a);'>
+ <iframe width="420" height="345" src="moz.png"></iframe>
+ </body>
+</html>");
diff --git a/browser/base/content/test/pageinfo/image.html b/browser/base/content/test/pageinfo/image.html
new file mode 100644
index 0000000000..1261be8e7b
--- /dev/null
+++ b/browser/base/content/test/pageinfo/image.html
@@ -0,0 +1,5 @@
+<html>
+ <img src='moz.png' height=100 width=150 id='test-image'>
+ <video src='video.ogg' id='test-video'></video>
+ <audio src='audio.ogg' id='test-audio'></audio>
+</html>
diff --git a/browser/base/content/test/pageinfo/svg_image.html b/browser/base/content/test/pageinfo/svg_image.html
new file mode 100644
index 0000000000..7ab17c33a0
--- /dev/null
+++ b/browser/base/content/test/pageinfo/svg_image.html
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html>
+ <head>
+ <title>Test for page info svg images</title>
+ </head>
+ <body>
+ <svg width="20" height="20">
+ <image xlink:href="title_test.svg" width="20" height="20">
+ </svg>
+ </body>
+</html>