test_casing.js (11408B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const AUTOFILL_PROVIDERNAME = "UrlbarProviderAutofill"; 6 const PLACES_PROVIDERNAME = "UrlbarProviderPlaces"; 7 8 testEngine_setup(); 9 10 add_task(async function test_casing_1() { 11 info("Searching for cased entry 1"); 12 await PlacesTestUtils.addVisits({ 13 uri: Services.io.newURI("http://mozilla.org/test/"), 14 }); 15 let context = createContext("MOZ", { isPrivate: false }); 16 await check_results({ 17 context, 18 autofilled: "MOZilla.org/", 19 completed: "http://mozilla.org/", 20 matches: [ 21 makeVisitResult(context, { 22 uri: "http://mozilla.org/", 23 title: UrlbarTestUtils.trimURL("http://mozilla.org"), 24 heuristic: true, 25 }), 26 makeVisitResult(context, { 27 uri: "http://mozilla.org/test/", 28 title: "test visit for http://mozilla.org/test/", 29 providerName: PLACES_PROVIDERNAME, 30 }), 31 ], 32 }); 33 await cleanupPlaces(); 34 }); 35 36 add_task(async function test_casing_2() { 37 info("Searching for cased entry 2"); 38 await PlacesTestUtils.addVisits({ 39 uri: Services.io.newURI("http://mozilla.org/test/"), 40 }); 41 let context = createContext("mozilla.org/T", { isPrivate: false }); 42 await check_results({ 43 context, 44 autofilled: "mozilla.org/Test/", 45 completed: "http://mozilla.org/test/", 46 matches: [ 47 makeVisitResult(context, { 48 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 49 uri: "http://mozilla.org/test/", 50 title: "test visit for http://mozilla.org/test/", 51 iconUri: "page-icon:http://mozilla.org/test/", 52 heuristic: true, 53 providerName: AUTOFILL_PROVIDERNAME, 54 }), 55 ], 56 }); 57 await cleanupPlaces(); 58 }); 59 60 add_task(async function test_casing_3() { 61 info("Searching for cased entry 3"); 62 await PlacesTestUtils.addVisits({ 63 uri: Services.io.newURI("http://mozilla.org/Test/"), 64 }); 65 let context = createContext("mozilla.org/T", { isPrivate: false }); 66 await check_results({ 67 context, 68 autofilled: "mozilla.org/Test/", 69 completed: "http://mozilla.org/Test/", 70 matches: [ 71 makeVisitResult(context, { 72 uri: "http://mozilla.org/Test/", 73 title: "test visit for http://mozilla.org/Test/", 74 heuristic: true, 75 }), 76 ], 77 }); 78 await cleanupPlaces(); 79 }); 80 81 add_task(async function test_casing_4() { 82 info("Searching for cased entry 4"); 83 await PlacesTestUtils.addVisits({ 84 uri: Services.io.newURI("http://mozilla.org/Test/"), 85 }); 86 let context = createContext("mOzilla.org/t", { isPrivate: false }); 87 await check_results({ 88 context, 89 autofilled: "mOzilla.org/test/", 90 completed: "http://mozilla.org/Test/", 91 matches: [ 92 makeVisitResult(context, { 93 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 94 uri: "http://mozilla.org/Test/", 95 title: "test visit for http://mozilla.org/Test/", 96 iconUri: "page-icon:http://mozilla.org/Test/", 97 heuristic: true, 98 providerName: AUTOFILL_PROVIDERNAME, 99 }), 100 ], 101 }); 102 await cleanupPlaces(); 103 }); 104 105 add_task(async function test_casing_5() { 106 info("Searching for cased entry 5"); 107 await PlacesTestUtils.addVisits({ 108 uri: Services.io.newURI("http://mozilla.org/Test/"), 109 }); 110 let context = createContext("mOzilla.org/T", { isPrivate: false }); 111 await check_results({ 112 context, 113 autofilled: "mOzilla.org/Test/", 114 completed: "http://mozilla.org/Test/", 115 matches: [ 116 makeVisitResult(context, { 117 uri: "http://mozilla.org/Test/", 118 title: "test visit for http://mozilla.org/Test/", 119 heuristic: true, 120 }), 121 ], 122 }); 123 await cleanupPlaces(); 124 }); 125 126 add_task(async function test_untrimmed_casing() { 127 info("Searching for untrimmed cased entry"); 128 await PlacesTestUtils.addVisits({ 129 uri: Services.io.newURI("http://mozilla.org/Test/"), 130 }); 131 let context = createContext("http://mOz", { isPrivate: false }); 132 await check_results({ 133 context, 134 autofilled: "http://mOzilla.org/", 135 completed: "http://mozilla.org/", 136 matches: [ 137 makeVisitResult(context, { 138 uri: "http://mozilla.org/", 139 title: UrlbarTestUtils.trimURL("http://mozilla.org"), 140 heuristic: true, 141 }), 142 makeVisitResult(context, { 143 uri: "http://mozilla.org/Test/", 144 title: "test visit for http://mozilla.org/Test/", 145 providerName: PLACES_PROVIDERNAME, 146 }), 147 ], 148 }); 149 await cleanupPlaces(); 150 }); 151 152 add_task(async function test_untrimmed_www_casing() { 153 info("Searching for untrimmed cased entry with www"); 154 await PlacesTestUtils.addVisits({ 155 uri: Services.io.newURI("http://www.mozilla.org/Test/"), 156 }); 157 let context = createContext("http://www.mOz", { isPrivate: false }); 158 await check_results({ 159 context, 160 autofilled: "http://www.mOzilla.org/", 161 completed: "http://www.mozilla.org/", 162 matches: [ 163 makeVisitResult(context, { 164 uri: "http://www.mozilla.org/", 165 title: UrlbarTestUtils.trimURL("http://www.mozilla.org"), 166 heuristic: true, 167 }), 168 makeVisitResult(context, { 169 uri: "http://www.mozilla.org/Test/", 170 title: "test visit for http://www.mozilla.org/Test/", 171 providerName: PLACES_PROVIDERNAME, 172 }), 173 ], 174 }); 175 await cleanupPlaces(); 176 }); 177 178 add_task(async function test_untrimmed_path_casing() { 179 info("Searching for untrimmed cased entry with path"); 180 await PlacesTestUtils.addVisits({ 181 uri: Services.io.newURI("http://mozilla.org/Test/"), 182 }); 183 let context = createContext("http://mOzilla.org/t", { isPrivate: false }); 184 await check_results({ 185 context, 186 autofilled: "http://mOzilla.org/test/", 187 completed: "http://mozilla.org/Test/", 188 matches: [ 189 makeVisitResult(context, { 190 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 191 uri: "http://mozilla.org/Test/", 192 title: "test visit for http://mozilla.org/Test/", 193 iconUri: "page-icon:http://mozilla.org/Test/", 194 heuristic: true, 195 providerName: AUTOFILL_PROVIDERNAME, 196 }), 197 ], 198 }); 199 await cleanupPlaces(); 200 }); 201 202 add_task(async function test_untrimmed_path_casing_2() { 203 info("Searching for untrimmed cased entry with path 2"); 204 await PlacesTestUtils.addVisits({ 205 uri: Services.io.newURI("http://mozilla.org/Test/"), 206 }); 207 let context = createContext("http://mOzilla.org/T", { isPrivate: false }); 208 await check_results({ 209 context, 210 autofilled: "http://mOzilla.org/Test/", 211 completed: "http://mozilla.org/Test/", 212 matches: [ 213 makeVisitResult(context, { 214 uri: "http://mozilla.org/Test/", 215 title: "test visit for http://mozilla.org/Test/", 216 heuristic: true, 217 }), 218 ], 219 }); 220 await cleanupPlaces(); 221 }); 222 223 add_task(async function test_untrimmed_path_www_casing() { 224 info("Searching for untrimmed cased entry with www and path"); 225 await PlacesTestUtils.addVisits({ 226 uri: Services.io.newURI("http://www.mozilla.org/Test/"), 227 }); 228 let context = createContext("http://www.mOzilla.org/t", { isPrivate: false }); 229 await check_results({ 230 context, 231 autofilled: "http://www.mOzilla.org/test/", 232 completed: "http://www.mozilla.org/Test/", 233 matches: [ 234 makeVisitResult(context, { 235 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 236 uri: "http://www.mozilla.org/Test/", 237 title: "test visit for http://www.mozilla.org/Test/", 238 iconUri: "page-icon:http://www.mozilla.org/Test/", 239 heuristic: true, 240 providerName: AUTOFILL_PROVIDERNAME, 241 }), 242 ], 243 }); 244 await cleanupPlaces(); 245 }); 246 247 add_task(async function test_untrimmed_path_www_casing_2() { 248 info("Searching for untrimmed cased entry with www and path 2"); 249 await PlacesTestUtils.addVisits({ 250 uri: Services.io.newURI("http://www.mozilla.org/Test/"), 251 }); 252 let context = createContext("http://www.mOzilla.org/T", { isPrivate: false }); 253 await check_results({ 254 context, 255 autofilled: "http://www.mOzilla.org/Test/", 256 completed: "http://www.mozilla.org/Test/", 257 matches: [ 258 makeVisitResult(context, { 259 uri: "http://www.mozilla.org/Test/", 260 title: "test visit for http://www.mozilla.org/Test/", 261 heuristic: true, 262 }), 263 ], 264 }); 265 await cleanupPlaces(); 266 }); 267 268 add_task(async function test_searching() { 269 let uri1 = Services.io.newURI("http://dummy/1/"); 270 let uri2 = Services.io.newURI("http://dummy/2/"); 271 let uri3 = Services.io.newURI("http://dummy/3/"); 272 let uri4 = Services.io.newURI("http://dummy/4/"); 273 let uri5 = Services.io.newURI("http://dummy/5/"); 274 275 await PlacesTestUtils.addVisits([ 276 { uri: uri1, title: "uppercase lambda \u039B" }, 277 { uri: uri2, title: "lowercase lambda \u03BB" }, 278 { uri: uri3, title: "symbol \u212A" }, // kelvin 279 { uri: uri4, title: "uppercase K" }, 280 { uri: uri5, title: "lowercase k" }, 281 ]); 282 283 info("Search for lowercase lambda"); 284 let context = createContext("\u03BB", { isPrivate: false }); 285 await check_results({ 286 context, 287 matches: [ 288 makeSearchResult(context, { 289 engineName: SUGGESTIONS_ENGINE_NAME, 290 heuristic: true, 291 }), 292 makeVisitResult(context, { 293 uri: uri2.spec, 294 title: "lowercase lambda \u03BB", 295 }), 296 makeVisitResult(context, { 297 uri: uri1.spec, 298 title: "uppercase lambda \u039B", 299 }), 300 ], 301 }); 302 303 info("Search for uppercase lambda"); 304 context = createContext("\u039B", { isPrivate: false }); 305 await check_results({ 306 context, 307 matches: [ 308 makeSearchResult(context, { 309 engineName: SUGGESTIONS_ENGINE_NAME, 310 heuristic: true, 311 }), 312 makeVisitResult(context, { 313 uri: uri2.spec, 314 title: "lowercase lambda \u03BB", 315 }), 316 makeVisitResult(context, { 317 uri: uri1.spec, 318 title: "uppercase lambda \u039B", 319 }), 320 ], 321 }); 322 323 info("Search for kelvin sign"); 324 context = createContext("\u212A", { isPrivate: false }); 325 await check_results({ 326 context, 327 matches: [ 328 makeSearchResult(context, { 329 engineName: SUGGESTIONS_ENGINE_NAME, 330 heuristic: true, 331 }), 332 makeVisitResult(context, { uri: uri5.spec, title: "lowercase k" }), 333 makeVisitResult(context, { uri: uri4.spec, title: "uppercase K" }), 334 makeVisitResult(context, { uri: uri3.spec, title: "symbol \u212A" }), 335 ], 336 }); 337 338 info("Search for lowercase k"); 339 context = createContext("k", { isPrivate: false }); 340 await check_results({ 341 context, 342 matches: [ 343 makeSearchResult(context, { 344 engineName: SUGGESTIONS_ENGINE_NAME, 345 heuristic: true, 346 }), 347 makeVisitResult(context, { uri: uri5.spec, title: "lowercase k" }), 348 makeVisitResult(context, { uri: uri4.spec, title: "uppercase K" }), 349 makeVisitResult(context, { uri: uri3.spec, title: "symbol \u212A" }), 350 ], 351 }); 352 353 info("Search for uppercase k"); 354 355 context = createContext("K", { isPrivate: false }); 356 await check_results({ 357 context, 358 matches: [ 359 makeSearchResult(context, { 360 engineName: SUGGESTIONS_ENGINE_NAME, 361 heuristic: true, 362 }), 363 makeVisitResult(context, { uri: uri5.spec, title: "lowercase k" }), 364 makeVisitResult(context, { uri: uri4.spec, title: "uppercase K" }), 365 makeVisitResult(context, { uri: uri3.spec, title: "symbol \u212A" }), 366 ], 367 }); 368 369 await cleanupPlaces(); 370 });