diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:13:33 +0000 |
commit | 086c044dc34dfc0f74fbe41f4ecb402b2cd34884 (patch) | |
tree | a4f824bd33cb075dd5aa3eb5a0a94af221bbe83a /browser/components/urlbar/tests/unit | |
parent | Adding debian version 124.0.1-1. (diff) | |
download | firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.tar.xz firefox-086c044dc34dfc0f74fbe41f4ecb402b2cd34884.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/urlbar/tests/unit')
15 files changed, 135 insertions, 80 deletions
diff --git a/browser/components/urlbar/tests/unit/head.js b/browser/components/urlbar/tests/unit/head.js index 6f78608c94..da96d5704f 100644 --- a/browser/components/urlbar/tests/unit/head.js +++ b/browser/components/urlbar/tests/unit/head.js @@ -1110,44 +1110,13 @@ async function getOriginFrecency(prefix, aHost) { } /** - * Returns the origin frecency stats. - * - * @returns {object} - * An object { count, sum, squares }. - */ -async function getOriginFrecencyStats() { - let db = await PlacesUtils.promiseDBConnection(); - let rows = await db.execute(` - SELECT - IFNULL((SELECT value FROM moz_meta WHERE key = 'origin_frecency_count'), 0), - IFNULL((SELECT value FROM moz_meta WHERE key = 'origin_frecency_sum'), 0), - IFNULL((SELECT value FROM moz_meta WHERE key = 'origin_frecency_sum_of_squares'), 0) - `); - let count = rows[0].getResultByIndex(0); - let sum = rows[0].getResultByIndex(1); - let squares = rows[0].getResultByIndex(2); - return { count, sum, squares }; -} - -/** * Returns the origin autofill frecency threshold. * * @returns {number} * The threshold. */ async function getOriginAutofillThreshold() { - let { count, sum, squares } = await getOriginFrecencyStats(); - if (!count) { - return 0; - } - if (count == 1) { - return sum; - } - let stddevMultiplier = UrlbarPrefs.get("autoFill.stddevMultiplier"); - return ( - sum / count + - stddevMultiplier * Math.sqrt((squares - (sum * sum) / count) / count) - ); + return PlacesUtils.metadata.get("origin_frecency_threshold", 2.0); } /** diff --git a/browser/components/urlbar/tests/unit/test_UrlbarPrefs.js b/browser/components/urlbar/tests/unit/test_UrlbarPrefs.js index d30739f03e..7fb3256f6c 100644 --- a/browser/components/urlbar/tests/unit/test_UrlbarPrefs.js +++ b/browser/components/urlbar/tests/unit/test_UrlbarPrefs.js @@ -363,10 +363,10 @@ add_task(async function onNimbusChanged() { // Add an observer that throws an Error and an observer that does not define // anything to check whether the other observers can get notifications. UrlbarPrefs.addObserver({ - onPrefChanged(pref) { + onPrefChanged() { throw new Error("From onPrefChanged"); }, - onNimbusChanged(pref) { + onNimbusChanged() { throw new Error("From onNimbusChanged"); }, }); @@ -407,10 +407,10 @@ add_task(async function onPrefChanged() { // Add an observer that throws an Error and an observer that does not define // anything to check whether the other observers can get notifications. UrlbarPrefs.addObserver({ - onPrefChanged(pref) { + onPrefChanged() { throw new Error("From onPrefChanged"); }, - onNimbusChanged(pref) { + onNimbusChanged() { throw new Error("From onNimbusChanged"); }, }); diff --git a/browser/components/urlbar/tests/unit/test_UrlbarSearchUtils.js b/browser/components/urlbar/tests/unit/test_UrlbarSearchUtils.js index fe33228007..28cbd381f1 100644 --- a/browser/components/urlbar/tests/unit/test_UrlbarSearchUtils.js +++ b/browser/components/urlbar/tests/unit/test_UrlbarSearchUtils.js @@ -65,14 +65,10 @@ add_task(async function onlyEnabled_option_nomatch() { let domain = engine.searchUrlDomain; let token = domain.substr(0, 1); engine.hideOneOffButton = true; - let matchedEngines = await UrlbarSearchUtils.enginesForDomainPrefix(token, { - onlyEnabled: true, - }); + let matchedEngines = await UrlbarSearchUtils.enginesForDomainPrefix(token); Assert.notEqual(matchedEngines[0].searchUrlDomain, domain); engine.hideOneOffButton = false; - matchedEngines = await UrlbarSearchUtils.enginesForDomainPrefix(token, { - onlyEnabled: true, - }); + matchedEngines = await UrlbarSearchUtils.enginesForDomainPrefix(token); Assert.equal(matchedEngines[0].searchUrlDomain, domain); }); @@ -95,7 +91,7 @@ add_task(async function add_search_engine_match() { Assert.ok(matchedEngine); Assert.equal(matchedEngine.searchForm, "https://www.bacon.moz"); Assert.equal(matchedEngine.name, "bacon"); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); info("also type part of the public suffix"); matchedEngine = ( await UrlbarSearchUtils.enginesForDomainPrefix("bacon.m") @@ -103,7 +99,7 @@ add_task(async function add_search_engine_match() { Assert.ok(matchedEngine); Assert.equal(matchedEngine.searchForm, "https://www.bacon.moz"); Assert.equal(matchedEngine.name, "bacon"); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); }); add_task(async function match_multiple_search_engines() { @@ -134,19 +130,19 @@ add_task(async function test_aliased_search_engine_match() { Assert.ok(matchedEngine); Assert.equal(matchedEngine.name, "bacon"); Assert.ok(matchedEngine.aliases.includes("pork")); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); // Upper case matchedEngine = await UrlbarSearchUtils.engineForAlias("PORK"); Assert.ok(matchedEngine); Assert.equal(matchedEngine.name, "bacon"); Assert.ok(matchedEngine.aliases.includes("pork")); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); // Cap case matchedEngine = await UrlbarSearchUtils.engineForAlias("Pork"); Assert.ok(matchedEngine); Assert.equal(matchedEngine.name, "bacon"); Assert.ok(matchedEngine.aliases.includes("pork")); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); }); add_task(async function test_aliased_search_engine_match_upper_case_alias() { @@ -164,19 +160,19 @@ add_task(async function test_aliased_search_engine_match_upper_case_alias() { Assert.ok(matchedEngine); Assert.equal(matchedEngine.name, "patch"); Assert.ok(matchedEngine.aliases.includes("PR")); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); // Upper case matchedEngine = await UrlbarSearchUtils.engineForAlias("PR"); Assert.ok(matchedEngine); Assert.equal(matchedEngine.name, "patch"); Assert.ok(matchedEngine.aliases.includes("PR")); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); // Cap case matchedEngine = await UrlbarSearchUtils.engineForAlias("Pr"); Assert.ok(matchedEngine); Assert.equal(matchedEngine.name, "patch"); Assert.ok(matchedEngine.aliases.includes("PR")); - Assert.equal(matchedEngine.getIconURL(), null); + Assert.equal(await matchedEngine.getIconURL(), null); }); add_task(async function remove_search_engine_nomatch() { diff --git a/browser/components/urlbar/tests/unit/test_about_urls.js b/browser/components/urlbar/tests/unit/test_about_urls.js index 277ddb8ee1..82a8ef2750 100644 --- a/browser/components/urlbar/tests/unit/test_about_urls.js +++ b/browser/components/urlbar/tests/unit/test_about_urls.js @@ -76,8 +76,10 @@ add_task(async function aboutAboutAndAboutAddons() { heuristic: true, }), makeVisitResult(context, { + source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, uri: "about:addons", title: "about:addons", + iconUri: "page-icon:about:addons", tags: null, providerName: "AboutPages", }), @@ -93,8 +95,10 @@ add_task(async function aboutColonMatchesOnlyAboutPages() { const aboutPageNames = AboutPagesUtils.visibleAboutUrls.slice(0, 9); const aboutPageResults = aboutPageNames.map(aboutPageName => { return makeVisitResult(context, { + source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, uri: aboutPageName, title: aboutPageName, + iconUri: "page-icon:" + aboutPageName, tags: null, providerName: "AboutPages", }); @@ -165,8 +169,10 @@ add_task(async function after_general() { title: "Guide to about:addons in Firefox", }), makeVisitResult(context, { + source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, uri: "about:addons", title: "about:addons", + iconUri: "page-icon:about:addons", tags: null, providerName: "AboutPages", }), diff --git a/browser/components/urlbar/tests/unit/test_autofill_originsAndQueries.js b/browser/components/urlbar/tests/unit/test_autofill_originsAndQueries.js index 05e3a230f1..7164ae8911 100644 --- a/browser/components/urlbar/tests/unit/test_autofill_originsAndQueries.js +++ b/browser/components/urlbar/tests/unit/test_autofill_originsAndQueries.js @@ -893,8 +893,11 @@ add_autofill_task(async function bookmarkBelowThreshold() { await cleanup(); }); -// Bookmarked places should be autofilled when they *do* meet the threshold. +// Bookmarked places should be autofilled also when they meet the threshold. add_autofill_task(async function bookmarkAboveThreshold() { + // Add a visit to the URL, otherwise origin frecency will be too small, note + // it would be filled anyway as bookmarks are always filled. + await PlacesTestUtils.addVisits(["http://" + url]); // Bookmark a URL. await PlacesTestUtils.addBookmarkWithDetails({ uri: "http://" + url, @@ -957,13 +960,10 @@ add_autofill_task(async function zeroThreshold() { ); Assert.equal(placeFrecency, -1); - // Make sure the origin's frecency is 0. let originFrecency = await getOriginFrecency("http://", host); - Assert.equal(originFrecency, 0); - - // Make sure the autofill threshold is 0. + Assert.equal(originFrecency, 1, "Check expected origin's frecency"); let threshold = await getOriginAutofillThreshold(); - Assert.equal(threshold, 0); + Assert.equal(threshold, 1, "Check expected origins threshold"); let context = createContext(search, { isPrivate: false }); await check_results({ diff --git a/browser/components/urlbar/tests/unit/test_heuristic_cancel.js b/browser/components/urlbar/tests/unit/test_heuristic_cancel.js index 6f6f2fbd8a..a78004f2bd 100644 --- a/browser/components/urlbar/tests/unit/test_heuristic_cancel.js +++ b/browser/components/urlbar/tests/unit/test_heuristic_cancel.js @@ -126,7 +126,7 @@ add_task(async function timerIsCancelled() { // Then they will be queued up in a _heuristicProvidersTimer, waiting for // the results from SlowProvider. let resultsAddedPromise = new Promise(resolve => { - let observe = async (subject, topic, data) => { + let observe = async () => { Services.obs.removeObserver(observe, "results-added"); // Fire the second query to cancel the first. await controller.startQuery(secondContext); diff --git a/browser/components/urlbar/tests/unit/test_hideSponsoredHistory.js b/browser/components/urlbar/tests/unit/test_hideSponsoredHistory.js index d49aaf2fb7..79d3e3b17c 100644 --- a/browser/components/urlbar/tests/unit/test_hideSponsoredHistory.js +++ b/browser/components/urlbar/tests/unit/test_hideSponsoredHistory.js @@ -78,7 +78,7 @@ add_task(async function test() { makeSearchResult(context, { heuristic: true, engineName: engine.name, - engineIconUri: engine.getIconURL(), + engineIconUri: await engine.getIconURL(), }), ]; if (shouldAppear) { diff --git a/browser/components/urlbar/tests/unit/test_match_javascript.js b/browser/components/urlbar/tests/unit/test_match_javascript.js index 3d3eab19ba..bba0af1376 100644 --- a/browser/components/urlbar/tests/unit/test_match_javascript.js +++ b/browser/components/urlbar/tests/unit/test_match_javascript.js @@ -32,7 +32,10 @@ add_task(async function test_javascript_match() { await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); info("Match non-javascript: with plain search"); - let context = createContext("a", { isPrivate: false }); + let context = createContext("a", { + isPrivate: false, + allowAutofill: false /* avoid autofilling abc, as it's not necessary */, + }); await check_results({ context, matches: [ diff --git a/browser/components/urlbar/tests/unit/test_providerHistoryUrlHeuristic.js b/browser/components/urlbar/tests/unit/test_providerHistoryUrlHeuristic.js index 7eb62fbeea..8cf643393f 100644 --- a/browser/components/urlbar/tests/unit/test_providerHistoryUrlHeuristic.js +++ b/browser/components/urlbar/tests/unit/test_providerHistoryUrlHeuristic.js @@ -185,8 +185,10 @@ add_task(async function test_unsupported_protocol() { title: "Robots!", }), makeVisitResult(context, { + source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, uri: "about:robots", title: "about:robots", + iconUri: "page-icon:about:robots", tags: null, providerName: "AboutPages", }), diff --git a/browser/components/urlbar/tests/unit/test_providerOpenTabs.js b/browser/components/urlbar/tests/unit/test_providerOpenTabs.js index f85f547ac3..689ecf614f 100644 --- a/browser/components/urlbar/tests/unit/test_providerOpenTabs.js +++ b/browser/components/urlbar/tests/unit/test_providerOpenTabs.js @@ -3,23 +3,24 @@ "use strict"; +const userContextId1 = 3; +const userContextId2 = 5; +const url = "http://foo.mozilla.org/"; +const url2 = "http://foo2.mozilla.org/"; + add_task(async function test_openTabs() { - const userContextId1 = 3; - const userContextId2 = 5; - const url = "http://foo.mozilla.org/"; - const url2 = "http://foo2.mozilla.org/"; UrlbarProviderOpenTabs.registerOpenTab(url, userContextId1, false); UrlbarProviderOpenTabs.registerOpenTab(url, userContextId1, false); UrlbarProviderOpenTabs.registerOpenTab(url2, userContextId1, false); UrlbarProviderOpenTabs.registerOpenTab(url, userContextId2, false); Assert.deepEqual( [url, url2], - UrlbarProviderOpenTabs.getOpenTabs(userContextId1), + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(userContextId1), "Found all the expected tabs" ); Assert.deepEqual( [url], - UrlbarProviderOpenTabs.getOpenTabs(userContextId2), + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(userContextId2), "Found all the expected tabs" ); await PlacesUtils.promiseLargeCacheDBConnection(); @@ -37,13 +38,13 @@ add_task(async function test_openTabs() { await UrlbarProviderOpenTabs.unregisterOpenTab(url2, userContextId1, false); Assert.deepEqual( [url], - UrlbarProviderOpenTabs.getOpenTabs(userContextId1), + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(userContextId1), "Found all the expected tabs" ); await UrlbarProviderOpenTabs.unregisterOpenTab(url, userContextId1, false); Assert.deepEqual( [url], - UrlbarProviderOpenTabs.getOpenTabs(userContextId1), + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(userContextId1), "Found all the expected tabs" ); Assert.deepEqual( @@ -77,4 +78,86 @@ add_task(async function test_openTabs() { Assert.equal(matchCount, 2, "Found the expected number of matches"); // Sanity check that this doesn't throw. provider.cancelQuery(context); + await UrlbarProviderOpenTabs.unregisterOpenTab(url, userContextId1, false); + await UrlbarProviderOpenTabs.unregisterOpenTab(url, userContextId2, false); +}); + +add_task(async function test_openTabs_mixedtype_input() { + // Passing the userContextId as a string, rather than a number, is a fairly + // common mistake, check the API handles both properly. + Assert.deepEqual( + [], + UrlbarProviderOpenTabs.getOpenTabUrls(1), + "Found all the expected tabs" + ); + Assert.deepEqual( + [], + UrlbarProviderOpenTabs.getOpenTabUrls(2), + "Found all the expected tabs" + ); + UrlbarProviderOpenTabs.registerOpenTab(url, 1, false); + UrlbarProviderOpenTabs.registerOpenTab(url, "2", false); + Assert.deepEqual( + [url], + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(1), + "Found all the expected tabs" + ); + Assert.deepEqual( + [url], + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(2), + "Found all the expected tabs" + ); + Assert.deepEqual( + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(1), + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId("1"), + "Also check getOpenTabs adapts to the argument type" + ); + UrlbarProviderOpenTabs.unregisterOpenTab(url, "1", false); + UrlbarProviderOpenTabs.unregisterOpenTab(url, 2, false); + Assert.deepEqual( + [], + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(1), + "Found all the expected tabs" + ); + Assert.deepEqual( + [], + UrlbarProviderOpenTabs.getOpenTabUrlsForUserContextId(2), + "Found all the expected tabs" + ); +}); + +add_task(async function test_openTabs() { + Assert.equal( + 0, + UrlbarProviderOpenTabs.getOpenTabUrls().size, + "Check there's no open tabs" + ); + Assert.equal( + 0, + UrlbarProviderOpenTabs.getOpenTabUrls(true).size, + "Check there's no private open tabs" + ); + await UrlbarProviderOpenTabs.registerOpenTab(url, userContextId1, false); + await UrlbarProviderOpenTabs.registerOpenTab(url, userContextId2, false); + await UrlbarProviderOpenTabs.registerOpenTab(url2, 0, true); + Assert.equal( + 1, + UrlbarProviderOpenTabs.getOpenTabUrls().size, + "Check open tabs" + ); + Assert.deepEqual( + [userContextId1, userContextId2], + Array.from(UrlbarProviderOpenTabs.getOpenTabUrls().get(url)), + "Check the tab is in 2 userContextIds" + ); + Assert.equal( + 1, + UrlbarProviderOpenTabs.getOpenTabUrls(true).size, + "Check open private tabs" + ); + Assert.deepEqual( + [-1], + Array.from(UrlbarProviderOpenTabs.getOpenTabUrls(true).get(url2)), + "Check the tab is in the private userContextId" + ); }); diff --git a/browser/components/urlbar/tests/unit/test_providerTabToSearch.js b/browser/components/urlbar/tests/unit/test_providerTabToSearch.js index 0a8bfbead5..32bf450654 100644 --- a/browser/components/urlbar/tests/unit/test_providerTabToSearch.js +++ b/browser/components/urlbar/tests/unit/test_providerTabToSearch.js @@ -87,7 +87,7 @@ add_task(async function noAutofill() { matches: [ makeSearchResult(context, { engineName: Services.search.defaultEngine.name, - engineIconUri: Services.search.defaultEngine.getIconURL(), + engineIconUri: await Services.search.defaultEngine.getIconURL(), heuristic: true, providerName: "HeuristicFallback", }), @@ -423,7 +423,7 @@ add_task(async function test_publicSuffix() { matches: [ makeSearchResult(context, { engineName: Services.search.defaultEngine.name, - engineIconUri: Services.search.defaultEngine.getIconURL(), + engineIconUri: await Services.search.defaultEngine.getIconURL(), heuristic: true, providerName: "HeuristicFallback", }), diff --git a/browser/components/urlbar/tests/unit/test_providersManager_filtering.js b/browser/components/urlbar/tests/unit/test_providersManager_filtering.js index 094eb42437..4a1eb5c0ef 100644 --- a/browser/components/urlbar/tests/unit/test_providersManager_filtering.js +++ b/browser/components/urlbar/tests/unit/test_providersManager_filtering.js @@ -205,10 +205,10 @@ add_task(async function test_filter_queryContext() { get type() { return UrlbarUtils.PROVIDER_TYPE.PROFILE; } - isActive(context) { + isActive(_context) { return true; } - async startQuery(context, add) { + async startQuery(_context, _add) { Assert.ok(false, "Provider should no be invoked"); } } @@ -360,7 +360,7 @@ add_task(async function test_filter_priority() { super({ priority, name: `${priority}` + namePart }); this._shouldBeInvoked = shouldBeInvoked; } - async startQuery(context, add) { + async startQuery(_context, _add) { Assert.ok(this._shouldBeInvoked, `${this.name} was invoked`); } } diff --git a/browser/components/urlbar/tests/unit/test_remote_tabs.js b/browser/components/urlbar/tests/unit/test_remote_tabs.js index bb0e708162..a73721d7dc 100644 --- a/browser/components/urlbar/tests/unit/test_remote_tabs.js +++ b/browser/components/urlbar/tests/unit/test_remote_tabs.js @@ -28,7 +28,7 @@ let MockClientsEngine = { Assert.ok(guid.endsWith("desktop") || guid.endsWith("mobile")); return guid.endsWith("mobile") ? "phone" : "desktop"; }, - remoteClientExists(id) { + remoteClientExists(_id) { return true; }, getClientName(id) { @@ -662,7 +662,7 @@ add_task(async function test_duplicate_remote_tabs() { let url = "http://foo.remote.com/"; let tabs = Array(3) .fill(0) - .map((e, i) => ({ + .map(() => ({ urlHistory: [url], title: "A title", lastUsed: Math.floor(Date.now() / 1000), diff --git a/browser/components/urlbar/tests/unit/test_search_suggestions.js b/browser/components/urlbar/tests/unit/test_search_suggestions.js index dc7185149f..22f1ec7617 100644 --- a/browser/components/urlbar/tests/unit/test_search_suggestions.js +++ b/browser/components/urlbar/tests/unit/test_search_suggestions.js @@ -430,7 +430,7 @@ add_task(async function remoteSuggestionsDupeSearchString() { add_task(async function queryIsNotASubstring() { Services.prefs.setBoolPref(SUGGEST_PREF, true); - setSuggestionsFn(searchStr => { + setSuggestionsFn(() => { return ["aaa", "bbb"]; }); @@ -1550,7 +1550,7 @@ add_task(async function restrict_remote_suggestions_after_no_results() { // maxCharsForSearchSuggestions returns 0 results. We set it to 4 here to // avoid constructing a 100+ character string. Services.prefs.setIntPref("browser.urlbar.maxCharsForSearchSuggestions", 4); - setSuggestionsFn(searchStr => { + setSuggestionsFn(() => { return []; }); diff --git a/browser/components/urlbar/tests/unit/xpcshell.toml b/browser/components/urlbar/tests/unit/xpcshell.toml index 188f4390c7..b168d3b987 100644 --- a/browser/components/urlbar/tests/unit/xpcshell.toml +++ b/browser/components/urlbar/tests/unit/xpcshell.toml @@ -128,10 +128,6 @@ prefs = [ ["test_providerOmnibox.js"] ["test_providerOpenTabs.js"] -skip-if = [ - "os == 'mac' && debug", # Bug 1781972 - "os == 'win' && debug", # Bug 1781972 -] ["test_providerPlaces.js"] |