test_autofill_urls.js (25381B)
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 "use strict"; 6 7 const HEURISTIC_FALLBACK_PROVIDERNAME = "UrlbarProviderHeuristicFallback"; 8 const PLACES_PROVIDERNAME = "UrlbarProviderPlaces"; 9 10 // "example.com/foo/" should match http://example.com/foo/. 11 testEngine_setup(); 12 13 registerCleanupFunction(async () => { 14 Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions"); 15 }); 16 Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false); 17 18 add_task(async function multipleSlashes() { 19 await PlacesTestUtils.addVisits([ 20 { 21 uri: "http://example.com/foo/", 22 }, 23 ]); 24 let context = createContext("example.com/foo/", { isPrivate: false }); 25 await check_results({ 26 context, 27 autofilled: "example.com/foo/", 28 completed: "http://example.com/foo/", 29 matches: [ 30 makeVisitResult(context, { 31 uri: "http://example.com/foo/", 32 title: "test visit for http://example.com/foo/", 33 heuristic: true, 34 }), 35 ], 36 }); 37 await cleanupPlaces(); 38 }); 39 40 // "example.com:8888/f" should match http://example.com:8888/foo. 41 add_task(async function port() { 42 await PlacesTestUtils.addVisits([ 43 { 44 uri: "http://example.com:8888/foo", 45 }, 46 ]); 47 let context = createContext("example.com:8888/f", { isPrivate: false }); 48 await check_results({ 49 context, 50 autofilled: "example.com:8888/foo", 51 completed: "http://example.com:8888/foo", 52 matches: [ 53 makeVisitResult(context, { 54 uri: "http://example.com:8888/foo", 55 title: "test visit for http://example.com:8888/foo", 56 heuristic: true, 57 }), 58 ], 59 }); 60 await cleanupPlaces(); 61 }); 62 63 // "example.com:8999/f" should *not* autofill http://example.com:8888/foo. 64 add_task(async function portNoMatch() { 65 await PlacesTestUtils.addVisits([ 66 { 67 uri: "http://example.com:8888/foo", 68 }, 69 ]); 70 let context = createContext("example.com:8999/f", { isPrivate: false }); 71 await check_results({ 72 context, 73 matches: [ 74 makeVisitResult(context, { 75 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 76 uri: "http://example.com:8999/f", 77 title: "example.com:8999/f", 78 iconUri: "page-icon:http://example.com:8999/", 79 heuristic: true, 80 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 81 }), 82 ], 83 }); 84 await cleanupPlaces(); 85 }); 86 87 // autofill to the next slash 88 add_task(async function port() { 89 await PlacesTestUtils.addVisits([ 90 { 91 uri: "http://example.com:8888/foo/bar/baz", 92 }, 93 ]); 94 let context = createContext("example.com:8888/foo/b", { isPrivate: false }); 95 await check_results({ 96 context, 97 autofilled: "example.com:8888/foo/bar/", 98 completed: "http://example.com:8888/foo/bar/", 99 matches: [ 100 makeVisitResult(context, { 101 uri: "http://example.com:8888/foo/bar/", 102 title: UrlbarTestUtils.trimURL("http://example.com:8888/foo/bar/"), 103 heuristic: true, 104 }), 105 makeVisitResult(context, { 106 uri: "http://example.com:8888/foo/bar/baz", 107 title: "test visit for http://example.com:8888/foo/bar/baz", 108 tags: [], 109 providerName: PLACES_PROVIDERNAME, 110 }), 111 ], 112 }); 113 await cleanupPlaces(); 114 }); 115 116 // autofill to the next slash, end of url 117 add_task(async function port() { 118 await PlacesTestUtils.addVisits([ 119 { 120 uri: "http://example.com:8888/foo/bar/baz", 121 }, 122 ]); 123 let context = createContext("example.com:8888/foo/bar/b", { 124 isPrivate: false, 125 }); 126 await check_results({ 127 context, 128 autofilled: "example.com:8888/foo/bar/baz", 129 completed: "http://example.com:8888/foo/bar/baz", 130 matches: [ 131 makeVisitResult(context, { 132 uri: "http://example.com:8888/foo/bar/baz", 133 title: "test visit for http://example.com:8888/foo/bar/baz", 134 heuristic: true, 135 }), 136 ], 137 }); 138 await cleanupPlaces(); 139 }); 140 141 // autofill with case insensitive from history and bookmark. 142 add_task(async function caseInsensitiveFromHistoryAndBookmark() { 143 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true); 144 Services.prefs.setBoolPref("browser.urlbar.suggest.history", true); 145 146 await PlacesTestUtils.addVisits([ 147 { 148 uri: "http://example.com/foo", 149 }, 150 ]); 151 152 await testCaseInsensitive(); 153 154 Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark"); 155 Services.prefs.clearUserPref("browser.urlbar.suggest.history"); 156 await cleanupPlaces(); 157 }); 158 159 // autofill with case insensitive from history. 160 add_task(async function caseInsensitiveFromHistory() { 161 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 162 Services.prefs.setBoolPref("browser.urlbar.suggest.history", true); 163 164 await PlacesTestUtils.addVisits([ 165 { 166 uri: "http://example.com/foo", 167 }, 168 ]); 169 170 await testCaseInsensitive(); 171 172 Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark"); 173 Services.prefs.clearUserPref("browser.urlbar.suggest.history"); 174 await cleanupPlaces(); 175 }); 176 177 // autofill with case insensitive from bookmark. 178 add_task(async function caseInsensitiveFromBookmark() { 179 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", true); 180 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 181 182 await PlacesTestUtils.addBookmarkWithDetails({ 183 uri: "http://example.com/foo", 184 }); 185 186 await testCaseInsensitive(true); 187 188 Services.prefs.clearUserPref("browser.urlbar.suggest.bookmark"); 189 Services.prefs.clearUserPref("browser.urlbar.suggest.history"); 190 await cleanupPlaces(); 191 }); 192 193 // should *not* autofill if the URI fragment does not match with case-sensitive. 194 add_task(async function uriFragmentCaseSensitiveNoMatch() { 195 await PlacesTestUtils.addVisits([ 196 { 197 uri: "http://example.com/#TEST", 198 }, 199 ]); 200 const context = createContext("http://example.com/#t", { isPrivate: false }); 201 await check_results({ 202 context, 203 matches: [ 204 makeVisitResult(context, { 205 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 206 uri: "http://example.com/#t", 207 title: "http://example.com/#t", 208 heuristic: true, 209 }), 210 makeVisitResult(context, { 211 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 212 uri: "http://example.com/#TEST", 213 title: "test visit for http://example.com/#TEST", 214 tags: [], 215 }), 216 ], 217 }); 218 219 await cleanupPlaces(); 220 }); 221 222 // should autofill if the URI fragment matches with case-sensitive. 223 add_task(async function uriFragmentCaseSensitive() { 224 await PlacesTestUtils.addVisits([ 225 { 226 uri: "http://example.com/#TEST", 227 }, 228 ]); 229 const context = createContext("http://example.com/#T", { isPrivate: false }); 230 await check_results({ 231 context, 232 autofilled: "http://example.com/#TEST", 233 completed: "http://example.com/#TEST", 234 matches: [ 235 makeVisitResult(context, { 236 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 237 uri: "http://example.com/#TEST", 238 title: "test visit for http://example.com/#TEST", 239 heuristic: true, 240 }), 241 ], 242 }); 243 244 await cleanupPlaces(); 245 }); 246 247 add_task(async function uriCase() { 248 await PlacesTestUtils.addVisits([ 249 { 250 uri: "http://example.com/ABC/DEF", 251 }, 252 ]); 253 254 const testData = [ 255 { 256 input: "example.COM", 257 expected: { 258 autofilled: "example.COM/", 259 completed: "http://example.com/", 260 results: [ 261 context => 262 makeVisitResult(context, { 263 uri: "http://example.com/", 264 title: UrlbarTestUtils.trimURL("http://example.com/"), 265 heuristic: true, 266 }), 267 context => 268 makeVisitResult(context, { 269 uri: "http://example.com/ABC/DEF", 270 title: "test visit for http://example.com/ABC/DEF", 271 }), 272 ], 273 }, 274 }, 275 { 276 input: "example.COM/", 277 expected: { 278 autofilled: "example.COM/", 279 completed: "http://example.com/", 280 results: [ 281 context => 282 makeVisitResult(context, { 283 uri: "http://example.com/", 284 title: UrlbarTestUtils.trimURL("http://example.com/", { 285 removeSingleTrailingSlash: false, 286 }), 287 heuristic: true, 288 }), 289 context => 290 makeVisitResult(context, { 291 uri: "http://example.com/ABC/DEF", 292 title: "test visit for http://example.com/ABC/DEF", 293 }), 294 ], 295 }, 296 }, 297 { 298 input: "example.COM/a", 299 expected: { 300 autofilled: "example.COM/aBC/", 301 completed: "http://example.com/ABC/", 302 results: [ 303 context => 304 makeVisitResult(context, { 305 uri: "http://example.com/ABC/", 306 title: UrlbarTestUtils.trimURL("http://example.com/ABC/"), 307 heuristic: true, 308 }), 309 context => 310 makeVisitResult(context, { 311 uri: "http://example.com/ABC/DEF", 312 title: "test visit for http://example.com/ABC/DEF", 313 }), 314 ], 315 }, 316 }, 317 { 318 input: "example.com/ab", 319 expected: { 320 autofilled: "example.com/abC/", 321 completed: "http://example.com/ABC/", 322 results: [ 323 context => 324 makeVisitResult(context, { 325 uri: "http://example.com/ABC/", 326 title: UrlbarTestUtils.trimURL("http://example.com/ABC/"), 327 heuristic: true, 328 }), 329 context => 330 makeVisitResult(context, { 331 uri: "http://example.com/ABC/DEF", 332 title: "test visit for http://example.com/ABC/DEF", 333 }), 334 ], 335 }, 336 }, 337 { 338 input: "example.com/abc", 339 expected: { 340 autofilled: "example.com/abc/", 341 completed: "http://example.com/ABC/", 342 results: [ 343 context => 344 makeVisitResult(context, { 345 uri: "http://example.com/ABC/", 346 title: UrlbarTestUtils.trimURL("http://example.com/ABC/"), 347 heuristic: true, 348 }), 349 context => 350 makeVisitResult(context, { 351 uri: "http://example.com/ABC/DEF", 352 title: "test visit for http://example.com/ABC/DEF", 353 }), 354 ], 355 }, 356 }, 357 { 358 input: "example.com/abc/", 359 expected: { 360 autofilled: "example.com/abc/", 361 completed: "http://example.com/abc/", 362 results: [ 363 context => 364 makeVisitResult(context, { 365 uri: "http://example.com/abc/", 366 title: UrlbarTestUtils.trimURL("http://example.com/abc/"), 367 heuristic: true, 368 }), 369 context => 370 makeVisitResult(context, { 371 uri: "http://example.com/ABC/DEF", 372 title: "test visit for http://example.com/ABC/DEF", 373 }), 374 ], 375 }, 376 }, 377 { 378 input: "example.com/abc/d", 379 expected: { 380 autofilled: "example.com/abc/dEF", 381 completed: "http://example.com/ABC/DEF", 382 results: [ 383 context => 384 makeVisitResult(context, { 385 uri: "http://example.com/ABC/DEF", 386 title: "test visit for http://example.com/ABC/DEF", 387 heuristic: true, 388 }), 389 ], 390 }, 391 }, 392 { 393 input: "example.com/abc/de", 394 expected: { 395 autofilled: "example.com/abc/deF", 396 completed: "http://example.com/ABC/DEF", 397 results: [ 398 context => 399 makeVisitResult(context, { 400 uri: "http://example.com/ABC/DEF", 401 title: "test visit for http://example.com/ABC/DEF", 402 heuristic: true, 403 }), 404 ], 405 }, 406 }, 407 { 408 input: "example.com/abc/def", 409 expected: { 410 autofilled: "example.com/abc/def", 411 completed: "http://example.com/abc/def", 412 results: [ 413 context => 414 makeVisitResult(context, { 415 uri: "http://example.com/abc/def", 416 title: UrlbarTestUtils.trimURL("http://example.com/abc/def"), 417 heuristic: true, 418 }), 419 context => 420 makeVisitResult(context, { 421 uri: "http://example.com/ABC/DEF", 422 title: "test visit for http://example.com/ABC/DEF", 423 }), 424 ], 425 }, 426 }, 427 { 428 input: "http://example.com/a", 429 expected: { 430 autofilled: "http://example.com/aBC/", 431 completed: "http://example.com/ABC/", 432 results: [ 433 context => 434 makeVisitResult(context, { 435 uri: "http://example.com/ABC/", 436 title: UrlbarTestUtils.trimURL("http://example.com/ABC/"), 437 heuristic: true, 438 }), 439 context => 440 makeVisitResult(context, { 441 uri: "http://example.com/ABC/DEF", 442 title: "test visit for http://example.com/ABC/DEF", 443 }), 444 ], 445 }, 446 }, 447 { 448 input: "http://example.com/abc/", 449 expected: { 450 autofilled: "http://example.com/abc/", 451 completed: "http://example.com/abc/", 452 results: [ 453 context => 454 makeVisitResult(context, { 455 uri: "http://example.com/abc/", 456 title: UrlbarTestUtils.trimURL("http://example.com/abc/"), 457 heuristic: true, 458 }), 459 context => 460 makeVisitResult(context, { 461 uri: "http://example.com/ABC/DEF", 462 title: "test visit for http://example.com/ABC/DEF", 463 }), 464 ], 465 }, 466 }, 467 { 468 input: "http://example.com/abc/d", 469 expected: { 470 autofilled: "http://example.com/abc/dEF", 471 completed: "http://example.com/ABC/DEF", 472 results: [ 473 context => 474 makeVisitResult(context, { 475 uri: "http://example.com/ABC/DEF", 476 title: "test visit for http://example.com/ABC/DEF", 477 heuristic: true, 478 }), 479 ], 480 }, 481 }, 482 { 483 input: "http://example.com/abc/def", 484 expected: { 485 autofilled: "http://example.com/abc/def", 486 completed: "http://example.com/abc/def", 487 results: [ 488 context => 489 makeVisitResult(context, { 490 uri: "http://example.com/abc/def", 491 title: UrlbarTestUtils.trimURL("http://example.com/abc/def"), 492 heuristic: true, 493 }), 494 context => 495 makeVisitResult(context, { 496 uri: "http://example.com/ABC/DEF", 497 title: "test visit for http://example.com/ABC/DEF", 498 }), 499 ], 500 }, 501 }, 502 { 503 input: "http://eXAMple.com/ABC/DEF", 504 expected: { 505 autofilled: "http://eXAMple.com/ABC/DEF", 506 completed: "http://example.com/ABC/DEF", 507 results: [ 508 context => 509 makeVisitResult(context, { 510 uri: "http://example.com/ABC/DEF", 511 title: "test visit for http://example.com/ABC/DEF", 512 heuristic: true, 513 }), 514 ], 515 }, 516 }, 517 { 518 input: "http://eXAMple.com/abc/def", 519 expected: { 520 autofilled: "http://eXAMple.com/abc/def", 521 completed: "http://example.com/abc/def", 522 results: [ 523 context => 524 makeVisitResult(context, { 525 uri: "http://example.com/abc/def", 526 title: UrlbarTestUtils.trimURL("http://example.com/abc/def"), 527 heuristic: true, 528 }), 529 context => 530 makeVisitResult(context, { 531 uri: "http://example.com/ABC/DEF", 532 title: "test visit for http://example.com/ABC/DEF", 533 }), 534 ], 535 }, 536 }, 537 ]; 538 539 for (const { input, expected } of testData) { 540 const context = createContext(input, { 541 isPrivate: false, 542 }); 543 await check_results({ 544 context, 545 autofilled: expected.autofilled, 546 completed: expected.completed, 547 matches: expected.results.map(f => f(context)), 548 }); 549 } 550 551 await cleanupPlaces(); 552 }); 553 554 async function testCaseInsensitive(isBookmark = false) { 555 const testData = [ 556 { 557 input: "example.com/F", 558 expectedAutofill: "example.com/Foo", 559 }, 560 { 561 // Test with prefix. 562 input: "http://example.com/F", 563 expectedAutofill: "http://example.com/Foo", 564 }, 565 ]; 566 567 for (const { input, expectedAutofill } of testData) { 568 const context = createContext(input, { 569 isPrivate: false, 570 }); 571 await check_results({ 572 context, 573 autofilled: expectedAutofill, 574 completed: "http://example.com/foo", 575 matches: [ 576 makeVisitResult(context, { 577 uri: "http://example.com/foo", 578 title: isBookmark 579 ? "A bookmark" 580 : "test visit for http://example.com/foo", 581 heuristic: true, 582 }), 583 ], 584 }); 585 } 586 587 await cleanupPlaces(); 588 } 589 590 // Checks a URL with an origin that looks like a prefix: a scheme with no dots + 591 // a port. 592 add_task(async function originLooksLikePrefix1() { 593 await PlacesTestUtils.addVisits([ 594 { 595 uri: "http://localhost:8888/foo", 596 }, 597 ]); 598 const context = createContext("localhost:8888/f", { isPrivate: false }); 599 await check_results({ 600 context, 601 autofilled: "localhost:8888/foo", 602 completed: "http://localhost:8888/foo", 603 matches: [ 604 makeVisitResult(context, { 605 uri: "http://localhost:8888/foo", 606 title: "test visit for http://localhost:8888/foo", 607 heuristic: true, 608 }), 609 ], 610 }); 611 await cleanupPlaces(); 612 }); 613 614 // Same as previous (originLooksLikePrefix1) but uses a URL whose path has two 615 // slashes, not one. 616 add_task(async function originLooksLikePrefix2() { 617 await PlacesTestUtils.addVisits([ 618 { 619 uri: "http://localhost:8888/foo/bar", 620 }, 621 ]); 622 623 let context = createContext("localhost:8888/f", { isPrivate: false }); 624 await check_results({ 625 context, 626 autofilled: "localhost:8888/foo/", 627 completed: "http://localhost:8888/foo/", 628 matches: [ 629 makeVisitResult(context, { 630 uri: "http://localhost:8888/foo/", 631 title: UrlbarTestUtils.trimURL("http://localhost:8888/foo/"), 632 heuristic: true, 633 }), 634 makeVisitResult(context, { 635 uri: "http://localhost:8888/foo/bar", 636 title: "test visit for http://localhost:8888/foo/bar", 637 providerName: PLACES_PROVIDERNAME, 638 tags: [], 639 }), 640 ], 641 }); 642 643 context = createContext("localhost:8888/foo/b", { isPrivate: false }); 644 await check_results({ 645 context, 646 autofilled: "localhost:8888/foo/bar", 647 completed: "http://localhost:8888/foo/bar", 648 matches: [ 649 makeVisitResult(context, { 650 uri: "http://localhost:8888/foo/bar", 651 title: "test visit for http://localhost:8888/foo/bar", 652 heuristic: true, 653 }), 654 ], 655 }); 656 await cleanupPlaces(); 657 }); 658 659 // Checks view-source pages as a prefix 660 // Uses bookmark because addVisits does not allow non-http uri's 661 add_task(async function viewSourceAsPrefix() { 662 let address = "view-source:https://www.example.com/"; 663 let title = "A view source bookmark"; 664 await PlacesTestUtils.addBookmarkWithDetails({ 665 uri: address, 666 title, 667 }); 668 669 let testData = [ 670 { 671 input: "view-source:h", 672 completed: "view-source:https:/", 673 autofilled: "view-source:https:/", 674 }, 675 { 676 input: "view-source:http", 677 completed: "view-source:https:/", 678 autofilled: "view-source:https:/", 679 }, 680 { 681 input: "VIEW-SOURCE:http", 682 completed: "view-source:https:/", 683 autofilled: "VIEW-SOURCE:https:/", 684 }, 685 ]; 686 687 // Only autofills from view-source:h to view-source:https:/ 688 for (let { input, completed, autofilled } of testData) { 689 let context = createContext(input, { isPrivate: false }); 690 await check_results({ 691 context, 692 completed, 693 autofilled, 694 matches: [ 695 { 696 heuristic: true, 697 type: UrlbarUtils.RESULT_TYPE.URL, 698 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 699 }, 700 makeBookmarkResult(context, { 701 uri: address, 702 iconUri: "chrome://global/skin/icons/defaultFavicon.svg", 703 title, 704 }), 705 ], 706 }); 707 } 708 709 await cleanupPlaces(); 710 }); 711 712 // Checks data url prefixes 713 // Uses bookmark because addVisits does not allow non-http uri's 714 add_task(async function dataAsPrefix() { 715 let address = "data:text/html,%3Ch1%3EHello%2C World!%3C%2Fh1%3E"; 716 let title = "A data url bookmark"; 717 await PlacesTestUtils.addBookmarkWithDetails({ 718 uri: address, 719 title, 720 }); 721 722 let testData = [ 723 { 724 input: "data:t", 725 completed: "data:text/", 726 autofilled: "data:text/", 727 }, 728 { 729 input: "data:text", 730 completed: "data:text/", 731 autofilled: "data:text/", 732 }, 733 { 734 input: "DATA:text", 735 completed: "data:text/", 736 autofilled: "DATA:text/", 737 }, 738 ]; 739 740 for (let { input, completed, autofilled } of testData) { 741 let context = createContext(input, { isPrivate: false }); 742 await check_results({ 743 context, 744 completed, 745 autofilled, 746 matches: [ 747 { 748 heuristic: true, 749 type: UrlbarUtils.RESULT_TYPE.URL, 750 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 751 }, 752 makeBookmarkResult(context, { 753 uri: address, 754 iconUri: "chrome://global/skin/icons/defaultFavicon.svg", 755 title, 756 }), 757 ], 758 }); 759 } 760 761 await cleanupPlaces(); 762 }); 763 764 // Checks about prefixes 765 add_task(async function aboutAsPrefix() { 766 let testData = [ 767 { 768 input: "about:abou", 769 completed: "about:about", 770 autofilled: "about:about", 771 }, 772 { 773 input: "ABOUT:abou", 774 completed: "about:about", 775 autofilled: "ABOUT:about", 776 }, 777 ]; 778 779 for (let { input, completed, autofilled } of testData) { 780 let context = createContext(input, { isPrivate: false }); 781 await check_results({ 782 context, 783 completed, 784 autofilled, 785 matches: [ 786 { 787 heuristic: true, 788 type: UrlbarUtils.RESULT_TYPE.URL, 789 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 790 }, 791 ], 792 }); 793 } 794 795 await cleanupPlaces(); 796 }); 797 798 // Checks a URL that has www name in history. 799 add_task(async function wwwHistory() { 800 const testData = [ 801 { 802 input: "example.com/", 803 visitHistory: [{ uri: "http://www.example.com/", title: "Example" }], 804 expected: { 805 autofilled: "example.com/", 806 completed: "http://www.example.com/", 807 results: [ 808 context => 809 makeVisitResult(context, { 810 uri: "http://www.example.com/", 811 title: "Example", 812 heuristic: true, 813 }), 814 ], 815 }, 816 }, 817 { 818 input: "https://example.com/", 819 visitHistory: [{ uri: "https://www.example.com/", title: "Example" }], 820 expected: { 821 autofilled: "https://example.com/", 822 completed: "https://www.example.com/", 823 results: [ 824 context => 825 makeVisitResult(context, { 826 uri: "https://www.example.com/", 827 title: "Example", 828 heuristic: true, 829 }), 830 ], 831 }, 832 }, 833 { 834 input: "https://example.com/abc", 835 visitHistory: [{ uri: "https://www.example.com/abc", title: "Example" }], 836 expected: { 837 autofilled: "https://example.com/abc", 838 completed: "https://www.example.com/abc", 839 results: [ 840 context => 841 makeVisitResult(context, { 842 uri: "https://www.example.com/abc", 843 title: "Example", 844 heuristic: true, 845 }), 846 ], 847 }, 848 }, 849 { 850 input: "https://example.com/ABC", 851 visitHistory: [{ uri: "https://www.example.com/abc", title: "Example" }], 852 expected: { 853 autofilled: "https://example.com/ABC", 854 completed: "https://www.example.com/ABC", 855 results: [ 856 context => 857 makeVisitResult(context, { 858 uri: "https://www.example.com/ABC", 859 title: UrlbarTestUtils.trimURL("https://www.example.com/ABC"), 860 heuristic: true, 861 }), 862 context => 863 makeVisitResult(context, { 864 uri: "https://www.example.com/abc", 865 title: "Example", 866 }), 867 ], 868 }, 869 }, 870 ]; 871 872 for (const { input, visitHistory, expected } of testData) { 873 await PlacesTestUtils.addVisits(visitHistory); 874 const context = createContext(input, { isPrivate: false }); 875 await check_results({ 876 context, 877 completed: expected.completed, 878 autofilled: expected.autofilled, 879 matches: expected.results.map(f => f(context)), 880 }); 881 await cleanupPlaces(); 882 } 883 }); 884 885 add_task(async function formatPunycodeResultCorrectly() { 886 await PlacesTestUtils.addVisits([ 887 { 888 uri: `http://test.xn--e1afmkfd.com/`, 889 }, 890 ]); 891 let context = createContext("test", { isPrivate: false }); 892 await check_results({ 893 context, 894 autofilled: "test.xn--e1afmkfd.com/", 895 completed: "http://test.xn--e1afmkfd.com/", 896 matches: [ 897 makeVisitResult(context, { 898 uri: "http://test.xn--e1afmkfd.com/", 899 title: "test visit for http://test.xn--e1afmkfd.com/", 900 heuristic: true, 901 }), 902 ], 903 }); 904 await cleanupPlaces(); 905 });