diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js b/browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js new file mode 100644 index 0000000000..d4addd380d --- /dev/null +++ b/browser/base/content/test/protectionsUI/browser_protectionsUI_shield_visibility.js @@ -0,0 +1,124 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/* This test checks pages of different URL variants (mostly differing in scheme) + * and verifies that the shield is only shown when content blocking can deal + * with the specific variant. */ + +const TEST_CASES = [ + { + type: "http", + // eslint-disable-next-line @microsoft/sdl/no-insecure-url + testURL: "http://example.com", + hidden: false, + }, + { + type: "https", + testURL: "https://example.com", + hidden: false, + }, + { + type: "chrome page", + testURL: "chrome://global/skin/in-content/info-pages.css", + hidden: true, + }, + { + type: "content-privileged about page", + testURL: "about:robots", + hidden: true, + }, + { + type: "non-chrome about page", + testURL: "about:about", + hidden: true, + }, + { + type: "chrome about page", + testURL: "about:preferences", + hidden: true, + }, + { + type: "file", + testURL: "benignPage.html", + hidden: true, + }, + { + type: "certificateError", + testURL: "https://self-signed.example.com", + hidden: true, + }, + { + type: "localhost", + testURL: "http://127.0.0.1", + hidden: false, + }, + { + type: "data URI", + testURL: "data:text/html,<div>", + hidden: true, + }, + { + type: "view-source HTTP", + testURL: "view-source:http://example.com/", + hidden: true, + }, + { + type: "view-source HTTPS", + testURL: "view-source:https://example.com/", + hidden: true, + }, + { + type: "top level sandbox", + testURL: + "https://example.com/browser/browser/base/content/test/protectionsUI/sandboxed.html", + hidden: false, + }, +]; + +add_task(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + // By default, proxies don't apply to 127.0.0.1. We need them to for this test, though: + ["network.proxy.allow_hijacking_localhost", true], + ], + }); + + for (let testData of TEST_CASES) { + info(`Testing for ${testData.type}`); + let testURL = testData.testURL; + + // Overwrite the url if it is testing the file url. + if (testData.type === "file") { + let dir = getChromeDir(getResolvedURI(gTestPath)); + dir.append(testURL); + dir.normalize(); + testURL = Services.io.newFileURI(dir).spec; + } + + let pageLoaded; + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + () => { + gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, testURL); + let browser = gBrowser.selectedBrowser; + if (testData.type === "certificateError") { + pageLoaded = BrowserTestUtils.waitForErrorPage(browser); + } else { + pageLoaded = BrowserTestUtils.browserLoaded(browser, true); + } + }, + false + ); + await pageLoaded; + + is( + BrowserTestUtils.isHidden( + gProtectionsHandler._trackingProtectionIconContainer + ), + testData.hidden, + "tracking protection icon container is correctly displayed" + ); + + BrowserTestUtils.removeTab(tab); + } +}); |