test_richsuggestions_order.js (2323B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * Tests that rich suggestion results are ordered in the 6 * same order they were returned from the API. 7 */ 8 9 const SUGGEST_ENABLED_PREF = "browser.search.suggest.enabled"; 10 const RICH_SUGGESTIONS_PREF = "browser.urlbar.richSuggestions.featureGate"; 11 12 const QUICKACTIONS_URLBAR_PREF = "quickactions.enabled"; 13 14 add_setup(async function () { 15 let engine = await addTestTailSuggestionsEngine(defaultRichSuggestionsFn); 16 17 // Install the test engine. 18 let oldDefaultEngine = await Services.search.getDefault(); 19 registerCleanupFunction(async () => { 20 Services.search.setDefault( 21 oldDefaultEngine, 22 Ci.nsISearchService.CHANGE_REASON_UNKNOWN 23 ); 24 Services.prefs.clearUserPref(RICH_SUGGESTIONS_PREF); 25 Services.prefs.clearUserPref(SUGGEST_ENABLED_PREF); 26 UrlbarPrefs.clear(QUICKACTIONS_URLBAR_PREF); 27 }); 28 Services.search.setDefault(engine, Ci.nsISearchService.CHANGE_REASON_UNKNOWN); 29 Services.prefs.setBoolPref(RICH_SUGGESTIONS_PREF, true); 30 Services.prefs.setBoolPref(SUGGEST_ENABLED_PREF, true); 31 UrlbarPrefs.set(QUICKACTIONS_URLBAR_PREF, false); 32 }); 33 34 /** 35 * Tests that non-tail suggestion providers still return results correctly when 36 * the tailSuggestions pref is enabled. 37 */ 38 add_task(async function test_richsuggestions_order() { 39 const query = "what time is it in t"; 40 let context = createContext(query, { isPrivate: false }); 41 42 let defaultRichResult = { 43 engineName: TAIL_SUGGESTIONS_ENGINE_NAME, 44 isRichSuggestion: true, 45 }; 46 47 await check_results({ 48 context, 49 matches: [ 50 makeSearchResult(context, { 51 engineName: TAIL_SUGGESTIONS_ENGINE_NAME, 52 heuristic: true, 53 }), 54 makeSearchResult( 55 context, 56 Object.assign(defaultRichResult, { 57 suggestion: query + "oronto", 58 }) 59 ), 60 makeSearchResult(context, { 61 engineName: TAIL_SUGGESTIONS_ENGINE_NAME, 62 suggestion: query + "unisia", 63 }), 64 makeSearchResult( 65 context, 66 Object.assign(defaultRichResult, { 67 suggestion: query + "acoma", 68 }) 69 ), 70 makeSearchResult(context, { 71 engineName: TAIL_SUGGESTIONS_ENGINE_NAME, 72 suggestion: query + "aipei", 73 }), 74 ], 75 }); 76 });