diff options
Diffstat (limited to 'browser/components/urlbar/tests/unit')
3 files changed, 103 insertions, 77 deletions
diff --git a/browser/components/urlbar/tests/unit/test_autofill_origins.js b/browser/components/urlbar/tests/unit/test_autofill_origins.js index 33e462a8af..454881b933 100644 --- a/browser/components/urlbar/tests/unit/test_autofill_origins.js +++ b/browser/components/urlbar/tests/unit/test_autofill_origins.js @@ -1039,3 +1039,68 @@ async function doTitleTest({ visits, input, expected }) { await cleanup(); } + +/* Tests sorting order when only unvisited bookmarks are available (e.g. in + permanent private browsing mode), then the only information we have is the + number of bookmarks per origin, and we're going to use that. */ +add_task(async function just_multiple_unvisited_bookmarks() { + // These are sorted to avoid confusion with natural sorting, so the one with + // the highest score is added in the middle. + let filledUrl = "https://www.tld2.com/"; + let urls = [ + { + url: "https://tld1.com/", + count: 1, + }, + { + url: "https://tld2.com/", + count: 2, + }, + { + url: filledUrl, + count: 2, + }, + { + url: "https://tld3.com/", + count: 3, + }, + ]; + + await PlacesUtils.history.clear(); + for (let { url, count } of urls) { + while (count--) { + await PlacesTestUtils.addBookmarkWithDetails({ + uri: url, + }); + } + } + await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); + + let context = createContext("tld", { isPrivate: false }); + await check_results({ + context, + autofilled: "tld2.com/", + completed: filledUrl, + matches: [ + makeVisitResult(context, { + uri: filledUrl, + title: "A bookmark", + heuristic: true, + }), + makeBookmarkResult(context, { + uri: "https://tld3.com/", + title: "A bookmark", + }), + makeBookmarkResult(context, { + uri: "https://tld2.com/", + title: "A bookmark", + }), + makeBookmarkResult(context, { + uri: "https://tld1.com/", + title: "A bookmark", + }), + ], + }); + + await cleanup(); +}); diff --git a/browser/components/urlbar/tests/unit/test_quickactions.js b/browser/components/urlbar/tests/unit/test_quickactions.js index 00206c77b2..30e3fbdd95 100644 --- a/browser/components/urlbar/tests/unit/test_quickactions.js +++ b/browser/components/urlbar/tests/unit/test_quickactions.js @@ -5,108 +5,58 @@ "use strict"; ChromeUtils.defineESModuleGetters(this, { - UrlbarProviderQuickActions: - "resource:///modules/UrlbarProviderQuickActions.sys.mjs", + ActionsProviderQuickActions: + "resource:///modules/ActionsProviderQuickActions.sys.mjs", }); -let expectedMatch = (key, inputLength) => ({ - type: UrlbarUtils.RESULT_TYPE.DYNAMIC, - source: UrlbarUtils.RESULT_SOURCE.ACTIONS, - heuristic: false, - payload: { - results: [{ key }], - dynamicType: "quickactions", - inQuickActionsSearchMode: false, - helpUrl: UrlbarProviderQuickActions.helpUrl, - inputLength, - }, -}); - -testEngine_setup(); - add_setup(async () => { UrlbarPrefs.set("quickactions.enabled", true); - UrlbarPrefs.set("suggest.quickactions", true); - UrlbarProviderQuickActions.addAction("newaction", { + ActionsProviderQuickActions.addAction("newaction", { commands: ["newaction"], }); registerCleanupFunction(async () => { UrlbarPrefs.clear("quickactions.enabled"); - UrlbarPrefs.clear("suggest.quickactions"); - UrlbarProviderQuickActions.removeAction("newaction"); + ActionsProviderQuickActions.removeAction("newaction"); }); }); add_task(async function nomatch() { - let context = createContext("this doesnt match", { - providers: [UrlbarProviderQuickActions.name], - isPrivate: false, - }); - await check_results({ - context, - matches: [], - }); -}); - -add_task(async function quickactions_disabled() { - UrlbarPrefs.set("suggest.quickactions", false); - let context = createContext("new", { - providers: [UrlbarProviderQuickActions.name], - isPrivate: false, - }); - await check_results({ - context, - matches: [], - }); + let context = createContext("this doesnt match", {}); + let result = await ActionsProviderQuickActions.queryAction(context); + Assert.ok(result === null, "there were no matches"); }); add_task(async function quickactions_match() { - UrlbarPrefs.set("suggest.quickactions", true); - let context = createContext("new", { - providers: [UrlbarProviderQuickActions.name], - isPrivate: false, - }); - await check_results({ - context, - matches: [expectedMatch("newaction", 3)], - }); + let context = createContext("new", {}); + let result = await ActionsProviderQuickActions.queryAction(context); + Assert.ok(result.key == "newaction", "Matched the new action"); }); add_task(async function duplicate_matches() { - UrlbarProviderQuickActions.addAction("testaction", { + ActionsProviderQuickActions.addAction("testaction", { commands: ["testaction", "test"], }); - let context = createContext("testaction", { - providers: [UrlbarProviderQuickActions.name], - isPrivate: false, - }); + let context = createContext("test", {}); + let result = await ActionsProviderQuickActions.queryAction(context); - await check_results({ - context, - matches: [expectedMatch("testaction", 10)], - }); + Assert.ok(result.key == "testaction", "Matched the test action"); - UrlbarProviderQuickActions.removeAction("testaction"); + ActionsProviderQuickActions.removeAction("testaction"); }); add_task(async function remove_action() { - UrlbarProviderQuickActions.addAction("testaction", { + ActionsProviderQuickActions.addAction("testaction", { commands: ["testaction"], }); - UrlbarProviderQuickActions.removeAction("testaction"); + ActionsProviderQuickActions.removeAction("testaction"); - let context = createContext("test", { - providers: [UrlbarProviderQuickActions.name], - isPrivate: false, - }); + let context = createContext("test", {}); + let result = await ActionsProviderQuickActions.queryAction(context); - await check_results({ - context, - matches: [], - }); + Assert.ok(result === null, "there were no matches"); }); add_task(async function minimum_search_string() { @@ -114,13 +64,18 @@ add_task(async function minimum_search_string() { for (let minimumSearchString of [0, 3]) { UrlbarPrefs.set("quickactions.minimumSearchString", minimumSearchString); for (let i = 1; i < 4; i++) { - let context = createContext(searchString.substring(0, i), { - providers: [UrlbarProviderQuickActions.name], - isPrivate: false, - }); - let matches = - i >= minimumSearchString ? [expectedMatch("newaction", i)] : []; - await check_results({ context, matches }); + let context = createContext(searchString.substring(0, i), {}); + let result = await ActionsProviderQuickActions.queryAction(context); + + if (i >= minimumSearchString) { + Assert.ok(result.key == "newaction", "Matched the new action"); + } else { + Assert.equal( + ActionsProviderQuickActions.isActive(context), + false, + "QuickActions Provider is not active" + ); + } } } UrlbarPrefs.clear("quickactions.minimumSearchString"); diff --git a/browser/components/urlbar/tests/unit/test_tokenizer.js b/browser/components/urlbar/tests/unit/test_tokenizer.js index 835d1a5909..76b2c31ac2 100644 --- a/browser/components/urlbar/tests/unit/test_tokenizer.js +++ b/browser/components/urlbar/tests/unit/test_tokenizer.js @@ -32,6 +32,12 @@ add_task(async function test_tokenizer() { ], }, { + desc: "do not separate restriction char at beginning in search mode", + searchMode: { engineName: "testEngine" }, + searchString: `${UrlbarTokenizer.RESTRICT.SEARCH}test`, + expectedTokens: [{ value: "?test", type: UrlbarTokenizer.TYPE.TEXT }], + }, + { desc: "separate restriction char at end", searchString: `test ${UrlbarTokenizer.RESTRICT.BOOKMARK}`, expectedTokens: [ |