diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /toolkit/components/satchel/test/browser | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/satchel/test/browser')
4 files changed, 191 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..1d00bbf0ee --- /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.import( + "resource://gre/modules/FormHistory.jsm" +); + +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 new Promise(resolve => + FormHistory.update([{ op: "remove" }, ...mockHistory], { + handleCompletion: resolve, + }) + ); + 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..3cd17f7707 --- /dev/null +++ b/toolkit/components/satchel/test/browser/browser_popup_mouseover.js @@ -0,0 +1,68 @@ +/* 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.import( + "resource://gre/modules/FormHistory.jsm" +); + +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 new Promise(resolve => + FormHistory.update([{ op: "remove" }, ...mockHistory], { + handleCompletion: resolve, + }) + ); + 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" + ); + is(listItemElems.length, mockHistory.length, "ensure result length"); + is(autoCompletePopup.mousedOverIndex, -1, "mousedOverIndex should be -1"); + + // navigate to the first item + await BrowserTestUtils.synthesizeKey("VK_DOWN", {}, browser); + is(autoCompletePopup.selectedIndex, 0, "selectedIndex should be 0"); + + // mouseover the second item + EventUtils.synthesizeMouseAtCenter(listItemElems[1], { type: "mouseover" }); + await BrowserTestUtils.waitForCondition(() => { + return (autoCompletePopup.mousedOverIndex = 1); + }); + ok(true, "mousedOverIndex changed"); + is( + 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..2753d2050c --- /dev/null +++ b/toolkit/components/satchel/test/browser/browser_privbrowsing_perwindowpb.js @@ -0,0 +1,68 @@ +/* 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.import( + "resource://gre/modules/FormHistory.jsm" +); + +/** 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.loadURI(browser, testURI); + await BrowserTestUtils.browserLoaded(browser); + + // Wait for the page to reload itself. + await BrowserTestUtils.browserLoaded(browser); + + let count = 0; + let doneCounting = {}; + doneCounting.promise = new Promise( + resolve => (doneCounting.resolve = resolve) + ); + FormHistory.count( + { fieldname: "field", value: "value" }, + { + handleResult(result) { + count = result; + }, + handleError(error) { + Assert.ok(false, "Error occurred searching form history: " + error); + }, + handleCompletion(num) { + if (aShouldValueExist) { + is(count, 1, "In non-PB mode, we add a single entry"); + } else { + is(count, 0, "In PB mode, we don't add any entries"); + } + + doneCounting.resolve(); + }, + } + ); + await doneCounting.promise; + } + + 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)) + ); +}); |