summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/mochitest/test_ext_webnavigation_incognito.html
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/mochitest/test_ext_webnavigation_incognito.html
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/mochitest/test_ext_webnavigation_incognito.html')
-rw-r--r--toolkit/components/extensions/test/mochitest/test_ext_webnavigation_incognito.html105
1 files changed, 105 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/mochitest/test_ext_webnavigation_incognito.html b/toolkit/components/extensions/test/mochitest/test_ext_webnavigation_incognito.html
new file mode 100644
index 0000000000..45147365ee
--- /dev/null
+++ b/toolkit/components/extensions/test/mochitest/test_ext_webnavigation_incognito.html
@@ -0,0 +1,105 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Test for simple WebExtension</title>
+ <meta charset="utf-8">
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
+ <script src="/tests/SimpleTest/EventUtils.js"></script>
+ <script type="text/javascript" src="head.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+
+<script type="text/javascript">
+"use strict";
+
+add_task(async function webnav_test_incognito() {
+ // Monitor will fail if it gets any event.
+ let monitor = ExtensionTestUtils.loadExtension({
+ manifest: {
+ "permissions": ["webNavigation", "*://mochi.test/*"],
+ },
+ background() {
+ const EVENTS = [
+ "onTabReplaced",
+ "onBeforeNavigate",
+ "onCommitted",
+ "onDOMContentLoaded",
+ "onCompleted",
+ "onErrorOccurred",
+ "onReferenceFragmentUpdated",
+ "onHistoryStateUpdated",
+ ];
+
+ function onEvent(event, details) {
+ browser.test.fail(`not_allowed - Got ${event} ${details.url} ${details.frameId} ${details.parentFrameId}`);
+ }
+
+ let listeners = {};
+ for (let event of EVENTS) {
+ listeners[event] = onEvent.bind(null, event);
+ browser.webNavigation[event].addListener(listeners[event]);
+ }
+
+ browser.test.onMessage.addListener(async (message, tabId) => {
+ // try to access the private window
+ await browser.test.assertRejects(browser.webNavigation.getAllFrames({tabId}),
+ /Invalid tab ID/,
+ "should not be able to get incognito frames");
+ await browser.test.assertRejects(browser.webNavigation.getFrame({tabId, frameId: 0}),
+ /Invalid tab ID/,
+ "should not be able to get incognito frames");
+ browser.test.notifyPass("completed");
+ });
+ },
+ });
+
+ // extension loads a private window and waits for the onCompleted event.
+ let extension = ExtensionTestUtils.loadExtension({
+ incognitoOverride: "spanning",
+ manifest: {
+ permissions: ["tabs", "webNavigation", "*://mochi.test/*"],
+ },
+ async background() {
+ const BASE = "http://mochi.test:8888/tests/toolkit/components/extensions/test/mochitest";
+ const url = BASE + "/file_WebNavigation_page1.html";
+ let window;
+
+ browser.webNavigation.onCompleted.addListener(async (details) => {
+ if (details.url !== url) {
+ return;
+ }
+ browser.test.log(`spanning - Got onCompleted ${details.url} ${details.frameId} ${details.parentFrameId}`);
+ browser.test.sendMessage("completed");
+ });
+ browser.test.onMessage.addListener(async () => {
+ await browser.windows.remove(window.id);
+ browser.test.notifyPass("done");
+ });
+ window = await browser.windows.create({url, incognito: true});
+ let tabs = await browser.tabs.query({active: true, windowId: window.id});
+ browser.test.sendMessage("tabId", tabs[0].id);
+ },
+ });
+
+ await monitor.startup();
+ await extension.startup();
+
+ await extension.awaitMessage("completed");
+ let tabId = await extension.awaitMessage("tabId");
+
+ await monitor.sendMessage("tab", tabId);
+ await monitor.awaitFinish("completed");
+
+ await extension.sendMessage("close");
+ await extension.awaitFinish("done");
+
+ await extension.unload();
+ await monitor.unload();
+});
+
+</script>
+
+</body>
+</html>