test_search_engine_restyle.js (3404B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 testEngine_setup(); 6 7 const engineDomain = "s.example.com"; 8 add_setup(async function () { 9 Services.prefs.setBoolPref("browser.urlbar.restyleSearches", true); 10 await SearchTestUtils.installSearchExtension({ 11 name: "MozSearch", 12 search_url: `https://${engineDomain}/search`, 13 }); 14 registerCleanupFunction(async () => { 15 Services.prefs.clearUserPref("browser.urlbar.restyleSearches"); 16 }); 17 }); 18 19 add_task(async function test_searchEngine() { 20 let uri = Services.io.newURI(`https://${engineDomain}/search?q=Terms`); 21 await PlacesTestUtils.addVisits({ 22 uri, 23 title: "Terms - SearchEngine Search", 24 }); 25 26 info("Past search terms should be styled."); 27 let context = createContext("term", { isPrivate: false }); 28 await check_results({ 29 context, 30 matches: [ 31 makeSearchResult(context, { 32 engineName: SUGGESTIONS_ENGINE_NAME, 33 heuristic: true, 34 }), 35 makeFormHistoryResult(context, { 36 engineName: "MozSearch", 37 suggestion: "Terms", 38 }), 39 ], 40 }); 41 42 info( 43 "Searching for a superset of the search string in history should not restyle." 44 ); 45 context = createContext("Terms Foo", { isPrivate: false }); 46 await check_results({ 47 context, 48 matches: [ 49 makeSearchResult(context, { 50 engineName: SUGGESTIONS_ENGINE_NAME, 51 heuristic: true, 52 }), 53 ], 54 }); 55 56 info("Bookmarked past searches should not be restyled"); 57 await PlacesTestUtils.addBookmarkWithDetails({ 58 uri, 59 title: "Terms - SearchEngine Search", 60 }); 61 62 context = createContext("term", { isPrivate: false }); 63 await check_results({ 64 context, 65 matches: [ 66 makeSearchResult(context, { 67 engineName: SUGGESTIONS_ENGINE_NAME, 68 heuristic: true, 69 }), 70 makeBookmarkResult(context, { 71 uri: uri.spec, 72 title: "Terms - SearchEngine Search", 73 }), 74 ], 75 }); 76 77 await PlacesUtils.bookmarks.eraseEverything(); 78 79 info("Past search terms should not be styled if restyling is disabled"); 80 Services.prefs.setBoolPref("browser.urlbar.restyleSearches", false); 81 context = createContext("term", { isPrivate: false }); 82 await check_results({ 83 context, 84 matches: [ 85 makeSearchResult(context, { 86 engineName: SUGGESTIONS_ENGINE_NAME, 87 heuristic: true, 88 }), 89 makeVisitResult(context, { 90 uri: uri.spec, 91 title: "Terms - SearchEngine Search", 92 }), 93 ], 94 }); 95 Services.prefs.setBoolPref("browser.urlbar.restyleSearches", true); 96 97 await cleanupPlaces(); 98 }); 99 100 add_task(async function test_extraneousParameters() { 101 info("SERPs in history with extraneous parameters should not be restyled."); 102 let uri = Services.io.newURI( 103 `https://${engineDomain}/search?q=Terms&p=2&type=img` 104 ); 105 await PlacesTestUtils.addVisits({ 106 uri, 107 title: "Terms - SearchEngine Search", 108 }); 109 110 let context = createContext("term", { isPrivate: false }); 111 await check_results({ 112 context, 113 matches: [ 114 makeSearchResult(context, { 115 engineName: SUGGESTIONS_ENGINE_NAME, 116 heuristic: true, 117 }), 118 makeVisitResult(context, { 119 uri: uri.spec, 120 title: "Terms - SearchEngine Search", 121 }), 122 ], 123 }); 124 });