summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js')
-rw-r--r--toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js b/toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js
new file mode 100644
index 0000000000..a37996c221
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/test_proxy_incognito.js
@@ -0,0 +1,95 @@
+"use strict";
+
+/* eslint no-unused-vars: ["error", {"args": "none", "varsIgnorePattern": "^(FindProxyForURL)$"}] */
+
+const server = createHttpServer({ hosts: ["example.com"] });
+
+server.registerPathHandler("/dummy", (request, response) => {
+ response.setStatusLine(request.httpVersion, 200, "OK");
+ response.setHeader("Content-Type", "text/html", false);
+ response.write("<!DOCTYPE html><html></html>");
+});
+
+add_task(async function test_incognito_proxy_onRequest_access() {
+ // This extension will fail if it gets a private request.
+ let extension = ExtensionTestUtils.loadExtension({
+ manifest: {
+ permissions: ["proxy", "<all_urls>"],
+ },
+ async background() {
+ browser.proxy.onRequest.addListener(
+ async details => {
+ browser.test.assertFalse(
+ details.incognito,
+ "incognito flag is not set"
+ );
+ browser.test.notifyPass("proxy.onRequest");
+ },
+ { urls: ["<all_urls>"], types: ["main_frame"] }
+ );
+
+ // Actual call arguments do not matter here.
+ await browser.test.assertRejects(
+ browser.proxy.settings.set({
+ value: {
+ proxyType: "none",
+ },
+ }),
+ /proxy.settings requires private browsing permission/,
+ "proxy.settings requires private browsing permission."
+ );
+
+ browser.test.sendMessage("ready");
+ },
+ });
+ await extension.startup();
+ await extension.awaitMessage("ready");
+
+ let pextension = ExtensionTestUtils.loadExtension({
+ incognitoOverride: "spanning",
+ manifest: {
+ permissions: ["proxy", "<all_urls>"],
+ },
+ background() {
+ browser.proxy.onRequest.addListener(
+ async details => {
+ browser.test.assertTrue(
+ details.incognito,
+ "incognito flag is set with filter"
+ );
+ browser.test.sendMessage("proxy.onRequest.private");
+ },
+ { urls: ["<all_urls>"], types: ["main_frame"], incognito: true }
+ );
+
+ browser.proxy.onRequest.addListener(
+ async details => {
+ browser.test.assertFalse(
+ details.incognito,
+ "incognito flag is not set with filter"
+ );
+ browser.test.notifyPass("proxy.onRequest.spanning");
+ },
+ { urls: ["<all_urls>"], types: ["main_frame"], incognito: false }
+ );
+ },
+ });
+ await pextension.startup();
+
+ let contentPage = await ExtensionTestUtils.loadContentPage(
+ "https://example.com/dummy",
+ { privateBrowsing: true }
+ );
+ await pextension.awaitMessage("proxy.onRequest.private");
+ await contentPage.close();
+
+ contentPage = await ExtensionTestUtils.loadContentPage(
+ "https://example.com/dummy"
+ );
+ await extension.awaitFinish("proxy.onRequest");
+ await pextension.awaitFinish("proxy.onRequest.spanning");
+ await contentPage.close();
+
+ await pextension.unload();
+ await extension.unload();
+});