diff options
Diffstat (limited to 'browser/components/urlbar/tests/browser')
47 files changed, 661 insertions, 123 deletions
diff --git a/browser/components/urlbar/tests/browser/browser.toml b/browser/components/urlbar/tests/browser/browser.toml index a77a831fab..b9934aa838 100644 --- a/browser/components/urlbar/tests/browser/browser.toml +++ b/browser/components/urlbar/tests/browser/browser.toml @@ -314,7 +314,6 @@ support-files = [ ["browser_oneOffs_heuristicRestyle.js"] skip-if = [ "os == 'linux' && bits == 64 && !debug", # Bug 1775811 - "a11y_checks", # Bugs 1858041 and 1854661 to investigate intermittent a11y_checks results ] ["browser_oneOffs_keyModifiers.js"] @@ -596,6 +595,8 @@ https_first_disabled = true ["browser_top_sites_private.js"] https_first_disabled = true +["browser_top_sites_switchtab.js"] + ["browser_typed_value.js"] ["browser_unitConversion.js"] diff --git a/browser/components/urlbar/tests/browser/browser_acknowledgeFeedbackAndDismissal.js b/browser/components/urlbar/tests/browser/browser_acknowledgeFeedbackAndDismissal.js index 5ad8dfc75d..8c4b05501e 100644 --- a/browser/components/urlbar/tests/browser/browser_acknowledgeFeedbackAndDismissal.js +++ b/browser/components/urlbar/tests/browser/browser_acknowledgeFeedbackAndDismissal.js @@ -7,6 +7,10 @@ "use strict"; +// See the comment in the setup task for the expected index of the main test +// result. +const RESULT_INDEX = 2; + // The command that dismisses a single result. const DISMISS_ONE_COMMAND = "dismiss-one"; @@ -20,18 +24,40 @@ const FEEDBACK_COMMAND = "show_less_frequently"; let gTestProvider; add_setup(async function () { + // This test expects the following results in the following order: + // + // 1. The heuristic + // 2. A history result + // 3. A result from our test provider. This will be the main result we'll use + // during this test. + // 4. Another history result + // + // This ensures a couple things: + // + // * The main test result has rows above and below it. Feedback and dismissal + // acknowledgments in the main result row should not affect adjacent rows, + // except that when the dismissal acknowledgment itself is dismissed, it + // should be replaced by the row below it. + // * The main result does not have a row label (a.k.a. group label). There's a + // separate task that specifically checks the row label, and that way this + // test covers both cases, where the row does and does not have a row label. gTestProvider = new TestProvider({ results: [ - new UrlbarResult( - UrlbarUtils.RESULT_TYPE.URL, - UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, - { - url: "https://example.com/", - isBlockable: true, - blockL10n: { - id: "urlbar-result-menu-dismiss-firefox-suggest", - }, - } + Object.assign( + new UrlbarResult( + UrlbarUtils.RESULT_TYPE.URL, + UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, + { + url: "https://example.com/", + isBlockable: true, + blockL10n: { + id: "urlbar-result-menu-dismiss-firefox-suggest", + }, + } + ), + // This ensures the result is sandwiched between the two history results + // in the Firefox Suggest group. + { suggestedIndex: 1, isSuggestedIndexRelativeToGroup: true } ), ], }); @@ -39,13 +65,15 @@ add_setup(async function () { gTestProvider.commandCount = {}; UrlbarProvidersManager.registerProvider(gTestProvider); - // Add a visit so that there's one result above the test result (the - // heuristic) and one below (the visit) just to make sure removing the test - // result doesn't mess up adjacent results. await PlacesUtils.history.clear(); await PlacesUtils.bookmarks.eraseEverything(); await UrlbarTestUtils.formHistory.clear(); - await PlacesTestUtils.addVisits("https://example.com/aaa"); + + // Add visits for the two history results. + await PlacesTestUtils.addVisits([ + "https://example.com/aaa", + "https://example.com/bbb", + ]); registerCleanupFunction(() => { UrlbarProvidersManager.unregisterProvider(gTestProvider); @@ -72,13 +100,9 @@ add_task(async function acknowledgeDismissal_rowSelected() { }); // Select the row. - let resultIndex = await getTestResultIndex(); - while (gURLBar.view.selectedRowIndex != resultIndex) { - this.EventUtils.synthesizeKey("KEY_ArrowDown"); - } + gURLBar.view.selectedRowIndex = RESULT_INDEX; await doDismissTest({ - resultIndex, command: DISMISS_ONE_COMMAND, shouldBeSelected: true, }); @@ -95,12 +119,14 @@ add_task(async function acknowledgeFeedbackAndDismissal() { value: "test", }); - let resultIndex = await getTestResultIndex(); - let details = await UrlbarTestUtils.getDetailsOfResultAt(window, resultIndex); + let details = await UrlbarTestUtils.getDetailsOfResultAt( + window, + RESULT_INDEX + ); // Click the feedback command. await UrlbarTestUtils.openResultMenuAndClickItem(window, FEEDBACK_COMMAND, { - resultIndex, + resultIndex: RESULT_INDEX, }); Assert.equal( @@ -121,7 +147,6 @@ add_task(async function acknowledgeFeedbackAndDismissal() { info("Doing dismissal"); await doDismissTest({ - resultIndex, command: DISMISS_ONE_COMMAND, shouldBeSelected: true, }); @@ -139,6 +164,29 @@ add_task(async function acknowledgeDismissal_all() { }); }); +// When a row with a row label (a.k.a. group label) is dismissed, the dismissal +// acknowledgment tip should retain the label. When the tip is then dismissed, +// the row that replaces it should also retain the label. +add_task(async function acknowledgeDismissal_rowLabel() { + // Show the result as the first row in the Firefox Suggest section so that it + // has the "Firefox Suggest" group label. + let { suggestedIndex } = gTestProvider.results[0]; + gTestProvider.results[0].suggestedIndex = 0; + + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "test", + }); + await doDismissTest({ + resultIndex: 1, + command: DISMISS_ALL_COMMAND, + shouldBeSelected: false, + expectedLabel: "Firefox Suggest", + }); + + gTestProvider.results[0].suggestedIndex = suggestedIndex; +}); + /** * Does a dismissal test: * @@ -158,10 +206,25 @@ add_task(async function acknowledgeDismissal_all() { * @param {number} options.resultIndex * The index of the test result, if known beforehand. Leave -1 to find it * automatically. + * @param {string} options.expectedLabel + * The row label (a.k.a. group label) the row is expected to have. This should + * be the expected translated en-US string, not an l10n object. If null, the + * row is expected not to have a row label at all. */ -async function doDismissTest({ command, shouldBeSelected, resultIndex = -1 }) { - if (resultIndex < 0) { - resultIndex = await getTestResultIndex(); +async function doDismissTest({ + command, + shouldBeSelected, + resultIndex = 2, + expectedLabel = null, +}) { + let details = await UrlbarTestUtils.getDetailsOfResultAt(window, resultIndex); + Assert.equal( + details.result.providerName, + gTestProvider.name, + "The test result should be at the expected index" + ); + if (details.result.providerName != gTestProvider.name) { + return; } let selectedElement = gURLBar.view.selectedElement; @@ -181,6 +244,9 @@ async function doDismissTest({ command, shouldBeSelected, resultIndex = -1 }) { ); } + info("Checking the row label on the original row"); + await checkRowLabel(resultIndex, expectedLabel); + let resultCount = UrlbarTestUtils.getResultCount(window); // Click the command. @@ -204,7 +270,7 @@ async function doDismissTest({ command, shouldBeSelected, resultIndex = -1 }) { "The result count should not haved changed after dismissal" ); - let details = await UrlbarTestUtils.getDetailsOfResultAt(window, resultIndex); + details = await UrlbarTestUtils.getDetailsOfResultAt(window, resultIndex); Assert.equal( details.type, UrlbarUtils.RESULT_TYPE.TIP, @@ -235,6 +301,9 @@ async function doDismissTest({ command, shouldBeSelected, resultIndex = -1 }) { "Row should not have feedback acknowledgment after dismissal" ); + info("Checking the row label on the dismissal acknowledgment tip"); + await checkRowLabel(resultIndex, expectedLabel); + // Get the dismissal acknowledgment's "Got it" button. let gotItButton = UrlbarTestUtils.getButtonForResultIndex( window, @@ -284,6 +353,11 @@ async function doDismissTest({ command, shouldBeSelected, resultIndex = -1 }) { ); } + info( + "Checking the row label on the row that replaced the dismissal acknowledgment tip" + ); + await checkRowLabel(resultIndex, expectedLabel); + await UrlbarTestUtils.promisePopupClose(window); } @@ -291,7 +365,7 @@ async function doDismissTest({ command, shouldBeSelected, resultIndex = -1 }) { * A provider that acknowledges feedback and dismissals. */ class TestProvider extends UrlbarTestUtils.TestProvider { - getResultCommands(result) { + getResultCommands(_result) { // The l10n values aren't important. return [ { @@ -347,15 +421,27 @@ class TestProvider extends UrlbarTestUtils.TestProvider { } } -async function getTestResultIndex() { - let index = 0; - let resultCount = UrlbarTestUtils.getResultCount(window); - for (; index < resultCount; index++) { - let details = await UrlbarTestUtils.getDetailsOfResultAt(window, index); - if (details.result.providerName == gTestProvider.name) { - break; - } +async function checkRowLabel(resultIndex, expectedLabel) { + let details = await UrlbarTestUtils.getDetailsOfResultAt(window, resultIndex); + let { row } = details.element; + let before = getComputedStyle(row, "::before"); + + if (expectedLabel) { + Assert.equal( + before.content, + "attr(label)", + "::before content should use the row label" + ); + Assert.equal( + row.getAttribute("label"), + expectedLabel, + "Row should have the expected label attribute" + ); + } else { + Assert.equal(before.content, "none", "::before content should be 'none'"); + Assert.ok( + !row.hasAttribute("label"), + "Row should not have a label attribute" + ); } - Assert.less(index, resultCount, "The test result should be present"); - return index; } diff --git a/browser/components/urlbar/tests/browser/browser_add_search_engine.js b/browser/components/urlbar/tests/browser/browser_add_search_engine.js index cfcaccfdd5..5ee41649ba 100644 --- a/browser/components/urlbar/tests/browser/browser_add_search_engine.js +++ b/browser/components/urlbar/tests/browser/browser_add_search_engine.js @@ -85,9 +85,6 @@ add_task(async function context_one() { add_task(async function context_invalid() { info("Checks the context menu with a page that offers an invalid engine."); - await SpecialPowers.pushPrefEnv({ - set: [["prompts.contentPromptSubDialog", false]], - }); let url = getRootDirectory(gTestPath) + "add_search_engine_invalid.html"; await BrowserTestUtils.withNewTab(url, async tab => { @@ -321,5 +318,5 @@ function promiseEngine(expectedData, expectedEngineName) { expectedEngineName == engine.wrappedJSObject.name ); } - ).then(([engine, data]) => engine); + ).then(([engine]) => engine); } diff --git a/browser/components/urlbar/tests/browser/browser_autoOpen.js b/browser/components/urlbar/tests/browser/browser_autoOpen.js index bfe491fc61..19035e4149 100644 --- a/browser/components/urlbar/tests/browser/browser_autoOpen.js +++ b/browser/components/urlbar/tests/browser/browser_autoOpen.js @@ -41,7 +41,7 @@ add_setup(async function () { add_task(async function test() { await BrowserTestUtils.withNewTab( { gBrowser, url: "about:blank" }, - async browser => { + async () => { await checkOpensOnFocus(); } ); diff --git a/browser/components/urlbar/tests/browser/browser_bestMatch.js b/browser/components/urlbar/tests/browser/browser_bestMatch.js index 21c97405a6..a21f81dfee 100644 --- a/browser/components/urlbar/tests/browser/browser_bestMatch.js +++ b/browser/components/urlbar/tests/browser/browser_bestMatch.js @@ -117,11 +117,7 @@ add_task(async function keySelection() { }); }); -async function checkBestMatchRow({ - result, - isSponsored = false, - hasHelpUrl = false, -}) { +async function checkBestMatchRow({ result, hasHelpUrl = false }) { Assert.equal( UrlbarTestUtils.getResultCount(window), 1, diff --git a/browser/components/urlbar/tests/browser/browser_blanking.js b/browser/components/urlbar/tests/browser/browser_blanking.js index f68c4d894a..b5ec976eac 100644 --- a/browser/components/urlbar/tests/browser/browser_blanking.js +++ b/browser/components/urlbar/tests/browser/browser_blanking.js @@ -46,7 +46,7 @@ add_task(async function () { await SpecialPowers.spawn(tab.linkedBrowser, [], async function () { // This is sync, so by the time we return we should have changed the URL bar. content.location.reload(); - }).catch(e => { + }).catch(() => { // Ignore expected exception. }); is( diff --git a/browser/components/urlbar/tests/browser/browser_clipboard.js b/browser/components/urlbar/tests/browser/browser_clipboard.js index f6127ef8d9..2332f595cc 100644 --- a/browser/components/urlbar/tests/browser/browser_clipboard.js +++ b/browser/components/urlbar/tests/browser/browser_clipboard.js @@ -19,8 +19,10 @@ add_setup(async function () { ["browser.urlbar.suggest.clipboard", true], ], }); - registerCleanupFunction(() => { + + registerCleanupFunction(async () => { SpecialPowers.clipboardCopyString(""); + await PlacesUtils.history.clear(); }); }); @@ -52,7 +54,7 @@ add_task(async function testFormattingOfClipboardSuggestion() { await BrowserTestUtils.withNewTab( { gBrowser, url: "about:home" }, - async browser => { + async () => { let { result } = await searchEmptyStringAndGetFirstRow(); Assert.equal( @@ -73,6 +75,7 @@ add_task(async function testFormattingOfClipboardSuggestion() { } ); }); + // Verifies that a valid URL copied to the clipboard results in the // display of a corresponding suggestion in the URL bar as the first // suggestion with accurate URL and icon. Also ensures that engaging @@ -121,6 +124,7 @@ add_task(async function testUserEngagementWithClipboardSuggestion() { await checkClipboardSuggestionAbsent(0); } ); + await PlacesUtils.history.clear(); }); // This test confirms that dismissing the result from the result menu @@ -347,3 +351,38 @@ add_task(async function testScalarAndStopWatchTelemetry() { } ); }); + +add_task(async function emptySearch_withClipboardEntry() { + SpecialPowers.clipboardCopyString("https://example.com/1"); + const MAX_RESULTS = 3; + let expectedHistoryResults = []; + + for (let i = 0; i < MAX_RESULTS; i++) { + await PlacesTestUtils.addVisits([`http://mochi.test/${i}`]); + expectedHistoryResults.push(`http://mochi.test/${i}`); + } + + await BrowserTestUtils.withNewTab("about:robots", async function () { + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "", + }); + await UrlbarTestUtils.enterSearchMode(window, { + source: UrlbarUtils.RESULT_SOURCE.HISTORY, + }); + + let urls = []; + + for (let i = 0; i < UrlbarTestUtils.getResultCount(window); i++) { + let url = (await UrlbarTestUtils.getDetailsOfResultAt(window, i)).url; + urls.push(url); + } + + urls.reverse(); + Assert.deepEqual(expectedHistoryResults, urls); + + await UrlbarTestUtils.exitSearchMode(window, { clickClose: true }); + await UrlbarTestUtils.promisePopupClose(window); + }); + await PlacesUtils.history.clear(); +}); diff --git a/browser/components/urlbar/tests/browser/browser_copy_during_load.js b/browser/components/urlbar/tests/browser/browser_copy_during_load.js index 4a81ff08be..3eaa53bcda 100644 --- a/browser/components/urlbar/tests/browser/browser_copy_during_load.js +++ b/browser/components/urlbar/tests/browser/browser_copy_during_load.js @@ -13,7 +13,7 @@ add_task(async function () { "http://www.example.com" ) + "slow-page.sjs"; - await BrowserTestUtils.withNewTab(gBrowser, async tab => { + await BrowserTestUtils.withNewTab(gBrowser, async () => { gURLBar.focus(); gURLBar.value = SLOW_PAGE; let promise = TestUtils.waitForCondition( diff --git a/browser/components/urlbar/tests/browser/browser_copying.js b/browser/components/urlbar/tests/browser/browser_copying.js index 111df58fd1..d9ad6ebaaf 100644 --- a/browser/components/urlbar/tests/browser/browser_copying.js +++ b/browser/components/urlbar/tests/browser/browser_copying.js @@ -727,7 +727,7 @@ add_task(async function loadingPageInBlank() { async function waitForNewTabWithLoadRequest() { return new Promise(resolve => gBrowser.addTabsProgressListener({ - onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags, aStatus) { + onStateChange(aBrowser, aWebProgress, aRequest, aStateFlags) { if (aStateFlags & Ci.nsIWebProgressListener.STATE_START) { gBrowser.removeTabsProgressListener(this); resolve(gBrowser.getTabForBrowser(aBrowser)); diff --git a/browser/components/urlbar/tests/browser/browser_dragdropURL.js b/browser/components/urlbar/tests/browser/browser_dragdropURL.js index 52c19e8965..1e194ee6af 100644 --- a/browser/components/urlbar/tests/browser/browser_dragdropURL.js +++ b/browser/components/urlbar/tests/browser/browser_dragdropURL.js @@ -43,7 +43,7 @@ function simulateURLBarDrop(content) { } add_task(async function checkDragURL() { - await BrowserTestUtils.withNewTab(TEST_URL, function (browser) { + await BrowserTestUtils.withNewTab(TEST_URL, function () { info("Check dragging a normal url to the urlbar"); const DRAG_URL = "http://www.example.com/"; simulateURLBarDrop({ type: "text/plain", data: DRAG_URL }); @@ -61,7 +61,7 @@ add_task(async function checkDragURL() { }); add_task(async function checkDragForbiddenURL() { - await BrowserTestUtils.withNewTab(TEST_URL, function (browser) { + await BrowserTestUtils.withNewTab(TEST_URL, function () { // See also browser_removeUnsafeProtocolsFromURLBarPaste.js for other // examples. In general we trust that function, we pick some testcases to // ensure we disallow dropping trimmed text. diff --git a/browser/components/urlbar/tests/browser/browser_dynamicResults.js b/browser/components/urlbar/tests/browser/browser_dynamicResults.js index 976ae3b9cb..aad15e0145 100644 --- a/browser/components/urlbar/tests/browser/browser_dynamicResults.js +++ b/browser/components/urlbar/tests/browser/browser_dynamicResults.js @@ -580,7 +580,7 @@ add_task(async function highlighting() { addCallback(this, result); } - getViewUpdate(result, idsByName) { + getViewUpdate(_result, _idsByName) { return {}; } } @@ -617,7 +617,7 @@ add_task(async function highlighting() { * Provides a dynamic result with highlighted text that is then overridden. */ class TestHighlightProviderOveridden extends TestHighlightProvider { - getViewUpdate(result, idsByName) { + getViewUpdate(_result, _idsByName) { return { text: { textContent: "Test title", @@ -904,7 +904,7 @@ class TestProvider extends UrlbarTestUtils.TestProvider { }; } - onEngagement(state, queryContext, details, controller) { + onEngagement(state, queryContext, details, _controller) { if (this._pickPromiseResolve) { let { result, element } = details; this._pickPromiseResolve([result, element]); diff --git a/browser/components/urlbar/tests/browser/browser_groupLabels.js b/browser/components/urlbar/tests/browser/browser_groupLabels.js index 2b43990b77..d04b6bc194 100644 --- a/browser/components/urlbar/tests/browser/browser_groupLabels.js +++ b/browser/components/urlbar/tests/browser/browser_groupLabels.js @@ -139,7 +139,7 @@ add_task(async function generalBeforeSuggestions() { add_task(async function generalBeforeSuggestions_suggestionsOnly() { await PlacesUtils.history.clear(); - await withSuggestions(async engine => { + await withSuggestions(async () => { await SpecialPowers.pushPrefEnv({ set: [[SUGGESTIONS_FIRST_PREF, false]], }); @@ -196,7 +196,7 @@ add_task(async function suggestedIndex_only() { let provider = new SuggestedIndexProvider(index); UrlbarProvidersManager.registerProvider(provider); - await withSuggestions(async engine => { + await withSuggestions(async () => { await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, value: "test", diff --git a/browser/components/urlbar/tests/browser/browser_locationBarCommand.js b/browser/components/urlbar/tests/browser/browser_locationBarCommand.js index 670b9741f4..84c45e586a 100644 --- a/browser/components/urlbar/tests/browser/browser_locationBarCommand.js +++ b/browser/components/urlbar/tests/browser/browser_locationBarCommand.js @@ -299,7 +299,7 @@ async function triggerCommand(eventType, details = {}) { function promiseLoadStarted() { return new Promise(resolve => { gBrowser.addTabsProgressListener({ - onStateChange(browser, webProgress, req, flags, status) { + onStateChange(browser, webProgress, req, flags) { if (flags & Ci.nsIWebProgressListener.STATE_START) { gBrowser.removeTabsProgressListener(this); resolve(); diff --git a/browser/components/urlbar/tests/browser/browser_locationBarExternalLoad.js b/browser/components/urlbar/tests/browser/browser_locationBarExternalLoad.js index 5a44db54ce..13457db52e 100644 --- a/browser/components/urlbar/tests/browser/browser_locationBarExternalLoad.js +++ b/browser/components/urlbar/tests/browser/browser_locationBarExternalLoad.js @@ -52,7 +52,7 @@ function promiseLoaded(browser) { }); } -async function testURL(url, loadFunc, endFunc) { +async function testURL(url, loadFunc) { let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser); let browser = tab.linkedBrowser; @@ -70,7 +70,7 @@ async function testURL(url, loadFunc, endFunc) { await SpecialPowers.spawn( browser, [{ isRemote: gMultiProcessBrowser }], - async function (arg) { + async function () { Assert.equal( Services.focus.focusedElement, null, diff --git a/browser/components/urlbar/tests/browser/browser_locationchange_urlbar_edit_dos.js b/browser/components/urlbar/tests/browser/browser_locationchange_urlbar_edit_dos.js index b50446a4c9..4e91069b4a 100644 --- a/browser/components/urlbar/tests/browser/browser_locationchange_urlbar_edit_dos.js +++ b/browser/components/urlbar/tests/browser/browser_locationchange_urlbar_edit_dos.js @@ -5,7 +5,7 @@ const TEST_URL = `${TEST_BASE_URL}file_urlbar_edit_dos.html`; -async function checkURLBarValueStays(browser) { +async function checkURLBarValueStays() { gURLBar.select(); EventUtils.sendString("a"); is(gURLBar.value, "a", "URL bar value should match after sending a key"); diff --git a/browser/components/urlbar/tests/browser/browser_oneOffs_heuristicRestyle.js b/browser/components/urlbar/tests/browser/browser_oneOffs_heuristicRestyle.js index 8f7f058dd8..6badfca72e 100644 --- a/browser/components/urlbar/tests/browser/browser_oneOffs_heuristicRestyle.js +++ b/browser/components/urlbar/tests/browser/browser_oneOffs_heuristicRestyle.js @@ -188,7 +188,7 @@ async function heuristicIsRestyled( if (engine) { Assert.equal( resultDetails.image, - engine.getIconURL() || UrlbarUtils.ICON.SEARCH_GLASS, + (await engine.getIconURL()) || UrlbarUtils.ICON.SEARCH_GLASS, "The restyled result's icon should be the engine's icon." ); } else if (source) { diff --git a/browser/components/urlbar/tests/browser/browser_oneOffs_settings.js b/browser/components/urlbar/tests/browser/browser_oneOffs_settings.js index b4b1e7006e..2def88b5f9 100644 --- a/browser/components/urlbar/tests/browser/browser_oneOffs_settings.js +++ b/browser/components/urlbar/tests/browser/browser_oneOffs_settings.js @@ -36,7 +36,7 @@ add_setup(async function () { async function selectSettings(win, activateFn) { await BrowserTestUtils.withNewTab( { gBrowser: win.gBrowser, url: "about:blank" }, - async browser => { + async () => { await UrlbarTestUtils.promiseAutocompleteResultPopup({ window: win, value: "example.com", diff --git a/browser/components/urlbar/tests/browser/browser_recentsearches.js b/browser/components/urlbar/tests/browser/browser_recentsearches.js index e0ba5f684f..d2b91a3a53 100644 --- a/browser/components/urlbar/tests/browser/browser_recentsearches.js +++ b/browser/components/urlbar/tests/browser/browser_recentsearches.js @@ -6,10 +6,51 @@ const CONFIG_DEFAULT = [ { webExtension: { id: "basic@search.mozilla.org" }, appliesTo: [{ included: { everywhere: true } }], + urls: { + trending: { + fullPath: + "https://example.com/browser/browser/components/search/test/browser/trendingSuggestionEngine.sjs", + query: "", + }, + }, default: "yes", }, ]; +const CONFIG_DEFAULT_V2 = [ + { + recordType: "engine", + identifier: "basic", + base: { + name: "basic", + urls: { + search: { + base: "https://example.com", + searchTermParamName: "q", + }, + trending: { + base: "https://example.com/browser/browser/components/search/test/browser/trendingSuggestionEngine.sjs", + method: "GET", + }, + }, + }, + variants: [ + { + environment: { allRegionsAndLocales: true }, + }, + ], + }, + { + recordType: "defaultEngines", + globalDefault: "basic", + specificDefaults: [], + }, + { + recordType: "engineOrders", + orders: [], + }, +]; + const TOP_SITES = [ "https://example-1.com/", "https://example-2.com/", @@ -38,7 +79,9 @@ add_setup(async () => { }); SearchTestUtils.useMockIdleService(); - await SearchTestUtils.updateRemoteSettingsConfig(CONFIG_DEFAULT); + await SearchTestUtils.updateRemoteSettingsConfig( + SearchUtils.newSearchConfigEnabled ? CONFIG_DEFAULT_V2 : CONFIG_DEFAULT + ); Services.telemetry.clearScalars(); registerCleanupFunction(async () => { @@ -135,4 +178,53 @@ add_task(async () => { Assert.equal(result.providerName, "RecentSearches"); await BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); +}); + +// Test that triggering the help menu of trending suggestions does not +// record that selection as a search. +add_task(async () => { + await UrlbarTestUtils.formHistory.clear(); + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.urlbar.suggest.topsites", false], + ["browser.urlbar.suggest.trending", true], + ["browser.urlbar.trending.featureGate", true], + ["browser.urlbar.trending.requireSearchMode", false], + ["app.support.baseURL", "https://example.com"], + ], + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + window.gBrowser, + "data:text/html," + ); + + info("Open the urlbar and pick the help menu of a trending result."); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "", + }); + + await UrlbarTestUtils.openResultMenuAndClickItem(window, "help", { + resultIndex: 1, + openByMouse: true, + }); + + info("Open the urlbar and check that a recent search has not been added."); + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "", + }); + + let { result } = await UrlbarTestUtils.getDetailsOfResultAt(window, 0); + Assert.notEqual( + result.providerName, + "RecentSearches", + "Click on help URL did not record a search" + ); + + await BrowserTestUtils.removeTab(gBrowser.selectedTab); + await BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); }); diff --git a/browser/components/urlbar/tests/browser/browser_redirect_error.js b/browser/components/urlbar/tests/browser/browser_redirect_error.js index ae8dec3da6..5f5194e5fc 100644 --- a/browser/components/urlbar/tests/browser/browser_redirect_error.js +++ b/browser/components/urlbar/tests/browser/browser_redirect_error.js @@ -67,7 +67,7 @@ var gWebProgressListener = { // onSecurityChange: function() {}, // ---------------------------------------------------------------------------- - onLocationChange(aWebProgress, aRequest, aLocation, aFlags) { + onLocationChange(aWebProgress, aRequest, aLocation) { if (!aRequest) { // This is bug 673752, or maybe initial "about:blank". return; diff --git a/browser/components/urlbar/tests/browser/browser_remove_match.js b/browser/components/urlbar/tests/browser/browser_remove_match.js index b9e97044e4..503f01875c 100644 --- a/browser/components/urlbar/tests/browser/browser_remove_match.js +++ b/browser/components/urlbar/tests/browser/browser_remove_match.js @@ -186,7 +186,7 @@ add_task(async function test_searchMode_removeRestyledHistory() { let url = `https://example.com/?q=${query}bar`; await PlacesTestUtils.addVisits(url); - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, value: query, diff --git a/browser/components/urlbar/tests/browser/browser_result_onSelection.js b/browser/components/urlbar/tests/browser/browser_result_onSelection.js index 2a5f8c3760..04f2847591 100644 --- a/browser/components/urlbar/tests/browser/browser_result_onSelection.js +++ b/browser/components/urlbar/tests/browser/browser_result_onSelection.js @@ -48,7 +48,7 @@ add_task(async function test() { let provider = new UrlbarTestUtils.TestProvider({ results, priority: 1, - onSelection: (result, element) => { + onSelection: () => { selectionCount++; }, }); diff --git a/browser/components/urlbar/tests/browser/browser_results_format_displayValue.js b/browser/components/urlbar/tests/browser/browser_results_format_displayValue.js index d0ec3d3818..5575293d06 100644 --- a/browser/components/urlbar/tests/browser/browser_results_format_displayValue.js +++ b/browser/components/urlbar/tests/browser/browser_results_format_displayValue.js @@ -22,7 +22,7 @@ add_task(async function test_receive_punycode_result() { addCallback(this, result); } - getViewUpdate(result, idsByName) { + getViewUpdate(_result, _idsByName) { return {}; } } diff --git a/browser/components/urlbar/tests/browser/browser_retainedResultsOnFocus.js b/browser/components/urlbar/tests/browser/browser_retainedResultsOnFocus.js index 3cc26a5757..fe3b24a675 100644 --- a/browser/components/urlbar/tests/browser/browser_retainedResultsOnFocus.js +++ b/browser/components/urlbar/tests/browser/browser_retainedResultsOnFocus.js @@ -95,7 +95,7 @@ async function test_window(win) { // we just wait for the expected currentURI value. await BrowserTestUtils.withNewTab( { gBrowser: win.gBrowser, url, waitForLoad: false }, - async browser => { + async () => { await TestUtils.waitForCondition( () => win.gBrowser.currentURI.spec == url, "Ensure we're on the expected page" diff --git a/browser/components/urlbar/tests/browser/browser_revert.js b/browser/components/urlbar/tests/browser/browser_revert.js index b68ad0ff91..faa2d92366 100644 --- a/browser/components/urlbar/tests/browser/browser_revert.js +++ b/browser/components/urlbar/tests/browser/browser_revert.js @@ -7,7 +7,7 @@ add_task(async function () { gBrowser, url: "http://example.com", }, - async function (browser) { + async function () { let originalValue = gURLBar.value; let tab = gBrowser.selectedTab; info("Put a typed value."); diff --git a/browser/components/urlbar/tests/browser/browser_searchMode_indicator.js b/browser/components/urlbar/tests/browser/browser_searchMode_indicator.js index 707a4ea38e..f86b1527bf 100644 --- a/browser/components/urlbar/tests/browser/browser_searchMode_indicator.js +++ b/browser/components/urlbar/tests/browser/browser_searchMode_indicator.js @@ -196,7 +196,7 @@ add_task(async function escapeOnInitialPage() { add_task(async function escapeOnBrowsingPage() { info("Tests the indicator's interaction with the ESC key on browsing page"); - await BrowserTestUtils.withNewTab("http://example.com", async browser => { + await BrowserTestUtils.withNewTab("http://example.com", async () => { await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, value: TEST_QUERY, @@ -355,7 +355,7 @@ add_task(async function menubar_item() { // Tests that entering search mode invalidates pageproxystate and that // pageproxystate remains invalid after exiting search mode. add_task(async function invalidate_pageproxystate() { - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await UrlbarTestUtils.promisePopupOpen(window, () => { EventUtils.synthesizeMouseAtCenter(gURLBar.inputField, {}); }); diff --git a/browser/components/urlbar/tests/browser/browser_searchMode_indicator_clickthrough.js b/browser/components/urlbar/tests/browser/browser_searchMode_indicator_clickthrough.js index 214448ee61..f53417834e 100644 --- a/browser/components/urlbar/tests/browser/browser_searchMode_indicator_clickthrough.js +++ b/browser/components/urlbar/tests/browser/browser_searchMode_indicator_clickthrough.js @@ -14,7 +14,7 @@ add_task(async function test() { set: [["browser.search.suggest.enabled", false]], }); - await BrowserTestUtils.withNewTab("about:robots", async browser => { + await BrowserTestUtils.withNewTab("about:robots", async () => { // View open, with string. await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, @@ -69,7 +69,7 @@ add_task(async function test() { Assert.ok(!BrowserTestUtils.isVisible(labelBox)); }); - await BrowserTestUtils.withNewTab("about:robots", async browser => { + await BrowserTestUtils.withNewTab("about:robots", async () => { await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, value: "test", diff --git a/browser/components/urlbar/tests/browser/browser_searchMode_localOneOffs_actionText.js b/browser/components/urlbar/tests/browser/browser_searchMode_localOneOffs_actionText.js index 2068d4c1d5..7b045e517c 100644 --- a/browser/components/urlbar/tests/browser/browser_searchMode_localOneOffs_actionText.js +++ b/browser/components/urlbar/tests/browser/browser_searchMode_localOneOffs_actionText.js @@ -94,7 +94,7 @@ add_task(async function localOneOff() { ); Assert.equal( result.image, - oneOffButtons.selectedButton.engine.getIconURL(), + await oneOffButtons.selectedButton.engine.getIconURL(), "Check the heuristic icon" ); diff --git a/browser/components/urlbar/tests/browser/browser_searchMode_suggestions.js b/browser/components/urlbar/tests/browser/browser_searchMode_suggestions.js index 6e9b3c1031..607cd220a1 100644 --- a/browser/components/urlbar/tests/browser/browser_searchMode_suggestions.js +++ b/browser/components/urlbar/tests/browser/browser_searchMode_suggestions.js @@ -74,7 +74,7 @@ add_setup(async function () { }); add_task(async function emptySearch() { - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await SpecialPowers.pushPrefEnv({ set: [["browser.urlbar.update2.emptySearchBehavior", 2]], }); @@ -109,7 +109,7 @@ add_task(async function emptySearch_withRestyledHistory() { // Can be restyled but does not dupe form history. "http://mochi.test:8888/?terms=ciao", ]); - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await SpecialPowers.pushPrefEnv({ set: [["browser.urlbar.update2.emptySearchBehavior", 2]], }); @@ -162,7 +162,7 @@ add_task(async function emptySearch_withRestyledHistory_noSearchHistory() { // Can be restyled but does not dupe form history. "http://mochi.test:8888/?terms=ciao", ]); - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await SpecialPowers.pushPrefEnv({ set: [ ["browser.urlbar.update2.emptySearchBehavior", 2], @@ -204,7 +204,7 @@ add_task(async function emptySearch_behavior() { // URLs with the same host as the search engine. await PlacesTestUtils.addVisits([`http://mochi.test/`]); - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await SpecialPowers.pushPrefEnv({ set: [["browser.urlbar.update2.emptySearchBehavior", 0]], }); @@ -245,7 +245,7 @@ add_task(async function emptySearch_behavior() { await SpecialPowers.popPrefEnv(); }); - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await SpecialPowers.pushPrefEnv({ set: [["browser.urlbar.update2.emptySearchBehavior", 1]], }); @@ -269,7 +269,7 @@ add_task(async function emptySearch_behavior() { add_task(async function emptySearch_local() { await PlacesTestUtils.addVisits([`http://mochi.test/`]); - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await SpecialPowers.pushPrefEnv({ set: [["browser.urlbar.update2.emptySearchBehavior", 0]], }); @@ -300,7 +300,7 @@ add_task(async function emptySearch_local() { }); add_task(async function nonEmptySearch() { - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { let query = "hello"; await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, @@ -348,7 +348,7 @@ add_task(async function nonEmptySearch() { }); add_task(async function nonEmptySearch_nonMatching() { - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { let query = "ciao"; await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, @@ -422,7 +422,7 @@ add_task(async function nonEmptySearch_withHistory() { }; } - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, value: query, @@ -520,7 +520,7 @@ add_task(async function nonEmptySearch_withHistory() { }); add_task(async function nonEmptySearch_url() { - await BrowserTestUtils.withNewTab("about:robots", async function (browser) { + await BrowserTestUtils.withNewTab("about:robots", async function () { let query = "http://www.example.com/"; await UrlbarTestUtils.promiseAutocompleteResultPopup({ window, diff --git a/browser/components/urlbar/tests/browser/browser_searchSingleWordNotification.js b/browser/components/urlbar/tests/browser/browser_searchSingleWordNotification.js index 36a065d58e..f217915939 100644 --- a/browser/components/urlbar/tests/browser/browser_searchSingleWordNotification.js +++ b/browser/components/urlbar/tests/browser/browser_searchSingleWordNotification.js @@ -62,7 +62,7 @@ async function runURLBarSearchTest({ for (let i = 0; i < setValueFns.length; ++i) { await setValueFns[i](valueToOpen); let topic = "uri-fixup-check-dns"; - let observer = (aSubject, aTopicInner, aData) => { + let observer = (aSubject, aTopicInner) => { if (aTopicInner == topic) { gDNSResolved = true; } @@ -248,7 +248,7 @@ function get_test_function_for_localhost_with_hostname( gBrowser: win.gBrowser, url: "about:blank", }, - browser => + () => runURLBarSearchTest({ valueToOpen: hostName, expectSearch: true, @@ -268,7 +268,7 @@ function get_test_function_for_localhost_with_hostname( gBrowser: win.gBrowser, url: "about:blank", }, - browser => + () => runURLBarSearchTest({ valueToOpen: hostName, expectSearch: true, @@ -289,7 +289,7 @@ function get_test_function_for_localhost_with_hostname( gBrowser: win.gBrowser, url: "about:blank", }, - browser => + () => runURLBarSearchTest({ valueToOpen: hostName, expectSearch: isPrivate, @@ -325,7 +325,7 @@ add_task(async function test_dnsResolveSingleWordsAfterSearch() { gBrowser, url: "about:blank", }, - browser => + () => runURLBarSearchTest({ valueToOpen: "localhost", expectSearch: true, diff --git a/browser/components/urlbar/tests/browser/browser_search_continuation.js b/browser/components/urlbar/tests/browser/browser_search_continuation.js index 8a24d57856..19c853c2e5 100644 --- a/browser/components/urlbar/tests/browser/browser_search_continuation.js +++ b/browser/components/urlbar/tests/browser/browser_search_continuation.js @@ -21,6 +21,65 @@ const CONFIG_DEFAULT = [ }, ]; +const CONFIG_V2 = [ + { + recordType: "engine", + identifier: "basic", + base: { + name: "basic", + urls: { + search: { + base: "https://example.com", + searchTermParamName: "q", + }, + trending: { + base: "https://example.com/browser/browser/components/search/test/browser/trendingSuggestionEngine.sjs", + method: "GET", + }, + }, + aliases: ["basic"], + }, + variants: [ + { + environment: { allRegionsAndLocales: true }, + }, + ], + }, + { + recordType: "engine", + identifier: "private", + base: { + name: "private", + urls: { + search: { + base: "https://example.com", + searchTermParamName: "q", + }, + suggestions: { + base: "https://example.com", + method: "GET", + searchTermParamName: "search", + }, + }, + aliases: ["private"], + }, + variants: [ + { + environment: { allRegionsAndLocales: true }, + }, + ], + }, + { + recordType: "defaultEngines", + globalDefault: "basic", + specificDefaults: [], + }, + { + recordType: "engineOrders", + orders: [], + }, +]; + add_setup(async () => { await SpecialPowers.pushPrefEnv({ set: [ @@ -39,7 +98,10 @@ add_setup(async () => { }); await UrlbarTestUtils.formHistory.clear(); - await SearchTestUtils.setupTestEngines("search-engines", CONFIG_DEFAULT); + await SearchTestUtils.setupTestEngines( + "search-engines", + SearchUtils.newSearchConfigEnabled ? CONFIG_V2 : CONFIG_DEFAULT + ); registerCleanupFunction(async () => { await UrlbarTestUtils.formHistory.clear(); diff --git a/browser/components/urlbar/tests/browser/browser_selectStaleResults.js b/browser/components/urlbar/tests/browser/browser_selectStaleResults.js index c381478712..97f3768881 100644 --- a/browser/components/urlbar/tests/browser/browser_selectStaleResults.js +++ b/browser/components/urlbar/tests/browser/browser_selectStaleResults.js @@ -258,7 +258,7 @@ add_task(async function staleReplacedWithFresh() { // test2 // test1 let mutationPromise = new Promise(resolve => { - let observer = new MutationObserver(mutations => { + let observer = new MutationObserver(() => { let row = UrlbarTestUtils.getRowAt(window, maxResults - 2); if (row && row._elements.get("title").textContent == "test2") { observer.disconnect(); diff --git a/browser/components/urlbar/tests/browser/browser_shortcuts_add_search_engine.js b/browser/components/urlbar/tests/browser/browser_shortcuts_add_search_engine.js index 92eebf1997..43a3f7de9f 100644 --- a/browser/components/urlbar/tests/browser/browser_shortcuts_add_search_engine.js +++ b/browser/components/urlbar/tests/browser/browser_shortcuts_add_search_engine.js @@ -206,7 +206,7 @@ function promiseEngine(expectedData, expectedEngineName) { expectedEngineName == engine.wrappedJSObject.name ); } - ).then(([engine, data]) => engine); + ).then(([engine]) => engine); } add_task(async function shortcuts_without_other_engines() { diff --git a/browser/components/urlbar/tests/browser/browser_speculative_connect_not_with_client_cert.js b/browser/components/urlbar/tests/browser/browser_speculative_connect_not_with_client_cert.js index 62aec6f67a..36c8c23330 100644 --- a/browser/components/urlbar/tests/browser/browser_speculative_connect_not_with_client_cert.js +++ b/browser/components/urlbar/tests/browser/browser_speculative_connect_not_with_client_cert.js @@ -57,7 +57,7 @@ class SecurityObserver { this.output = output; } - onHandshakeDone(socket, status) { + onHandshakeDone() { info("TLS handshake done"); handshakeDone = true; diff --git a/browser/components/urlbar/tests/browser/browser_stop.js b/browser/components/urlbar/tests/browser/browser_stop.js index 285071a3ff..84667eaa53 100644 --- a/browser/components/urlbar/tests/browser/browser_stop.js +++ b/browser/components/urlbar/tests/browser/browser_stop.js @@ -57,7 +57,7 @@ async function typeAndSubmitAndStop(url) { // urlbar value has been updated, add our own progress listener here. let progressPromise = new Promise(resolve => { let listener = { - onStateChange(browser, webProgress, request, stateFlags, status) { + onStateChange(browser, webProgress, request, stateFlags) { if ( webProgress.isTopLevel && stateFlags & Ci.nsIWebProgressListener.STATE_STOP diff --git a/browser/components/urlbar/tests/browser/browser_strip_on_share.js b/browser/components/urlbar/tests/browser/browser_strip_on_share.js index 508106ccdc..9e045cee9c 100644 --- a/browser/components/urlbar/tests/browser/browser_strip_on_share.js +++ b/browser/components/urlbar/tests/browser/browser_strip_on_share.js @@ -112,7 +112,7 @@ async function testMenuItemDisabled(url, prefEnabled, selection) { await SpecialPowers.pushPrefEnv({ set: [["privacy.query_stripping.strip_on_share.enabled", prefEnabled]], }); - await BrowserTestUtils.withNewTab(url, async function (browser) { + await BrowserTestUtils.withNewTab(url, async function () { gURLBar.focus(); if (selection) { //select only part of the url @@ -175,7 +175,7 @@ async function testMenuItemEnabled({ await listService.testSetList(testJson); } - await BrowserTestUtils.withNewTab(validUrl, async function (browser) { + await BrowserTestUtils.withNewTab(validUrl, async function () { gURLBar.focus(); if (selectWholeUrl) { gURLBar.select(); diff --git a/browser/components/urlbar/tests/browser/browser_strip_on_share_telemetry.js b/browser/components/urlbar/tests/browser/browser_strip_on_share_telemetry.js index 48a8b6c729..7b6fb53e3b 100644 --- a/browser/components/urlbar/tests/browser/browser_strip_on_share_telemetry.js +++ b/browser/components/urlbar/tests/browser/browser_strip_on_share_telemetry.js @@ -80,7 +80,7 @@ add_task(async function testMultiQueryParams() { }); async function testStripOnShare(validUrl, strippedUrl) { - await BrowserTestUtils.withNewTab(validUrl, async function (browser) { + await BrowserTestUtils.withNewTab(validUrl, async function () { gURLBar.focus(); gURLBar.select(); let menuitem = await promiseContextualMenuitem("strip-on-share"); diff --git a/browser/components/urlbar/tests/browser/browser_switchTab_inputHistory.js b/browser/components/urlbar/tests/browser/browser_switchTab_inputHistory.js index 0da3161d0e..3dab8e7e64 100644 --- a/browser/components/urlbar/tests/browser/browser_switchTab_inputHistory.js +++ b/browser/components/urlbar/tests/browser/browser_switchTab_inputHistory.js @@ -25,16 +25,15 @@ add_task(async function test_adaptive_with_search_term_and_switch_tab() { info(`Load tabs in same order as urls`); let tabs = []; + let waitForVisits = PlacesTestUtils.waitForNotification( + "page-visited", + events => events.some(e => e.url === urls[3]) + ); for (let url of urls) { - let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser, url, false, true); - gBrowser.loadTabs([url], { - inBackground: true, - triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(), - }); - - let tab = await tabPromise; - tabs.push(tab); + tabs.push(await BrowserTestUtils.openNewForegroundTab({ gBrowser, url })); } + // Ensure visits have been added. + await waitForVisits; info(`Switch to tab 0`); await BrowserTestUtils.switchTab(gBrowser, tabs[0]); @@ -89,3 +88,57 @@ add_task(async function test_adaptive_with_search_term_and_switch_tab() { BrowserTestUtils.removeTab(tab); } }); + +add_task( + async function test_adaptive_nonadaptive_container_dedupe_switch_tab() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["privacy.userContext.enabled", true], + ["browser.urlbar.switchTabs.searchAllContainers", true], + ], + }); + // Add a url both to history and input history, ensure that the Muxer will + // properly dedupe the 2 entries, also with containers involved. + await PlacesUtils.history.clear(); + const url = "https://example.com/"; + + let promiseVisited = PlacesTestUtils.waitForNotification( + "page-visited", + events => events.some(e => e.url === url) + ); + let tab = BrowserTestUtils.addTab(gBrowser, url, { userContextId: 1 }); + await promiseVisited; + + async function queryAndCheckOneSwitchTabResult() { + await UrlbarTestUtils.promiseAutocompleteResultPopup({ + window, + value: "xampl", + }); + Assert.equal( + 2, + UrlbarTestUtils.getResultCount(window), + "Check number of results" + ); + let result = await UrlbarTestUtils.getDetailsOfResultAt(window, 1); + Assert.equal(url, result.url, `Url is the first non-heuristic result`); + Assert.equal( + UrlbarUtils.RESULT_TYPE.TAB_SWITCH, + result.type, + "Should be a switch tab result" + ); + Assert.equal( + 1, + result.result.payload.userContextId, + "Should use the expected container" + ); + } + info("Check the tab is returned as history by a search."); + await queryAndCheckOneSwitchTabResult(); + info("Add the same url to input history."); + await UrlbarUtils.addToInputHistory(url, "xampl"); + info("Repeat the query."); + await queryAndCheckOneSwitchTabResult(); + BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); + } +); diff --git a/browser/components/urlbar/tests/browser/browser_switchTab_override.js b/browser/components/urlbar/tests/browser/browser_switchTab_override.js index 66426a154b..507c975cba 100644 --- a/browser/components/urlbar/tests/browser/browser_switchTab_override.js +++ b/browser/components/urlbar/tests/browser/browser_switchTab_override.js @@ -54,7 +54,7 @@ add_task(async function test_switchtab_override() { info("Override switch-to-tab"); let deferred = Promise.withResolvers(); // In case of failure this would switch tab. - let onTabSelect = event => { + let onTabSelect = () => { deferred.reject(new Error("Should have overridden switch to tab")); }; gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect); diff --git a/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js b/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js index 354cd3a802..94d46b3b81 100644 --- a/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js +++ b/browser/components/urlbar/tests/browser/browser_tabMatchesInAwesomebar.js @@ -138,7 +138,7 @@ function loadTab(tab, url) { // Because adding visits is async, we will not be notified immediately. let loaded = BrowserTestUtils.browserLoaded(tab.linkedBrowser); let visited = new Promise(resolve => { - Services.obs.addObserver(function observer(aSubject, aTopic, aData) { + Services.obs.addObserver(function observer(aSubject, aTopic) { if (url != aSubject.QueryInterface(Ci.nsIURI).spec) { return; } diff --git a/browser/components/urlbar/tests/browser/browser_tabToSearch.js b/browser/components/urlbar/tests/browser/browser_tabToSearch.js index a336980583..deba60ea1e 100644 --- a/browser/components/urlbar/tests/browser/browser_tabToSearch.js +++ b/browser/components/urlbar/tests/browser/browser_tabToSearch.js @@ -284,14 +284,14 @@ add_task(async function tab_key_race() { get type() { return UrlbarUtils.PROVIDER_TYPE.PROFILE; } - isActive(context) { + isActive(_context) { executeSoon(resolve); return false; } - isRestricting(context) { + isRestricting(_context) { return false; } - async startQuery(context, addCallback) { + async startQuery(_context, _addCallback) { // Nothing to do. } } diff --git a/browser/components/urlbar/tests/browser/browser_top_sites_switchtab.js b/browser/components/urlbar/tests/browser/browser_top_sites_switchtab.js new file mode 100644 index 0000000000..d4edce0f11 --- /dev/null +++ b/browser/components/urlbar/tests/browser/browser_top_sites_switchtab.js @@ -0,0 +1,209 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * Test that TopSites are showing an appropriate Switch-tab status, depending + * on the state of the `browser.urlbar.switchTabs.searchAllContainers` pref. + * When the feature is enabled, in a normal window they should show the + * tab container, otherwise it's only possible to switch to a tab in the same + * container. + * In private windows it's only possible to switch to private tabs in the + * private container. Similarly non-private windows don't see private tabs. + * This test is not checking that switching to the appropriate tab works as that + * is already covered by other tests. + */ + +ChromeUtils.defineESModuleGetters(this, { + AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs", + NewTabUtils: "resource://gre/modules/NewTabUtils.sys.mjs", +}); + +const EN_US_TOPSITES = + "https://www.youtube.com/,https://www.facebook.com/,https://www.amazon.com/,https://www.reddit.com/"; +const OUR_TOPSITE_URL = "https://example.com/"; +const REF_TOPSITE_URL = OUR_TOPSITE_URL + "#someref"; +const TOPSITES_COUNT = EN_US_TOPSITES.split(",").length + 1; + +add_setup(async function () { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.urlbar.suggest.topsites", true], + ["browser.urlbar.suggest.quickactions", false], + ["browser.newtabpage.activity-stream.default.sites", EN_US_TOPSITES], + ], + }); + registerCleanupFunction(PlacesUtils.history.clear); +}); + +add_task(async function test_ignoreRef() { + info("Add some visits to a URL."); + await addAsFirstTopSite(REF_TOPSITE_URL); + + for (let val of [true, false]) { + await SpecialPowers.pushPrefEnv({ + set: [["browser.urlbar.switchTabs.searchAllContainers", val]], + }); + info("Test with searchAllContainer set to " + val.toString()); + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + REF_TOPSITE_URL + ); + // Switch back to the originating tab, to check for switch to the current tab. + await BrowserTestUtils.switchTab(gBrowser, gBrowser.tabs[0]); + await openAddressBarAndCheckResults(window, TOPSITES_COUNT, new Set([0])); + await BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); + } + await PlacesUtils.history.remove(REF_TOPSITE_URL); +}); + +add_task(async function test_topSitesTabSwitch() { + await addAsFirstTopSite(OUR_TOPSITE_URL); + + for (let val of [true, false]) { + await SpecialPowers.pushPrefEnv({ + set: [["browser.urlbar.switchTabs.searchAllContainers", val]], + }); + info("Test with searchAllContainer set to " + val.toString()); + await doTest(); + await SpecialPowers.popPrefEnv(); + } + await PlacesUtils.history.remove(OUR_TOPSITE_URL); +}); + +async function doTest() { + info("Non-private window"); + // Add a normal tab and a container tab. + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + OUR_TOPSITE_URL + ); + let containerTab = await loadNewForegroundContainerTab(OUR_TOPSITE_URL, 1); + // Switch back to the originating tab, to check for switch to the current tab. + await BrowserTestUtils.switchTab(gBrowser, gBrowser.tabs[0]); + let expectedUserContextIds = UrlbarPrefs.get("switchTabs.searchAllContainers") + ? new Set([0, 1]) + : new Set([0]); + await openAddressBarAndCheckResults( + window, + TOPSITES_COUNT + expectedUserContextIds.size - 1, + expectedUserContextIds + ); + + info("Private window"); + let pbWin = await BrowserTestUtils.openNewBrowserWindow({ + private: true, + }); + await openAddressBarAndCheckResults(pbWin, TOPSITES_COUNT, new Set()); + + info("Close the original tab and open the url in the private window instead"); + await BrowserTestUtils.removeTab(tab); + await BrowserTestUtils.openNewForegroundTab(pbWin.gBrowser, OUR_TOPSITE_URL); + // Switch back to the originating tab, to check for switch to the current tab. + await BrowserTestUtils.switchTab(pbWin.gBrowser, pbWin.gBrowser.tabs[0]); + await openAddressBarAndCheckResults( + window, + TOPSITES_COUNT, + UrlbarPrefs.get("switchTabs.searchAllContainers") ? new Set([1]) : new Set() + ); + await openAddressBarAndCheckResults(pbWin, TOPSITES_COUNT, new Set([-1])); + + // We're done with the private window. + await BrowserTestUtils.closeWindow(pbWin); + + info("Check Top sites in the same container tab"); + let blankSameContainerTab = await loadNewForegroundContainerTab( + "about:blank", + 1 + ); + await openAddressBarAndCheckResults(window, TOPSITES_COUNT, new Set([1])); + await BrowserTestUtils.removeTab(blankSameContainerTab); + + info("Check Top sites in a different container tab"); + let blankDiffContainerTab = await loadNewForegroundContainerTab( + "about:blank", + 2 + ); + await openAddressBarAndCheckResults( + window, + TOPSITES_COUNT, + UrlbarPrefs.get("switchTabs.searchAllContainers") ? new Set([1]) : new Set() + ); + await BrowserTestUtils.removeTab(blankDiffContainerTab); + + await BrowserTestUtils.removeTab(containerTab); +} + +async function openAddressBarAndCheckResults( + win, + expectedResultCount, + expectedTabSwitchUserContextIds +) { + info("Open zero-prefix results."); + await UrlbarTestUtils.promisePopupOpen(win, () => { + win.gURLBar.blur(); + if (win.gURLBar.getAttribute("pageproxystate") == "invalid") { + win.gURLBar.handleRevert(); + } + EventUtils.synthesizeMouseAtCenter(win.gURLBar.inputField, {}, win); + }); + await UrlbarTestUtils.promiseSearchComplete(win); + let resultCount = UrlbarTestUtils.getResultCount(win); + Assert.equal(expectedResultCount, resultCount, "Check number of results."); + + for (let i = 0; i < resultCount; ++i) { + let result = await UrlbarTestUtils.getDetailsOfResultAt(win, i); + + if (result.url != "https://example.com/") { + // We don't care about other top sites. + continue; + } + + if (!expectedTabSwitchUserContextIds.size) { + // No more tab switch results expected. + Assert.notEqual( + UrlbarUtils.RESULT_TYPE.TAB_SWITCH, + result.type, + "Should not be a tab switch result." + ); + continue; + } + + // Must be a tab switch result with an expected userContextId. + Assert.equal( + UrlbarUtils.RESULT_TYPE.TAB_SWITCH, + result.type, + "Should be a tab switch result." + ); + let hasUserContextId = expectedTabSwitchUserContextIds.delete( + result.userContextId + ); + Assert.ok( + hasUserContextId, + `UserContextId ${result.userContextId} tab switch was expected in + ${expectedTabSwitchUserContextIds}` + ); + } +} + +async function addAsFirstTopSite(url) { + info("Add some visits to a URL."); + await PlacesTestUtils.addVisits(Array(10).fill(url)); + info("Add top sites and await for our page to be the first"); + await updateTopSites(sites => { + return sites && sites.length == TOPSITES_COUNT && sites[0].url == url; + }); +} + +async function loadNewForegroundContainerTab(url, userContextId, win = window) { + let tab = BrowserTestUtils.addTab(win.gBrowser, url, { + userContextId, + }); + await Promise.all([ + BrowserTestUtils.browserLoaded(tab.linkedBrowser), + BrowserTestUtils.switchTab(win.gBrowser, tab), + ]); + return tab; +} diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_dynamic.js b/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_dynamic.js index d4f4e77d57..1eef6fc0e0 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_dynamic.js +++ b/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_dynamic.js @@ -39,7 +39,7 @@ class TestProvider extends UrlbarTestUtils.TestProvider { }); } - getViewUpdate(result, idsByName) { + getViewUpdate(_result, _idsByName) { return { title: { textContent: "This is a dynamic result.", diff --git a/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_tip.js b/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_tip.js index 345b063441..66ddb225fb 100644 --- a/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_tip.js +++ b/browser/components/urlbar/tests/browser/browser_urlbar_telemetry_tip.js @@ -115,10 +115,10 @@ class TipProvider extends UrlbarProvider { get type() { return UrlbarUtils.PROVIDER_TYPE.PROFILE; } - isActive(context) { + isActive(_context) { return true; } - getPriority(context) { + getPriority(_context) { return 1; } async startQuery(context, addCallback) { diff --git a/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js b/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js index ba249adb3b..03afeb3410 100644 --- a/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js +++ b/browser/components/urlbar/tests/browser/browser_valueOnTabSwitch.js @@ -90,7 +90,7 @@ add_task(async function () { } function urlbarBackspace(removeAll) { - return new Promise((resolve, reject) => { + return new Promise(resolve => { gBrowser.selectedBrowser.focus(); gURLBar.addEventListener( "input", diff --git a/browser/components/urlbar/tests/browser/browser_view_removedSelectedElement.js b/browser/components/urlbar/tests/browser/browser_view_removedSelectedElement.js index 532f9e10a2..8ccb49d4ae 100644 --- a/browser/components/urlbar/tests/browser/browser_view_removedSelectedElement.js +++ b/browser/components/urlbar/tests/browser/browser_view_removedSelectedElement.js @@ -25,7 +25,7 @@ add_task(async function () { let firstSelectedElement; let delayResultsPromise = new Promise(resolve => { gURLBar.controller.addQueryListener({ - async onQueryResults(queryContext) { + async onQueryResults() { Assert.ok(!receivedResults, "Should execute only once"); gURLBar.controller.removeQueryListener(this); receivedResults = true; diff --git a/browser/components/urlbar/tests/browser/browser_view_selectionByMouse.js b/browser/components/urlbar/tests/browser/browser_view_selectionByMouse.js index fc617220b6..10110a8928 100644 --- a/browser/components/urlbar/tests/browser/browser_view_selectionByMouse.js +++ b/browser/components/urlbar/tests/browser/browser_view_selectionByMouse.js @@ -324,6 +324,9 @@ add_task(async function withDnsFirstForSingleWordsPref() { url: "https://example.org/", title: "example", }); + // An unvisited bookmark may have a lower ranking than a page visited many + // times, so let's clear history to ensure our bookmark is autofilled. + await PlacesUtils.history.clear(); await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); await UrlbarTestUtils.promiseAutocompleteResultPopup({ @@ -333,13 +336,13 @@ add_task(async function withDnsFirstForSingleWordsPref() { const details = await UrlbarTestUtils.getDetailsOfResultAt(window, 0); const target = details.element.action; - EventUtils.synthesizeMouseAtCenter(target, { type: "mousedown" }); + const onLoaded = BrowserTestUtils.browserLoaded( gBrowser.selectedBrowser, false, "https://example.org/" ); - EventUtils.synthesizeMouseAtCenter(target, { type: "mouseup" }); + EventUtils.synthesizeMouseAtCenter(target, {}); await onLoaded; Assert.ok(true, "Expected page is opened"); diff --git a/browser/components/urlbar/tests/browser/head.js b/browser/components/urlbar/tests/browser/head.js index a81e8e4811..f78624e68e 100644 --- a/browser/components/urlbar/tests/browser/head.js +++ b/browser/components/urlbar/tests/browser/head.js @@ -67,7 +67,7 @@ function waitForLoadStartOrTimeout(win = window, timeoutMs = 1000) { return Promise.race([ new Promise(resolve => { listener = { - onStateChange(browser, webprogress, request, flags, status) { + onStateChange(browser, webprogress, request, flags) { if (flags & Ci.nsIWebProgressListener.STATE_START) { resolve(request.QueryInterface(Ci.nsIChannel).URI); } |