test_providerHistoryUrlHeuristic.js (7310B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test for the behavior of UrlbarProviderHistoryUrlHeuristic. 7 8 add_setup(async function () { 9 Services.prefs.setBoolPref("browser.search.suggest.enabled", false); 10 Services.prefs.setBoolPref("browser.urlbar.autoFill", false); 11 Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false); 12 registerCleanupFunction(async () => { 13 Services.prefs.clearUserPref("browser.search.suggest.enabled"); 14 Services.prefs.clearUserPref("browser.urlbar.autoFill"); 15 Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions"); 16 await PlacesUtils.history.clear(); 17 await PlacesUtils.bookmarks.eraseEverything(); 18 }); 19 }); 20 21 add_task(async function test_after_clear_history() { 22 await PlacesTestUtils.addVisits([ 23 { uri: "https://example.com/", title: "VISIT" }, 24 ]); 25 await PlacesTestUtils.addBookmarkWithDetails({ 26 uri: "https://example.com/", 27 title: "BOOKMARK", 28 }); 29 30 const before = createContext("example.com", { isPrivate: false }); 31 await check_results({ 32 context: before, 33 matches: [ 34 makeVisitResult(before, { 35 uri: "http://example.com/", 36 title: "VISIT", 37 iconUri: "page-icon:https://example.com/", 38 heuristic: true, 39 providerName: "UrlbarProviderHistoryUrlHeuristic", 40 }), 41 makeBookmarkResult(before, { 42 uri: "https://example.com/", 43 title: "BOOKMARK", 44 }), 45 ], 46 }); 47 48 await PlacesUtils.history.clear(); 49 50 const after = createContext("example.com", { isPrivate: false }); 51 await check_results({ 52 context: after, 53 matches: [ 54 makeVisitResult(after, { 55 uri: "http://example.com/", 56 title: "BOOKMARK", 57 iconUri: "page-icon:https://example.com/", 58 heuristic: true, 59 providerName: "UrlbarProviderHistoryUrlHeuristic", 60 }), 61 makeBookmarkResult(after, { 62 uri: "https://example.com/", 63 title: "BOOKMARK", 64 }), 65 ], 66 }); 67 68 await PlacesUtils.bookmarks.eraseEverything(); 69 }); 70 71 add_task(async function test_basic() { 72 await PlacesTestUtils.addVisits([ 73 { uri: "https://example.com/", title: "Example COM" }, 74 ]); 75 76 const testCases = [ 77 { 78 input: "https://example.com/", 79 expected: context => [ 80 makeVisitResult(context, { 81 uri: "https://example.com/", 82 title: "Example COM", 83 iconUri: "page-icon:https://example.com/", 84 heuristic: true, 85 providerName: "UrlbarProviderHistoryUrlHeuristic", 86 }), 87 ], 88 }, 89 { 90 input: "https://www.example.com/", 91 expected: context => [ 92 makeVisitResult(context, { 93 uri: "https://www.example.com/", 94 title: "Example COM", 95 iconUri: "page-icon:https://example.com/", 96 heuristic: true, 97 providerName: "UrlbarProviderHistoryUrlHeuristic", 98 }), 99 ], 100 }, 101 { 102 input: "http://example.com/", 103 expected: context => [ 104 makeVisitResult(context, { 105 uri: "http://example.com/", 106 title: "Example COM", 107 iconUri: "page-icon:https://example.com/", 108 heuristic: true, 109 providerName: "UrlbarProviderHistoryUrlHeuristic", 110 }), 111 makeVisitResult(context, { 112 uri: "https://example.com/", 113 title: "Example COM", 114 iconUri: "page-icon:https://example.com/", 115 providerName: "UrlbarProviderPlaces", 116 }), 117 ], 118 }, 119 { 120 input: "example.com", 121 expected: context => [ 122 makeVisitResult(context, { 123 uri: "http://example.com/", 124 title: "Example COM", 125 iconUri: "page-icon:https://example.com/", 126 heuristic: true, 127 providerName: "UrlbarProviderHistoryUrlHeuristic", 128 }), 129 makeVisitResult(context, { 130 uri: "https://example.com/", 131 title: "Example COM", 132 iconUri: "page-icon:https://example.com/", 133 providerName: "UrlbarProviderPlaces", 134 }), 135 ], 136 }, 137 { 138 input: "www.example.com", 139 expected: context => [ 140 makeVisitResult(context, { 141 uri: "http://www.example.com/", 142 title: "Example COM", 143 iconUri: "page-icon:https://example.com/", 144 heuristic: true, 145 providerName: "UrlbarProviderHistoryUrlHeuristic", 146 }), 147 ], 148 }, 149 { 150 input: "htp:example.com", 151 expected: context => [ 152 makeVisitResult(context, { 153 uri: "http://example.com/", 154 title: "Example COM", 155 iconUri: "page-icon:https://example.com/", 156 heuristic: true, 157 providerName: "UrlbarProviderHistoryUrlHeuristic", 158 }), 159 ], 160 }, 161 ]; 162 163 for (const { input, expected } of testCases) { 164 info(`Test with "${input}"`); 165 const context = createContext(input, { isPrivate: false }); 166 await check_results({ 167 context, 168 matches: expected(context), 169 }); 170 } 171 172 await PlacesUtils.history.clear(); 173 }); 174 175 add_task(async function test_null_title() { 176 await PlacesTestUtils.addVisits([{ uri: "https://example.com/", title: "" }]); 177 178 const context = createContext("https://example.com/", { isPrivate: false }); 179 await check_results({ 180 context, 181 matches: [ 182 makeVisitResult(context, { 183 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 184 uri: "https://example.com/", 185 title: "https://example.com/", 186 iconUri: "page-icon:https://example.com/", 187 heuristic: true, 188 providerName: "UrlbarProviderHeuristicFallback", 189 }), 190 ], 191 }); 192 193 await PlacesUtils.history.clear(); 194 }); 195 196 add_task(async function test_over_max_length_text() { 197 let uri = "https://example.com/"; 198 for (; uri.length < UrlbarUtils.MAX_TEXT_LENGTH; ) { 199 uri += "0123456789"; 200 } 201 202 await PlacesTestUtils.addVisits([{ uri, title: "Example MAX" }]); 203 204 const context = createContext(uri, { isPrivate: false }); 205 await check_results({ 206 context, 207 matches: [ 208 makeVisitResult(context, { 209 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 210 uri, 211 title: uri, 212 iconUri: "page-icon:https://example.com/", 213 heuristic: true, 214 providerName: "UrlbarProviderHeuristicFallback", 215 }), 216 ], 217 }); 218 219 await PlacesUtils.history.clear(); 220 }); 221 222 add_task(async function test_unsupported_protocol() { 223 await PlacesTestUtils.addBookmarkWithDetails({ 224 uri: "about:robots", 225 title: "Robots!", 226 }); 227 228 const context = createContext("about:robots", { isPrivate: false }); 229 await check_results({ 230 context, 231 matches: [ 232 makeVisitResult(context, { 233 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 234 uri: "about:robots", 235 title: "about:robots", 236 heuristic: true, 237 providerName: "UrlbarProviderHeuristicFallback", 238 }), 239 makeBookmarkResult(context, { 240 uri: "about:robots", 241 title: "Robots!", 242 }), 243 makeVisitResult(context, { 244 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 245 uri: "about:robots", 246 title: "about:robots", 247 iconUri: "page-icon:about:robots", 248 tags: null, 249 providerName: "UrlbarProviderAboutPages", 250 }), 251 ], 252 }); 253 254 await PlacesUtils.bookmarks.eraseEverything(); 255 });