From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../browser/browser_touchbar_searchrestrictions.js | 154 +++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 browser/components/touchbar/tests/browser/browser_touchbar_searchrestrictions.js (limited to 'browser/components/touchbar/tests/browser/browser_touchbar_searchrestrictions.js') diff --git a/browser/components/touchbar/tests/browser/browser_touchbar_searchrestrictions.js b/browser/components/touchbar/tests/browser/browser_touchbar_searchrestrictions.js new file mode 100644 index 0000000000..3a78e9a4b1 --- /dev/null +++ b/browser/components/touchbar/tests/browser/browser_touchbar_searchrestrictions.js @@ -0,0 +1,154 @@ +/* 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/. */ + +ChromeUtils.defineESModuleGetters(this, { + UrlbarUtils: "resource:///modules/UrlbarUtils.sys.mjs", + UrlbarTokenizer: "resource:///modules/UrlbarTokenizer.sys.mjs", +}); + +ChromeUtils.defineLazyGetter(this, "UrlbarTestUtils", () => { + const { UrlbarTestUtils: module } = ChromeUtils.importESModule( + "resource://testing-common/UrlbarTestUtils.sys.mjs" + ); + module.init(this); + return module; +}); + +XPCOMUtils.defineLazyServiceGetter( + this, + "TouchBarHelper", + "@mozilla.org/widget/touchbarhelper;1", + "nsITouchBarHelper" +); + +/** + * Tests the search restriction buttons in the Touch Bar. + */ + +/** + * @param {string} input + * The value to be inserted in the Urlbar. + * @param {UrlbarTokenizer.RESTRICT} token + * A restriction token corresponding to a Touch Bar button. + */ +async function searchAndCheckState({ input, token }) { + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: input, + }); + input = input.trimStart(); + if (Object.values(UrlbarTokenizer.RESTRICT).includes(input[0])) { + input = input.slice(1).trimStart(); + } + let searchMode = UrlbarUtils.searchModeForToken(token); + let expectedValue = searchMode ? input : `${token} ${input}`; + TouchBarHelper.insertRestrictionInUrlbar(token); + + if (searchMode) { + searchMode.entry = "touchbar"; + await UrlbarTestUtils.assertSearchMode(window, searchMode); + } + Assert.equal( + gURLBar.value, + expectedValue, + "The search restriction token should have been entered." + ); + + await UrlbarTestUtils.promisePopupClose(window); +} + +add_task(async function insertTokens() { + const tests = [ + { + input: "mozilla", + token: UrlbarTokenizer.RESTRICT.HISTORY, + }, + { + input: "mozilla", + token: UrlbarTokenizer.RESTRICT.BOOKMARK, + }, + { + input: "mozilla", + token: UrlbarTokenizer.RESTRICT.TAG, + }, + { + input: "mozilla", + token: UrlbarTokenizer.RESTRICT.OPENPAGE, + }, + ]; + for (let test of tests) { + await searchAndCheckState(test); + } +}); + +add_task(async function existingTokens() { + const tests = [ + { + input: "* mozilla", + token: UrlbarTokenizer.RESTRICT.HISTORY, + }, + { + input: "+ mozilla", + token: UrlbarTokenizer.RESTRICT.BOOKMARK, + }, + { + input: "( $ ^ mozilla", + token: UrlbarTokenizer.RESTRICT.TAG, + }, + { + input: "^*+%?#$ mozilla", + token: UrlbarTokenizer.RESTRICT.TAG, + }, + ]; + for (let test of tests) { + await searchAndCheckState(test); + } +}); + +add_task(async function stripSpaces() { + const tests = [ + { + input: " ^ mozilla", + token: UrlbarTokenizer.RESTRICT.HISTORY, + }, + { + input: " + mozilla ", + token: UrlbarTokenizer.RESTRICT.BOOKMARK, + }, + { + input: " moz illa ", + token: UrlbarTokenizer.RESTRICT.TAG, + }, + ]; + for (let test of tests) { + await searchAndCheckState(test); + } +}); + +add_task(async function clearURLs() { + const tests = [ + { + loadUrl: "http://example.com/", + token: UrlbarTokenizer.RESTRICT.HISTORY, + }, + { + loadUrl: "about:mozilla", + token: UrlbarTokenizer.RESTRICT.BOOKMARK, + }, + ]; + let win = BrowserWindowTracker.getTopWindow(); + await UrlbarTestUtils.promisePopupClose(win); + for (let { loadUrl, token } of tests) { + let browser = win.gBrowser.selectedBrowser; + let loadedPromise = BrowserTestUtils.browserLoaded(browser, false, loadUrl); + BrowserTestUtils.loadURIString(browser, loadUrl); + await loadedPromise; + if (win.gURLBar.getAttribute("pageproxystate") != "valid") { + await TestUtils.waitForCondition( + () => win.gURLBar.getAttribute("pageproxystate") == "valid" + ); + } + await searchAndCheckState({ input: "", token }); + } +}); -- cgit v1.2.3