summaryrefslogtreecommitdiffstats
path: root/toolkit/components/satchel/test/browser
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /toolkit/components/satchel/test/browser
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/satchel/test/browser')
-rw-r--r--toolkit/components/satchel/test/browser/browser.ini9
-rw-r--r--toolkit/components/satchel/test/browser/browser_close_tab.js46
-rw-r--r--toolkit/components/satchel/test/browser/browser_popup_mouseover.js81
-rw-r--r--toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js49
4 files changed, 185 insertions, 0 deletions
diff --git a/toolkit/components/satchel/test/browser/browser.ini b/toolkit/components/satchel/test/browser/browser.ini
new file mode 100644
index 0000000000..6e50b45e7e
--- /dev/null
+++ b/toolkit/components/satchel/test/browser/browser.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+support-files =
+ !/toolkit/components/satchel/test/subtst_privbrowsing.html
+
+[browser_close_tab.js]
+[browser_popup_mouseover.js]
+skip-if = verify
+[browser_privbrowsing_perwindowpb.js]
+skip-if = verify
diff --git a/toolkit/components/satchel/test/browser/browser_close_tab.js b/toolkit/components/satchel/test/browser/browser_close_tab.js
new file mode 100644
index 0000000000..37962d37d8
--- /dev/null
+++ b/toolkit/components/satchel/test/browser/browser_close_tab.js
@@ -0,0 +1,46 @@
+/* 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/. */
+
+const { FormHistory } = ChromeUtils.importESModule(
+ "resource://gre/modules/FormHistory.sys.mjs"
+);
+
+add_task(async function test() {
+ const url = `data:text/html,<input type="text" name="field1">`;
+
+ // Open a dummy tab.
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url },
+ async function (browser) {}
+ );
+
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url },
+ async function (browser) {
+ const { autoCompletePopup } = browser;
+ const mockHistory = [{ op: "add", fieldname: "field1", value: "value1" }];
+
+ await FormHistory.update([{ op: "remove" }, ...mockHistory]);
+ await SpecialPowers.spawn(browser, [], async function () {
+ const input = content.document.querySelector("input");
+
+ input.focus();
+ });
+
+ // show popup
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await TestUtils.waitForCondition(() => {
+ return autoCompletePopup.popupOpen;
+ });
+
+ gBrowser.removeCurrentTab();
+
+ await TestUtils.waitForCondition(() => {
+ return !autoCompletePopup.popupOpen;
+ });
+
+ Assert.ok(!autoCompletePopup.popupOpen, "Ensure the popup is closed.");
+ }
+ );
+});
diff --git a/toolkit/components/satchel/test/browser/browser_popup_mouseover.js b/toolkit/components/satchel/test/browser/browser_popup_mouseover.js
new file mode 100644
index 0000000000..2b293ab983
--- /dev/null
+++ b/toolkit/components/satchel/test/browser/browser_popup_mouseover.js
@@ -0,0 +1,81 @@
+/* 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/. */
+
+const { FormHistory } = ChromeUtils.importESModule(
+ "resource://gre/modules/FormHistory.sys.mjs"
+);
+
+add_task(async function test() {
+ const url = `data:text/html,<input type="text" name="field1">`;
+ await BrowserTestUtils.withNewTab(
+ { gBrowser, url },
+ async function (browser) {
+ const {
+ autoCompletePopup,
+ autoCompletePopup: { richlistbox: itemsBox },
+ } = browser;
+ const mockHistory = [
+ { op: "add", fieldname: "field1", value: "value1" },
+ { op: "add", fieldname: "field1", value: "value2" },
+ { op: "add", fieldname: "field1", value: "value3" },
+ { op: "add", fieldname: "field1", value: "value4" },
+ ];
+
+ await FormHistory.update([{ op: "remove" }, ...mockHistory]);
+ await SpecialPowers.spawn(browser, [], async function () {
+ const input = content.document.querySelector("input");
+
+ input.focus();
+ });
+
+ // show popup
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ await BrowserTestUtils.waitForCondition(() => {
+ return autoCompletePopup.popupOpen;
+ });
+ const listItemElems = itemsBox.querySelectorAll(
+ ".autocomplete-richlistitem"
+ );
+ Assert.equal(
+ listItemElems.length,
+ mockHistory.length,
+ "ensure result length"
+ );
+ Assert.equal(
+ autoCompletePopup.mousedOverIndex,
+ -1,
+ "mousedOverIndex should be -1"
+ );
+
+ // navigate to the first item
+ await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser);
+ Assert.equal(
+ autoCompletePopup.selectedIndex,
+ 0,
+ "selectedIndex should be 0"
+ );
+
+ // mouseover the second item
+ EventUtils.synthesizeMouseAtCenter(listItemElems[1], {
+ type: "mouseover",
+ });
+ await BrowserTestUtils.waitForCondition(() => {
+ return (autoCompletePopup.mousedOverIndex = 1);
+ });
+ Assert.ok(true, "mousedOverIndex changed");
+ Assert.equal(
+ autoCompletePopup.selectedIndex,
+ 0,
+ "selectedIndex should not be changed by mouseover"
+ );
+
+ // close popup
+ await SpecialPowers.spawn(browser, [], async function () {
+ const input = content.document.querySelector("input");
+
+ input.blur();
+ });
+ }
+ );
+});
diff --git a/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js b/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js
new file mode 100644
index 0000000000..9614fd8f15
--- /dev/null
+++ b/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js
@@ -0,0 +1,49 @@
+/* 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/. */
+
+var { FormHistory } = ChromeUtils.importESModule(
+ "resource://gre/modules/FormHistory.sys.mjs"
+);
+
+/** Test for Bug 472396 */
+add_task(async function test() {
+ // initialization
+ let windowsToClose = [];
+ let testURI =
+ "http://example.com/tests/toolkit/components/satchel/test/subtst_privbrowsing.html";
+
+ async function doTest(aShouldValueExist, aWindow) {
+ let browser = aWindow.gBrowser.selectedBrowser;
+ BrowserTestUtils.loadURIString(browser, testURI);
+ await BrowserTestUtils.browserLoaded(browser);
+
+ // Wait for the page to reload itself.
+ await BrowserTestUtils.browserLoaded(browser);
+
+ let count = await FormHistory.count({ fieldname: "field", value: "value" });
+
+ if (aShouldValueExist) {
+ Assert.equal(count, 1, "In non-PB mode, we add a single entry");
+ } else {
+ Assert.equal(count, 0, "In PB mode, we don't add any entries");
+ }
+ }
+
+ function testOnWindow(aOptions, aCallback) {
+ return BrowserTestUtils.openNewBrowserWindow(aOptions).then(win => {
+ windowsToClose.push(win);
+ return win;
+ });
+ }
+
+ await testOnWindow({ private: true }).then(aWin => doTest(false, aWin));
+
+ // Test when not on private mode after visiting a site on private
+ // mode. The form history should not exist.
+ await testOnWindow({}).then(aWin => doTest(true, aWin));
+
+ await Promise.all(
+ windowsToClose.map(win => BrowserTestUtils.closeWindow(win))
+ );
+});