summaryrefslogtreecommitdiffstats
path: root/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.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 /browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.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 'browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js')
-rw-r--r--browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js82
1 files changed, 82 insertions, 0 deletions
diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js
new file mode 100644
index 0000000000..af2c6aeb65
--- /dev/null
+++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_placestitle.js
@@ -0,0 +1,82 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+// This test makes sure that the title of existing history entries does not
+// change inside a private window.
+
+add_task(async function test() {
+ const TEST_URL =
+ "http://mochi.test:8888/browser/browser/components/" +
+ "privatebrowsing/test/browser/title.sjs";
+ let cm = Services.cookies;
+
+ function cleanup() {
+ // delete all cookies
+ cm.removeAll();
+ // delete all history items
+ return PlacesUtils.history.clear();
+ }
+
+ await cleanup();
+ registerCleanupFunction(cleanup);
+
+ let win = await BrowserTestUtils.openNewBrowserWindow();
+ registerCleanupFunction(async () => {
+ await BrowserTestUtils.closeWindow(win);
+ });
+
+ let promiseTitleChanged = PlacesTestUtils.waitForNotification(
+ "page-title-changed",
+ events => events[0].url == TEST_URL
+ );
+ await BrowserTestUtils.openNewForegroundTab(win.gBrowser, TEST_URL);
+ await promiseTitleChanged;
+ await BrowserTestUtils.waitForCondition(async function () {
+ let entry = await PlacesUtils.history.fetch(TEST_URL);
+ return entry && entry.title == "No Cookie";
+ }, "The page should be loaded without any cookie for the first time");
+
+ promiseTitleChanged = PlacesTestUtils.waitForNotification(
+ "page-title-changed",
+ events => events[0].url == TEST_URL
+ );
+ await BrowserTestUtils.openNewForegroundTab(win.gBrowser, TEST_URL);
+ await promiseTitleChanged;
+ await BrowserTestUtils.waitForCondition(async function () {
+ let entry = await PlacesUtils.history.fetch(TEST_URL);
+ return entry && entry.title == "Cookie";
+ }, "The page should be loaded with a cookie for the second time");
+
+ await cleanup();
+
+ promiseTitleChanged = PlacesTestUtils.waitForNotification(
+ "page-title-changed",
+ events => events[0].url == TEST_URL
+ );
+ await BrowserTestUtils.openNewForegroundTab(win.gBrowser, TEST_URL);
+ await promiseTitleChanged;
+ await BrowserTestUtils.waitForCondition(async function () {
+ let entry = await PlacesUtils.history.fetch(TEST_URL);
+ return entry && entry.title == "No Cookie";
+ }, "The page should be loaded without any cookie again");
+
+ // Reopen the page in a private browser window, it should not notify a title
+ // change.
+ let win2 = await BrowserTestUtils.openNewBrowserWindow({ private: true });
+ registerCleanupFunction(async () => {
+ let promisePBExit = TestUtils.topicObserved("last-pb-context-exited");
+ await BrowserTestUtils.closeWindow(win2);
+ await promisePBExit;
+ });
+
+ await BrowserTestUtils.openNewForegroundTab(win2.gBrowser, TEST_URL);
+ // Wait long enough to be sure history didn't set a title.
+ await new Promise(resolve => setTimeout(resolve, 1000));
+ is(
+ (await PlacesUtils.history.fetch(TEST_URL)).title,
+ "No Cookie",
+ "The title remains the same after visiting in private window"
+ );
+});