test_autofill_originsAndQueries.js (75211B)
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 HEURISTIC_FALLBACK_PROVIDERNAME = "UrlbarProviderHeuristicFallback"; 6 const PLACES_PROVIDERNAME = "UrlbarProviderPlaces"; 7 8 /** 9 * Helpful reminder of the `autofilled` and `completed` properties in the 10 * object passed to check_results: 11 * autofilled: expected input.value after autofill 12 * completed: expected input.value after autofill and enter is pressed 13 * 14 * `completed` is the URL that the controller sets to input.value, and the URL 15 * that will ultimately be loaded when you press enter. 16 */ 17 18 async function cleanup() { 19 let suggestPrefs = ["history", "bookmark", "openpage"]; 20 for (let type of suggestPrefs) { 21 Services.prefs.clearUserPref("browser.urlbar.suggest." + type); 22 } 23 await cleanupPlaces(); 24 } 25 26 testEngine_setup(); 27 28 registerCleanupFunction(async () => { 29 Services.prefs.clearUserPref("browser.urlbar.suggest.quickactions"); 30 }); 31 Services.prefs.setBoolPref("browser.urlbar.suggest.quickactions", false); 32 33 let path; 34 let search; 35 let searchCase; 36 let visitTitle; 37 let url; 38 const host = "example.com"; 39 let origins; 40 41 function add_autofill_task(callback) { 42 let func = async () => { 43 info(`Running subtest with origins disabled: ${callback.name}`); 44 origins = false; 45 path = "/foo"; 46 search = "example.com/f"; 47 searchCase = "EXAMPLE.COM/f"; 48 visitTitle = (protocol, sub) => 49 `test visit for ${protocol}://${sub}example.com/foo`; 50 url = host + path; 51 await callback(); 52 53 info(`Running subtest with origins enabled: ${callback.name}`); 54 origins = true; 55 path = "/"; 56 search = "ex"; 57 searchCase = "EX"; 58 visitTitle = (protocol, sub) => 59 `test visit for ${protocol}://${sub}example.com/`; 60 url = host + path; 61 await callback(); 62 }; 63 Object.defineProperty(func, "name", { value: callback.name }); 64 add_task(func); 65 } 66 67 // "ex" should match http://example.com/. 68 add_autofill_task(async function basic() { 69 await PlacesTestUtils.addVisits([ 70 { 71 uri: "http://" + url, 72 }, 73 ]); 74 let context = createContext(search, { isPrivate: false }); 75 await check_results({ 76 context, 77 autofilled: url, 78 completed: "http://" + url, 79 matches: [ 80 makeVisitResult(context, { 81 uri: "http://" + url, 82 title: visitTitle("http", ""), 83 heuristic: true, 84 }), 85 ], 86 }); 87 await cleanup(); 88 }); 89 90 // "EX" should match http://example.com/. 91 add_autofill_task(async function basicCase() { 92 await PlacesTestUtils.addVisits([ 93 { 94 uri: "http://" + url, 95 }, 96 ]); 97 let context = createContext(searchCase, { isPrivate: false }); 98 await check_results({ 99 context, 100 autofilled: searchCase + url.substr(searchCase.length), 101 completed: "http://" + url, 102 matches: [ 103 makeVisitResult(context, { 104 uri: "http://" + url, 105 title: visitTitle("http", ""), 106 heuristic: true, 107 }), 108 ], 109 }); 110 await cleanup(); 111 }); 112 113 // "ex" should match http://www.example.com/. 114 add_autofill_task(async function noWWWShouldMatchWWW() { 115 await PlacesTestUtils.addVisits([ 116 { 117 uri: "http://www." + url, 118 }, 119 ]); 120 let context = createContext(search, { isPrivate: false }); 121 await check_results({ 122 context, 123 autofilled: url, 124 completed: "http://www." + url, 125 matches: [ 126 makeVisitResult(context, { 127 uri: "http://www." + url, 128 title: visitTitle("http", "www."), 129 heuristic: true, 130 }), 131 ], 132 }); 133 await cleanup(); 134 }); 135 136 // "EX" should match http://www.example.com/. 137 add_autofill_task(async function noWWWShouldMatchWWWCase() { 138 await PlacesTestUtils.addVisits([ 139 { 140 uri: "http://www." + url, 141 }, 142 ]); 143 let context = createContext(searchCase, { isPrivate: false }); 144 await check_results({ 145 context, 146 autofilled: searchCase + url.substr(searchCase.length), 147 completed: "http://www." + url, 148 matches: [ 149 makeVisitResult(context, { 150 uri: "http://www." + url, 151 title: visitTitle("http", "www."), 152 heuristic: true, 153 }), 154 ], 155 }); 156 await cleanup(); 157 }); 158 159 // "www.ex" should *not* match http://example.com/. 160 add_autofill_task(async function wwwShouldNotMatchNoWWW() { 161 await PlacesTestUtils.addVisits([ 162 { 163 uri: "http://" + url, 164 }, 165 ]); 166 let context = createContext("www." + search, { isPrivate: false }); 167 if (origins) { 168 await check_results({ 169 context, 170 matches: [ 171 makeVisitResult(context, { 172 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 173 uri: "http://www." + search + "/", 174 title: "www." + search + "/", 175 heuristic: true, 176 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 177 }), 178 makeSearchResult(context, { 179 engineName: SUGGESTIONS_ENGINE_NAME, 180 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 181 }), 182 ], 183 }); 184 } else { 185 await check_results({ 186 context, 187 matches: [ 188 makeVisitResult(context, { 189 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 190 uri: "http://www." + search, 191 title: "www." + search, 192 iconUri: `page-icon:http://www.${host}/`, 193 heuristic: true, 194 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 195 }), 196 ], 197 }); 198 } 199 await cleanup(); 200 }); 201 202 // "http://ex" should match http://example.com/. 203 add_autofill_task(async function prefix() { 204 await PlacesTestUtils.addVisits([ 205 { 206 uri: "http://" + url, 207 }, 208 ]); 209 let context = createContext("http://" + search, { isPrivate: false }); 210 await check_results({ 211 context, 212 autofilled: "http://" + url, 213 completed: "http://" + url, 214 matches: [ 215 makeVisitResult(context, { 216 uri: "http://" + url, 217 title: visitTitle("http", ""), 218 heuristic: true, 219 }), 220 ], 221 }); 222 await cleanup(); 223 }); 224 225 // "HTTP://EX" should match http://example.com/. 226 add_autofill_task(async function prefixCase() { 227 await PlacesTestUtils.addVisits([ 228 { 229 uri: "http://" + url, 230 }, 231 ]); 232 let context = createContext("HTTP://" + searchCase, { isPrivate: false }); 233 await check_results({ 234 context, 235 autofilled: "HTTP://" + searchCase + url.substr(searchCase.length), 236 completed: "http://" + url, 237 matches: [ 238 makeVisitResult(context, { 239 uri: "http://" + url, 240 title: visitTitle("http", ""), 241 heuristic: true, 242 }), 243 ], 244 }); 245 await cleanup(); 246 }); 247 248 // "http://ex" should match http://www.example.com/. 249 add_autofill_task(async function prefixNoWWWShouldMatchWWW() { 250 await PlacesTestUtils.addVisits([ 251 { 252 uri: "http://www." + url, 253 }, 254 ]); 255 let context = createContext("http://" + search, { isPrivate: false }); 256 await check_results({ 257 context, 258 autofilled: "http://" + url, 259 completed: "http://www." + url, 260 matches: [ 261 makeVisitResult(context, { 262 uri: "http://www." + url, 263 title: visitTitle("http", "www."), 264 heuristic: true, 265 }), 266 ], 267 }); 268 await cleanup(); 269 }); 270 271 // "HTTP://EX" should match http://www.example.com/. 272 add_autofill_task(async function prefixNoWWWShouldMatchWWWCase() { 273 await PlacesTestUtils.addVisits([ 274 { 275 uri: "http://www." + url, 276 }, 277 ]); 278 let context = createContext("HTTP://" + searchCase, { isPrivate: false }); 279 await check_results({ 280 context, 281 autofilled: "HTTP://" + searchCase + url.substr(searchCase.length), 282 completed: "http://www." + url, 283 matches: [ 284 makeVisitResult(context, { 285 uri: "http://www." + url, 286 title: visitTitle("http", "www."), 287 heuristic: true, 288 }), 289 ], 290 }); 291 await cleanup(); 292 }); 293 294 // "http://www.ex" should *not* match http://example.com/. 295 add_autofill_task(async function prefixWWWShouldNotMatchNoWWW() { 296 await PlacesTestUtils.addVisits([ 297 { 298 uri: "http://" + url, 299 }, 300 ]); 301 let context = createContext("http://www." + search, { isPrivate: false }); 302 let prefixedUrl = origins ? `http://www.${search}/` : `http://www.${search}`; 303 await check_results({ 304 context, 305 matches: [ 306 makeVisitResult(context, { 307 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 308 uri: prefixedUrl, 309 title: prefixedUrl, 310 heuristic: true, 311 iconUri: origins ? "" : `page-icon:http://www.${host}/`, 312 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 313 }), 314 ], 315 }); 316 await cleanup(); 317 }); 318 319 // "http://ex" should *not* match https://example.com/. 320 add_autofill_task(async function httpPrefixShouldNotMatchHTTPS() { 321 await PlacesTestUtils.addVisits([ 322 { 323 uri: "https://" + url, 324 }, 325 ]); 326 let context = createContext("http://" + search, { isPrivate: false }); 327 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 328 await check_results({ 329 context, 330 matches: [ 331 makeVisitResult(context, { 332 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 333 uri: prefixedUrl, 334 title: prefixedUrl, 335 heuristic: true, 336 iconUri: origins ? "" : `page-icon:http://${host}/`, 337 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 338 }), 339 makeVisitResult(context, { 340 uri: "https://" + url, 341 title: "test visit for https://" + url, 342 providerName: PLACES_PROVIDERNAME, 343 }), 344 ], 345 }); 346 await cleanup(); 347 }); 348 349 // "ex" should match https://example.com/. 350 add_autofill_task(async function httpsBasic() { 351 await PlacesTestUtils.addVisits([ 352 { 353 uri: "https://" + url, 354 }, 355 ]); 356 let context = createContext(search, { isPrivate: false }); 357 await check_results({ 358 context, 359 autofilled: url, 360 completed: "https://" + url, 361 matches: [ 362 makeVisitResult(context, { 363 uri: "https://" + url, 364 title: visitTitle("https", ""), 365 heuristic: true, 366 }), 367 ], 368 }); 369 await cleanup(); 370 }); 371 372 // "ex" should match https://www.example.com/. 373 add_autofill_task(async function httpsNoWWWShouldMatchWWW() { 374 await PlacesTestUtils.addVisits([ 375 { 376 uri: "https://www." + url, 377 }, 378 ]); 379 let context = createContext(search, { isPrivate: false }); 380 await check_results({ 381 context, 382 autofilled: url, 383 completed: "https://www." + url, 384 matches: [ 385 makeVisitResult(context, { 386 uri: "https://www." + url, 387 title: visitTitle("https", "www."), 388 heuristic: true, 389 }), 390 ], 391 }); 392 await cleanup(); 393 }); 394 395 // "www.ex" should *not* match https://example.com/. 396 add_autofill_task(async function httpsWWWShouldNotMatchNoWWW() { 397 await PlacesTestUtils.addVisits([ 398 { 399 uri: "https://" + url, 400 }, 401 ]); 402 let context = createContext("www." + search, { isPrivate: false }); 403 if (origins) { 404 await check_results({ 405 context, 406 matches: [ 407 makeVisitResult(context, { 408 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 409 uri: "http://www." + search + "/", 410 title: "www." + search + "/", 411 heuristic: true, 412 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 413 }), 414 makeSearchResult(context, { 415 engineName: SUGGESTIONS_ENGINE_NAME, 416 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 417 }), 418 ], 419 }); 420 } else { 421 await check_results({ 422 context, 423 matches: [ 424 makeVisitResult(context, { 425 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 426 uri: "http://www." + search, 427 title: "www." + search, 428 iconUri: `page-icon:http://www.${host}/`, 429 heuristic: true, 430 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 431 }), 432 ], 433 }); 434 } 435 await cleanup(); 436 }); 437 438 // "https://ex" should match https://example.com/. 439 add_autofill_task(async function httpsPrefix() { 440 await PlacesTestUtils.addVisits([ 441 { 442 uri: "https://" + url, 443 }, 444 ]); 445 let context = createContext("https://" + search, { isPrivate: false }); 446 await check_results({ 447 context, 448 autofilled: "https://" + url, 449 completed: "https://" + url, 450 matches: [ 451 makeVisitResult(context, { 452 uri: "https://" + url, 453 title: visitTitle("https", ""), 454 heuristic: true, 455 }), 456 ], 457 }); 458 await cleanup(); 459 }); 460 461 // "https://ex" should match https://www.example.com/. 462 add_autofill_task(async function httpsPrefixNoWWWShouldMatchWWW() { 463 await PlacesTestUtils.addVisits([ 464 { 465 uri: "https://www." + url, 466 }, 467 ]); 468 let context = createContext("https://" + search, { isPrivate: false }); 469 await check_results({ 470 context, 471 autofilled: "https://" + url, 472 completed: "https://www." + url, 473 matches: [ 474 makeVisitResult(context, { 475 uri: "https://www." + url, 476 title: visitTitle("https", "www."), 477 heuristic: true, 478 }), 479 ], 480 }); 481 await cleanup(); 482 }); 483 484 // "https://www.ex" should *not* match https://example.com/. 485 add_autofill_task(async function httpsPrefixWWWShouldNotMatchNoWWW() { 486 await PlacesTestUtils.addVisits([ 487 { 488 uri: "https://" + url, 489 }, 490 ]); 491 let context = createContext("https://www." + search, { isPrivate: false }); 492 let prefixedUrl = origins 493 ? `https://www.${search}/` 494 : `https://www.${search}`; 495 await check_results({ 496 context, 497 matches: [ 498 makeVisitResult(context, { 499 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 500 uri: prefixedUrl, 501 title: prefixedUrl, 502 heuristic: true, 503 iconUri: origins ? "" : `page-icon:https://www.${host}/`, 504 providerame: HEURISTIC_FALLBACK_PROVIDERNAME, 505 }), 506 ], 507 }); 508 await cleanup(); 509 }); 510 511 // "https://ex" should *not* match http://example.com/. 512 add_autofill_task(async function httpsPrefixShouldNotMatchHTTP() { 513 await PlacesTestUtils.addVisits([ 514 { 515 uri: "http://" + url, 516 }, 517 ]); 518 let context = createContext("https://" + search, { isPrivate: false }); 519 let prefixedUrl = origins ? `https://${search}/` : `https://${search}`; 520 await check_results({ 521 context, 522 matches: [ 523 makeVisitResult(context, { 524 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 525 uri: prefixedUrl, 526 title: prefixedUrl, 527 heuristic: true, 528 iconUri: origins ? "" : `page-icon:https://${host}/`, 529 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 530 }), 531 makeVisitResult(context, { 532 uri: "http://" + url, 533 title: "test visit for http://" + url, 534 providerName: PLACES_PROVIDERNAME, 535 }), 536 ], 537 }); 538 await cleanup(); 539 }); 540 541 // "https://ex" should *not* match http://example.com/, even if the latter is 542 // more frecent and both could be autofilled. 543 add_autofill_task(async function httpsPrefixShouldNotMatchMoreFrecentHTTP() { 544 await PlacesTestUtils.addVisits([ 545 { 546 uri: "http://" + url, 547 transition: PlacesUtils.history.TRANSITIONS.TYPED, 548 }, 549 { 550 uri: "http://" + url, 551 }, 552 { 553 uri: "https://" + url, 554 transition: PlacesUtils.history.TRANSITIONS.TYPED, 555 }, 556 { 557 uri: "http://otherpage", 558 }, 559 ]); 560 let context = createContext("https://" + search, { isPrivate: false }); 561 await check_results({ 562 context, 563 autofilled: "https://" + url, 564 completed: "https://" + url, 565 matches: [ 566 makeVisitResult(context, { 567 uri: "https://" + url, 568 title: visitTitle("https", ""), 569 heuristic: true, 570 }), 571 ], 572 }); 573 await cleanup(); 574 }); 575 576 // Autofill should respond to frecency changes. 577 add_autofill_task(async function frecency() { 578 // Start with an http visit. It should be completed. 579 await PlacesTestUtils.addVisits([ 580 { 581 uri: "http://" + url, 582 visitDate: daysAgo(30), 583 }, 584 ]); 585 let context = createContext(search, { isPrivate: false }); 586 await check_results({ 587 context, 588 autofilled: url, 589 completed: "http://" + url, 590 matches: [ 591 makeVisitResult(context, { 592 uri: "http://" + url, 593 title: visitTitle("http", ""), 594 heuristic: true, 595 }), 596 ], 597 }); 598 599 // Add two https visits. https should now be completed. 600 await PlacesTestUtils.addVisits([ 601 { uri: "https://" + url, visitDate: daysAgo(29) }, 602 ]); 603 context = createContext(search, { isPrivate: false }); 604 await check_results({ 605 context, 606 autofilled: url, 607 completed: "https://" + url, 608 matches: [ 609 makeVisitResult(context, { 610 uri: "https://" + url, 611 title: visitTitle("https", ""), 612 heuristic: true, 613 }), 614 ], 615 }); 616 617 // Add two more http visits, three total. http should now be completed 618 // again. 619 await PlacesTestUtils.addVisits([ 620 { uri: "http://" + url, visitDate: daysAgo(28) }, 621 { uri: "http://" + url, visitDate: daysAgo(27) }, 622 ]); 623 context = createContext(search, { isPrivate: false }); 624 await check_results({ 625 context, 626 autofilled: url, 627 completed: "http://" + url, 628 matches: [ 629 makeVisitResult(context, { 630 uri: "http://" + url, 631 title: visitTitle("http", ""), 632 heuristic: true, 633 }), 634 makeVisitResult(context, { 635 uri: "https://" + url, 636 title: "test visit for https://" + url, 637 providerName: PLACES_PROVIDERNAME, 638 }), 639 ], 640 }); 641 642 // Add four www https visits. www https should now be completed. 643 for (let i = 0; i < 4; i++) { 644 await PlacesTestUtils.addVisits([ 645 { uri: "https://www." + url, visitDate: daysAgo(i) }, 646 ]); 647 } 648 context = createContext(search, { isPrivate: false }); 649 await check_results({ 650 context, 651 autofilled: url, 652 completed: "https://www." + url, 653 matches: [ 654 makeVisitResult(context, { 655 uri: "https://www." + url, 656 title: visitTitle("https", "www."), 657 heuristic: true, 658 }), 659 makeVisitResult(context, { 660 uri: "https://" + url, 661 title: "test visit for https://" + url, 662 providerName: PLACES_PROVIDERNAME, 663 }), 664 ], 665 }); 666 667 // Remove the www https page. 668 await PlacesUtils.history.remove(["https://www." + url]); 669 670 // http should now be completed again. 671 context = createContext(search, { isPrivate: false }); 672 await check_results({ 673 context, 674 autofilled: url, 675 completed: "http://" + url, 676 matches: [ 677 makeVisitResult(context, { 678 uri: "http://" + url, 679 title: visitTitle("http", ""), 680 heuristic: true, 681 }), 682 makeVisitResult(context, { 683 uri: "https://" + url, 684 title: "test visit for https://" + url, 685 providerName: PLACES_PROVIDERNAME, 686 }), 687 ], 688 }); 689 690 // Remove the http page. 691 await PlacesUtils.history.remove(["http://" + url]); 692 693 // https should now be completed again. 694 context = createContext(search, { isPrivate: false }); 695 await check_results({ 696 context, 697 autofilled: url, 698 completed: "https://" + url, 699 matches: [ 700 makeVisitResult(context, { 701 uri: "https://" + url, 702 title: visitTitle("https", ""), 703 heuristic: true, 704 }), 705 ], 706 }); 707 708 // Add a visit with a different host so that "ex" doesn't autofill it. 709 // https://example.com/ should still have a higher frecency though, so it 710 // should still be autofilled. 711 await PlacesTestUtils.addVisits([{ uri: "https://not-" + url }]); 712 context = createContext(search, { isPrivate: false }); 713 await check_results({ 714 context, 715 autofilled: url, 716 completed: "https://" + url, 717 matches: [ 718 makeVisitResult(context, { 719 uri: "https://" + url, 720 title: visitTitle("https", ""), 721 heuristic: true, 722 }), 723 makeVisitResult(context, { 724 uri: "https://not-" + url, 725 title: "test visit for https://not-" + url, 726 providerName: PLACES_PROVIDERNAME, 727 }), 728 ], 729 }); 730 731 // Now add more visits to the different host so that the frecency of 732 // https://example.com/ falls below the autofill threshold. It should not 733 // be autofilled now. 734 await PlacesTestUtils.addVisits([ 735 { uri: "https://other-site.com/1" }, 736 { uri: "https://other-site.com/2" }, 737 { uri: "https://other-site.com/3" }, 738 { uri: "https://other-site.com/4" }, 739 ]); 740 741 for (let i = 0; i < 10; i++) { 742 await PlacesTestUtils.addVisits([{ uri: "https://not-" + url }]); 743 } 744 745 // In the `origins` case, the failure to make an autofill match means 746 // HeuristicFallback should not create a heuristic result. In the 747 // `!origins` case, autofill should still happen since there's no threshold 748 // comparison. 749 context = createContext(search, { isPrivate: false }); 750 if (origins) { 751 await check_results({ 752 context, 753 matches: [ 754 makeSearchResult(context, { 755 engineName: SUGGESTIONS_ENGINE_NAME, 756 heuristic: true, 757 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 758 }), 759 makeVisitResult(context, { 760 uri: "https://not-" + url, 761 title: "test visit for https://not-" + url, 762 providerName: PLACES_PROVIDERNAME, 763 }), 764 makeVisitResult(context, { 765 uri: "https://" + url, 766 title: "test visit for https://" + url, 767 providerName: PLACES_PROVIDERNAME, 768 }), 769 ], 770 }); 771 } else { 772 await check_results({ 773 context, 774 autofilled: url, 775 completed: "https://" + url, 776 matches: [ 777 makeVisitResult(context, { 778 uri: "https://" + url, 779 title: visitTitle("https", ""), 780 heuristic: true, 781 }), 782 makeVisitResult(context, { 783 uri: "https://not-" + url, 784 title: "test visit for https://not-" + url, 785 providerName: PLACES_PROVIDERNAME, 786 }), 787 ], 788 }); 789 } 790 791 // Remove the visits to the different host. 792 await PlacesUtils.history.remove(["https://not-" + url]); 793 794 // https should be completed again. 795 context = createContext(search, { isPrivate: false }); 796 await check_results({ 797 context, 798 autofilled: url, 799 completed: "https://" + url, 800 matches: [ 801 makeVisitResult(context, { 802 uri: "https://" + url, 803 title: visitTitle("https", ""), 804 heuristic: true, 805 }), 806 ], 807 }); 808 809 // Remove the https visits. 810 await PlacesUtils.history.remove(["https://" + url]); 811 812 // Now nothing should be completed. 813 context = createContext(search, { isPrivate: false }); 814 if (origins) { 815 await check_results({ 816 context, 817 matches: [ 818 makeSearchResult(context, { 819 engineName: SUGGESTIONS_ENGINE_NAME, 820 heuristic: true, 821 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 822 }), 823 ], 824 }); 825 } else { 826 await check_results({ 827 context, 828 matches: [ 829 makeVisitResult(context, { 830 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 831 uri: "http://" + search, 832 title: search, 833 iconUri: `page-icon:http://${host}/`, 834 heuristic: true, 835 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 836 }), 837 ], 838 }); 839 } 840 841 await cleanup(); 842 }); 843 844 // Bookmarked places should always be autofilled, even when they don't meet 845 // the threshold. 846 add_autofill_task(async function bookmarkBelowThreshold() { 847 // Add some visits to a URL so that the origin autofill threshold is large. 848 for (let i = 0; i < 3; i++) { 849 await PlacesTestUtils.addVisits([ 850 { 851 uri: "http://not-" + url, 852 }, 853 ]); 854 } 855 856 // Now bookmark another URL. 857 await PlacesTestUtils.addBookmarkWithDetails({ 858 uri: "http://" + url, 859 }); 860 861 // Bookmarks without a visit are given a frecency boost. To reduce its 862 // frecency (and thus, make it lower than the origin autofill threshold), 863 // set its creation date to a long time ago. 864 let thirtyYearsAgoMicroseconds = 865 (Date.now() - 30 * 365 * 24 * 60 * 60 * 1000) * 1000; 866 await PlacesUtils.withConnectionWrapper( 867 "test_autofill_originsAndQueries::add_autofill_task", 868 async db => { 869 await db.execute("UPDATE moz_bookmarks SET dateAdded = :dateAdded", { 870 dateAdded: thirtyYearsAgoMicroseconds, 871 }); 872 } 873 ); 874 875 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 876 877 // Make sure the bookmarked origin and place frecencies are below the 878 // threshold so that the origin/URL otherwise would not be autofilled. 879 let placeFrecency = await PlacesTestUtils.getDatabaseValue( 880 "moz_places", 881 "frecency", 882 { url: "http://" + url } 883 ); 884 let originFrecency = await getOriginFrecency("http://", host); 885 let threshold = await getOriginAutofillThreshold(); 886 Assert.less( 887 placeFrecency, 888 threshold, 889 `Place frecency should be below the threshold: ` + 890 `placeFrecency=${placeFrecency} threshold=${threshold}` 891 ); 892 Assert.less( 893 originFrecency, 894 threshold, 895 `Origin frecency should be below the threshold: ` + 896 `originFrecency=${originFrecency} threshold=${threshold}` 897 ); 898 899 // The bookmark should be autofilled. 900 let context = createContext(search, { isPrivate: false }); 901 await check_results({ 902 context, 903 autofilled: url, 904 completed: "http://" + url, 905 matches: [ 906 makeVisitResult(context, { 907 uri: "http://" + url, 908 title: "A bookmark", 909 heuristic: true, 910 }), 911 makeVisitResult(context, { 912 uri: "http://not-" + url, 913 title: "test visit for http://not-" + url, 914 providerName: PLACES_PROVIDERNAME, 915 }), 916 ], 917 }); 918 919 await cleanup(); 920 }); 921 922 // Bookmarked places should be autofilled also when they meet the threshold. 923 add_autofill_task(async function bookmarkAboveThreshold() { 924 // Add a visit to the URL, otherwise origin frecency will be too small, note 925 // it would be filled anyway as bookmarks are always filled. 926 await PlacesTestUtils.addVisits(["http://" + url]); 927 // Bookmark a URL. 928 await PlacesTestUtils.addBookmarkWithDetails({ 929 uri: "http://" + url, 930 }); 931 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 932 933 // The frecencies of the place and origin should be >= the threshold. In 934 // fact they should be the same as the threshold since the place is the only 935 // place in the database. 936 let placeFrecency = await PlacesTestUtils.getDatabaseValue( 937 "moz_places", 938 "frecency", 939 { url: "http://" + url } 940 ); 941 let originFrecency = await getOriginFrecency("http://", host); 942 let threshold = await getOriginAutofillThreshold(); 943 Assert.equal(placeFrecency, threshold); 944 Assert.equal(originFrecency, threshold); 945 946 // The bookmark should be autofilled. 947 let context = createContext(search, { isPrivate: false }); 948 await check_results({ 949 context, 950 autofilled: url, 951 completed: "http://" + url, 952 matches: [ 953 makeVisitResult(context, { 954 uri: "http://" + url, 955 title: "A bookmark", 956 heuristic: true, 957 }), 958 ], 959 }); 960 961 await cleanup(); 962 }); 963 964 // Bookmark a page and then clear history. 965 // The bookmarked origin/URL should still be autofilled. 966 add_autofill_task(async function zeroThreshold() { 967 const pageUrl = "http://" + url; 968 await PlacesTestUtils.addBookmarkWithDetails({ 969 uri: pageUrl, 970 }); 971 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 972 973 await PlacesUtils.history.clear(); 974 await PlacesUtils.withConnectionWrapper("zeroThreshold", async db => { 975 await db.execute("UPDATE moz_places SET frecency = -1 WHERE url = :url", { 976 url: pageUrl, 977 }); 978 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 979 }); 980 981 // Make sure the place's frecency is -1. 982 let placeFrecency = await PlacesTestUtils.getDatabaseValue( 983 "moz_places", 984 "frecency", 985 { url: pageUrl } 986 ); 987 Assert.equal(placeFrecency, -1); 988 989 let originFrecency = await getOriginFrecency("http://", host); 990 Assert.equal(originFrecency, 1, "Check expected origin's frecency"); 991 let threshold = await getOriginAutofillThreshold(); 992 Assert.equal(threshold, 2, "Check expected origins threshold"); 993 994 let context = createContext(search, { isPrivate: false }); 995 await check_results({ 996 context, 997 autofilled: url, 998 completed: "http://" + url, 999 matches: [ 1000 makeVisitResult(context, { 1001 uri: "http://" + url, 1002 title: "A bookmark", 1003 heuristic: true, 1004 }), 1005 ], 1006 }); 1007 1008 await cleanup(); 1009 }); 1010 1011 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1012 // 1013 // Config: 1014 // suggest.history = false 1015 // suggest.bookmark = true 1016 // search for: visit 1017 // prefix search: no 1018 // prefix matches search: n/a 1019 // origin matches search: yes 1020 // 1021 // Expected result: 1022 // should autofill: no 1023 add_autofill_task(async function suggestHistoryFalse_visit() { 1024 await PlacesTestUtils.addVisits("http://" + url); 1025 let context = createContext(search, { isPrivate: false }); 1026 await check_results({ 1027 context, 1028 autofilled: url, 1029 completed: "http://" + url, 1030 matches: [ 1031 makeVisitResult(context, { 1032 uri: "http://" + url, 1033 title: visitTitle("http", ""), 1034 heuristic: true, 1035 }), 1036 ], 1037 }); 1038 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1039 context = createContext(search, { isPrivate: false }); 1040 if (origins) { 1041 await check_results({ 1042 context, 1043 matches: [ 1044 makeSearchResult(context, { 1045 engineName: SUGGESTIONS_ENGINE_NAME, 1046 heuristic: true, 1047 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1048 }), 1049 ], 1050 }); 1051 } else { 1052 await check_results({ 1053 context, 1054 matches: [ 1055 makeVisitResult(context, { 1056 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1057 uri: "http://" + search, 1058 title: search, 1059 iconUri: `page-icon:http://${host}/`, 1060 heuristic: true, 1061 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1062 }), 1063 ], 1064 }); 1065 } 1066 await cleanup(); 1067 }); 1068 1069 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1070 // 1071 // Config: 1072 // suggest.history = false 1073 // suggest.bookmark = true 1074 // search for: visit 1075 // prefix search: yes 1076 // prefix matches search: yes 1077 // origin matches search: yes 1078 // 1079 // Expected result: 1080 // should autofill: no 1081 add_autofill_task(async function suggestHistoryFalse_visit_prefix() { 1082 await PlacesTestUtils.addVisits("http://" + url); 1083 let context = createContext("http://" + search, { isPrivate: false }); 1084 await check_results({ 1085 context, 1086 autofilled: "http://" + url, 1087 completed: "http://" + url, 1088 matches: [ 1089 makeVisitResult(context, { 1090 uri: "http://" + url, 1091 title: visitTitle("http", ""), 1092 heuristic: true, 1093 }), 1094 ], 1095 }); 1096 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1097 context = createContext(search, { isPrivate: false }); 1098 if (origins) { 1099 await check_results({ 1100 context, 1101 matches: [ 1102 makeSearchResult(context, { 1103 engineName: SUGGESTIONS_ENGINE_NAME, 1104 heuristic: true, 1105 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1106 }), 1107 ], 1108 }); 1109 } else { 1110 await check_results({ 1111 context, 1112 matches: [ 1113 makeVisitResult(context, { 1114 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1115 uri: "http://" + search, 1116 title: search, 1117 iconUri: `page-icon:http://${host}/`, 1118 heuristic: true, 1119 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1120 }), 1121 ], 1122 }); 1123 } 1124 await cleanup(); 1125 }); 1126 1127 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1128 // 1129 // Config: 1130 // suggest.history = false 1131 // suggest.bookmark = true 1132 // search for: bookmark 1133 // prefix search: no 1134 // prefix matches search: n/a 1135 // origin matches search: yes 1136 // 1137 // Expected result: 1138 // should autofill: yes 1139 add_autofill_task(async function suggestHistoryFalse_bookmark_0() { 1140 // Add the bookmark. 1141 await PlacesTestUtils.addBookmarkWithDetails({ 1142 uri: "http://" + url, 1143 }); 1144 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1145 1146 // Make the bookmark fall below the autofill frecency threshold so we ensure 1147 // the bookmark is always autofilled in this case, even if it doesn't meet 1148 // the threshold. 1149 await TestUtils.waitForCondition(async () => { 1150 // Add a visit to another origin to boost the threshold. 1151 await PlacesTestUtils.addVisits("http://foo-" + url); 1152 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1153 let originFrecency = await getOriginFrecency("http://", host); 1154 let threshold = await getOriginAutofillThreshold(); 1155 return threshold > originFrecency; 1156 }, "Make the bookmark fall below the frecency threshold"); 1157 1158 // At this point, the bookmark doesn't meet the threshold, but it should 1159 // still be autofilled. 1160 let originFrecency = await getOriginFrecency("http://", host); 1161 let threshold = await getOriginAutofillThreshold(); 1162 Assert.less(originFrecency, threshold); 1163 1164 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1165 let context = createContext(search, { isPrivate: false }); 1166 await check_results({ 1167 context, 1168 autofilled: url, 1169 completed: "http://" + url, 1170 matches: [ 1171 makeVisitResult(context, { 1172 uri: "http://" + url, 1173 title: "A bookmark", 1174 heuristic: true, 1175 }), 1176 ], 1177 }); 1178 await cleanup(); 1179 }); 1180 1181 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1182 // 1183 // Config: 1184 // suggest.history = false 1185 // suggest.bookmark = true 1186 // search for: bookmark 1187 // prefix search: no 1188 // prefix matches search: n/a 1189 // origin matches search: no 1190 // 1191 // Expected result: 1192 // should autofill: no 1193 add_autofill_task(async function suggestHistoryFalse_bookmark_1() { 1194 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1195 await PlacesTestUtils.addBookmarkWithDetails({ 1196 uri: "http://non-matching-" + url, 1197 }); 1198 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1199 1200 let context = createContext(search, { isPrivate: false }); 1201 let matches = [ 1202 makeBookmarkResult(context, { 1203 uri: "http://non-matching-" + url, 1204 title: "A bookmark", 1205 }), 1206 ]; 1207 if (origins) { 1208 matches.unshift( 1209 makeSearchResult(context, { 1210 engineName: SUGGESTIONS_ENGINE_NAME, 1211 heuristic: true, 1212 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1213 }) 1214 ); 1215 } else { 1216 matches.unshift( 1217 makeVisitResult(context, { 1218 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1219 uri: "http://" + search, 1220 title: search, 1221 iconUri: `page-icon:http://${host}/`, 1222 heuristic: true, 1223 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1224 }) 1225 ); 1226 } 1227 await check_results({ 1228 context, 1229 matches, 1230 }); 1231 await cleanup(); 1232 }); 1233 1234 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1235 // 1236 // Config: 1237 // suggest.history = false 1238 // suggest.bookmark = true 1239 // search for: bookmark 1240 // prefix search: yes 1241 // prefix matches search: yes 1242 // origin matches search: yes 1243 // 1244 // Expected result: 1245 // should autofill: yes 1246 add_autofill_task(async function suggestHistoryFalse_bookmark_prefix_0() { 1247 // Add the bookmark. 1248 await PlacesTestUtils.addBookmarkWithDetails({ 1249 uri: "http://" + url, 1250 }); 1251 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1252 1253 // Make the bookmark fall below the autofill frecency threshold so we ensure 1254 // the bookmark is always autofilled in this case, even if it doesn't meet 1255 // the threshold. 1256 await TestUtils.waitForCondition(async () => { 1257 // Add a visit to another origin to boost the threshold. 1258 await PlacesTestUtils.addVisits("http://foo-" + url); 1259 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1260 let originFrecency = await getOriginFrecency("http://", host); 1261 let threshold = await getOriginAutofillThreshold(); 1262 return threshold > originFrecency; 1263 }, "Make the bookmark fall below the frecency threshold"); 1264 1265 // At this point, the bookmark doesn't meet the threshold, but it should 1266 // still be autofilled. 1267 let originFrecency = await getOriginFrecency("http://", host); 1268 let threshold = await getOriginAutofillThreshold(); 1269 Assert.less(originFrecency, threshold); 1270 1271 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1272 await PlacesTestUtils.addBookmarkWithDetails({ 1273 uri: "http://" + url, 1274 }); 1275 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1276 let context = createContext("http://" + search, { isPrivate: false }); 1277 await check_results({ 1278 context, 1279 autofilled: "http://" + url, 1280 completed: "http://" + url, 1281 matches: [ 1282 makeVisitResult(context, { 1283 uri: "http://" + url, 1284 title: "A bookmark", 1285 heuristic: true, 1286 }), 1287 ], 1288 }); 1289 await cleanup(); 1290 }); 1291 1292 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1293 // 1294 // Config: 1295 // suggest.history = false 1296 // suggest.bookmark = true 1297 // search for: bookmark 1298 // prefix search: yes 1299 // prefix matches search: no 1300 // origin matches search: yes 1301 // 1302 // Expected result: 1303 // should autofill: no 1304 add_autofill_task(async function suggestHistoryFalse_bookmark_prefix_1() { 1305 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1306 await PlacesTestUtils.addBookmarkWithDetails({ 1307 uri: "ftp://" + url, 1308 }); 1309 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1310 let context = createContext("http://" + search, { isPrivate: false }); 1311 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1312 await check_results({ 1313 context, 1314 matches: [ 1315 makeVisitResult(context, { 1316 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1317 uri: prefixedUrl, 1318 title: prefixedUrl, 1319 heuristic: true, 1320 iconUri: origins ? "" : `page-icon:http://${host}/`, 1321 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1322 }), 1323 makeBookmarkResult(context, { 1324 uri: "ftp://" + url, 1325 title: "A bookmark", 1326 }), 1327 ], 1328 }); 1329 await cleanup(); 1330 }); 1331 1332 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1333 // 1334 // Config: 1335 // suggest.history = false 1336 // suggest.bookmark = true 1337 // search for: bookmark 1338 // prefix search: yes 1339 // prefix matches search: yes 1340 // origin matches search: no 1341 // 1342 // Expected result: 1343 // should autofill: no 1344 add_autofill_task(async function suggestHistoryFalse_bookmark_prefix_2() { 1345 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1346 await PlacesTestUtils.addBookmarkWithDetails({ 1347 uri: "http://non-matching-" + url, 1348 }); 1349 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1350 let context = createContext("http://" + search, { isPrivate: false }); 1351 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1352 await check_results({ 1353 context, 1354 matches: [ 1355 makeVisitResult(context, { 1356 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1357 uri: prefixedUrl, 1358 title: prefixedUrl, 1359 heuristic: true, 1360 iconUri: origins ? "" : `page-icon:http://${host}/`, 1361 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1362 }), 1363 makeBookmarkResult(context, { 1364 uri: "http://non-matching-" + url, 1365 title: "A bookmark", 1366 }), 1367 ], 1368 }); 1369 await cleanup(); 1370 }); 1371 1372 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1373 // 1374 // Config: 1375 // suggest.history = false 1376 // suggest.bookmark = true 1377 // search for: bookmark 1378 // prefix search: yes 1379 // prefix matches search: no 1380 // origin matches search: no 1381 // 1382 // Expected result: 1383 // should autofill: no 1384 add_autofill_task(async function suggestHistoryFalse_bookmark_prefix_3() { 1385 Services.prefs.setBoolPref("browser.urlbar.suggest.history", false); 1386 await PlacesTestUtils.addBookmarkWithDetails({ 1387 uri: "ftp://non-matching-" + url, 1388 }); 1389 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1390 let context = createContext("http://" + search, { isPrivate: false }); 1391 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1392 await check_results({ 1393 context, 1394 matches: [ 1395 makeVisitResult(context, { 1396 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1397 uri: prefixedUrl, 1398 title: prefixedUrl, 1399 heuristic: true, 1400 iconUri: origins ? "" : `page-icon:http://${host}/`, 1401 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1402 }), 1403 makeBookmarkResult(context, { 1404 uri: "ftp://non-matching-" + url, 1405 title: "A bookmark", 1406 }), 1407 ], 1408 }); 1409 await cleanup(); 1410 }); 1411 1412 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1413 // 1414 // Config: 1415 // suggest.history = true 1416 // suggest.bookmark = false 1417 // search for: visit 1418 // prefix search: no 1419 // prefix matches search: n/a 1420 // origin matches search: yes 1421 // 1422 // Expected result: 1423 // should autofill: yes 1424 add_autofill_task(async function suggestBookmarkFalse_visit_0() { 1425 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1426 await PlacesTestUtils.addVisits("http://" + url); 1427 let context = createContext(search, { isPrivate: false }); 1428 await check_results({ 1429 context, 1430 autofilled: url, 1431 completed: "http://" + url, 1432 matches: [ 1433 makeVisitResult(context, { 1434 uri: "http://" + url, 1435 title: visitTitle("http", ""), 1436 heuristic: true, 1437 }), 1438 ], 1439 }); 1440 await cleanup(); 1441 }); 1442 1443 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1444 // 1445 // Config: 1446 // suggest.history = true 1447 // suggest.bookmark = false 1448 // search for: visit 1449 // prefix search: no 1450 // prefix matches search: n/a 1451 // origin matches search: no 1452 // 1453 // Expected result: 1454 // should autofill: no 1455 add_autofill_task(async function suggestBookmarkFalse_visit_1() { 1456 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1457 await PlacesTestUtils.addVisits("http://non-matching-" + url); 1458 let context = createContext(search, { isPrivate: false }); 1459 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1460 let matches = [ 1461 makeVisitResult(context, { 1462 uri: "http://non-matching-" + url, 1463 title: "test visit for http://non-matching-" + url, 1464 providerName: PLACES_PROVIDERNAME, 1465 }), 1466 ]; 1467 if (origins) { 1468 matches.unshift( 1469 makeSearchResult(context, { 1470 engineName: SUGGESTIONS_ENGINE_NAME, 1471 heuristic: true, 1472 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1473 }) 1474 ); 1475 } else { 1476 matches.unshift( 1477 makeVisitResult(context, { 1478 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1479 uri: prefixedUrl, 1480 title: UrlbarUtils.stripPrefixAndTrim(prefixedUrl, { 1481 stripHttp: true, 1482 stripHttps: true, 1483 })[0], 1484 heuristic: true, 1485 iconUri: origins ? "" : `page-icon:http://${host}/`, 1486 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1487 }) 1488 ); 1489 } 1490 await check_results({ 1491 context, 1492 matches, 1493 }); 1494 await cleanup(); 1495 }); 1496 1497 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1498 // 1499 // Config: 1500 // suggest.history = true 1501 // suggest.bookmark = false 1502 // search for: visit 1503 // prefix search: yes 1504 // prefix matches search: yes 1505 // origin matches search: yes 1506 // 1507 // Expected result: 1508 // should autofill: yes 1509 add_autofill_task(async function suggestBookmarkFalse_visit_prefix_0() { 1510 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1511 await PlacesTestUtils.addVisits("http://" + url); 1512 let context = createContext("http://" + search, { isPrivate: false }); 1513 await check_results({ 1514 context, 1515 autofilled: "http://" + url, 1516 completed: "http://" + url, 1517 matches: [ 1518 makeVisitResult(context, { 1519 uri: "http://" + url, 1520 title: visitTitle("http", ""), 1521 heuristic: true, 1522 }), 1523 ], 1524 }); 1525 await cleanup(); 1526 }); 1527 1528 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1529 // 1530 // Config: 1531 // suggest.history = true 1532 // suggest.bookmark = false 1533 // search for: visit 1534 // prefix search: yes 1535 // prefix matches search: no 1536 // origin matches search: yes 1537 // 1538 // Expected result: 1539 // should autofill: no 1540 add_autofill_task(async function suggestBookmarkFalse_visit_prefix_1() { 1541 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1542 await PlacesTestUtils.addVisits("ftp://" + url); 1543 let context = createContext("http://" + search, { isPrivate: false }); 1544 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1545 await check_results({ 1546 context, 1547 matches: [ 1548 makeVisitResult(context, { 1549 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1550 uri: prefixedUrl, 1551 title: prefixedUrl, 1552 heuristic: true, 1553 iconUri: origins ? "" : `page-icon:http://${host}/`, 1554 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1555 }), 1556 makeVisitResult(context, { 1557 uri: "ftp://" + url, 1558 title: "test visit for ftp://" + url, 1559 providerName: PLACES_PROVIDERNAME, 1560 }), 1561 ], 1562 }); 1563 await cleanup(); 1564 }); 1565 1566 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1567 // 1568 // Config: 1569 // suggest.history = true 1570 // suggest.bookmark = false 1571 // search for: visit 1572 // prefix search: yes 1573 // prefix matches search: yes 1574 // origin matches search: no 1575 // 1576 // Expected result: 1577 // should autofill: no 1578 add_autofill_task(async function suggestBookmarkFalse_visit_prefix_2() { 1579 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1580 await PlacesTestUtils.addVisits("http://non-matching-" + url); 1581 let context = createContext("http://" + search, { isPrivate: false }); 1582 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1583 await check_results({ 1584 context, 1585 matches: [ 1586 makeVisitResult(context, { 1587 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1588 uri: prefixedUrl, 1589 title: prefixedUrl, 1590 heuristic: true, 1591 iconUri: origins ? "" : `page-icon:http://${host}/`, 1592 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1593 }), 1594 makeVisitResult(context, { 1595 uri: "http://non-matching-" + url, 1596 title: "test visit for http://non-matching-" + url, 1597 providerName: PLACES_PROVIDERNAME, 1598 }), 1599 ], 1600 }); 1601 await cleanup(); 1602 }); 1603 1604 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1605 // 1606 // Config: 1607 // suggest.history = true 1608 // suggest.bookmark = false 1609 // search for: visit 1610 // prefix search: yes 1611 // prefix matches search: no 1612 // origin matches search: no 1613 // 1614 // Expected result: 1615 // should autofill: no 1616 add_autofill_task(async function suggestBookmarkFalse_visit_prefix_3() { 1617 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1618 await PlacesTestUtils.addVisits("ftp://non-matching-" + url); 1619 let context = createContext("http://" + search, { isPrivate: false }); 1620 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1621 await check_results({ 1622 context, 1623 matches: [ 1624 makeVisitResult(context, { 1625 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1626 uri: prefixedUrl, 1627 title: prefixedUrl, 1628 heuristic: true, 1629 iconUri: origins ? "" : `page-icon:http://${host}/`, 1630 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1631 }), 1632 makeVisitResult(context, { 1633 uri: "ftp://non-matching-" + url, 1634 title: "test visit for ftp://non-matching-" + url, 1635 providerName: PLACES_PROVIDERNAME, 1636 }), 1637 ], 1638 }); 1639 await cleanup(); 1640 }); 1641 1642 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1643 // 1644 // Config: 1645 // suggest.history = true 1646 // suggest.bookmark = false 1647 // search for: unvisited bookmark 1648 // prefix search: no 1649 // prefix matches search: n/a 1650 // origin matches search: yes 1651 // 1652 // Expected result: 1653 // should autofill: no 1654 add_autofill_task(async function suggestBookmarkFalse_unvisitedBookmark() { 1655 await PlacesTestUtils.addBookmarkWithDetails({ 1656 uri: "http://" + url, 1657 }); 1658 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1659 let context = createContext(search, { isPrivate: false }); 1660 await check_results({ 1661 context, 1662 autofilled: url, 1663 completed: "http://" + url, 1664 matches: [ 1665 makeVisitResult(context, { 1666 uri: "http://" + url, 1667 title: "A bookmark", 1668 heuristic: true, 1669 }), 1670 ], 1671 }); 1672 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1673 context = createContext(search, { isPrivate: false }); 1674 if (origins) { 1675 await check_results({ 1676 context, 1677 matches: [ 1678 makeSearchResult(context, { 1679 engineName: SUGGESTIONS_ENGINE_NAME, 1680 heuristic: true, 1681 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1682 }), 1683 ], 1684 }); 1685 } else { 1686 await check_results({ 1687 context, 1688 matches: [ 1689 makeVisitResult(context, { 1690 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1691 uri: "http://" + search, 1692 title: search, 1693 iconUri: `page-icon:http://${host}/`, 1694 heuristic: true, 1695 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1696 }), 1697 ], 1698 }); 1699 } 1700 await cleanup(); 1701 }); 1702 1703 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1704 // 1705 // Config: 1706 // suggest.history = true 1707 // suggest.bookmark = false 1708 // search for: unvisited bookmark 1709 // prefix search: yes 1710 // prefix matches search: yes 1711 // origin matches search: yes 1712 // 1713 // Expected result: 1714 // should autofill: no 1715 add_autofill_task( 1716 async function suggestBookmarkFalse_unvisitedBookmark_prefix_0() { 1717 await PlacesTestUtils.addBookmarkWithDetails({ 1718 uri: "http://" + url, 1719 }); 1720 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1721 let context = createContext("http://" + search, { isPrivate: false }); 1722 await check_results({ 1723 context, 1724 autofilled: "http://" + url, 1725 completed: "http://" + url, 1726 matches: [ 1727 makeVisitResult(context, { 1728 uri: "http://" + url, 1729 title: "A bookmark", 1730 heuristic: true, 1731 }), 1732 ], 1733 }); 1734 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1735 context = createContext("http://" + search, { isPrivate: false }); 1736 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1737 await check_results({ 1738 context, 1739 matches: [ 1740 makeVisitResult(context, { 1741 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1742 uri: prefixedUrl, 1743 title: prefixedUrl, 1744 heuristic: true, 1745 iconUri: origins ? "" : `page-icon:http://${host}/`, 1746 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1747 }), 1748 ], 1749 }); 1750 await cleanup(); 1751 } 1752 ); 1753 1754 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1755 // 1756 // Config: 1757 // suggest.history = true 1758 // suggest.bookmark = false 1759 // search for: unvisited bookmark 1760 // prefix search: yes 1761 // prefix matches search: no 1762 // origin matches search: yes 1763 // 1764 // Expected result: 1765 // should autofill: no 1766 add_autofill_task( 1767 async function suggestBookmarkFalse_unvisitedBookmark_prefix_1() { 1768 await PlacesTestUtils.addBookmarkWithDetails({ 1769 uri: "ftp://" + url, 1770 }); 1771 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1772 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1773 let context = createContext("http://" + search, { isPrivate: false }); 1774 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1775 await check_results({ 1776 context, 1777 matches: [ 1778 makeVisitResult(context, { 1779 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1780 uri: prefixedUrl, 1781 title: prefixedUrl, 1782 heuristic: true, 1783 iconUri: origins ? "" : `page-icon:http://${host}/`, 1784 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1785 }), 1786 ], 1787 }); 1788 await cleanup(); 1789 } 1790 ); 1791 1792 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1793 // 1794 // Config: 1795 // suggest.history = true 1796 // suggest.bookmark = false 1797 // search for: unvisited bookmark 1798 // prefix search: yes 1799 // prefix matches search: yes 1800 // origin matches search: no 1801 // 1802 // Expected result: 1803 // should autofill: no 1804 add_autofill_task( 1805 async function suggestBookmarkFalse_unvisitedBookmark_prefix_2() { 1806 await PlacesTestUtils.addBookmarkWithDetails({ 1807 uri: "http://non-matching-" + url, 1808 }); 1809 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1810 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1811 let context = createContext("http://" + search, { isPrivate: false }); 1812 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1813 await check_results({ 1814 context, 1815 matches: [ 1816 makeVisitResult(context, { 1817 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1818 uri: prefixedUrl, 1819 title: prefixedUrl, 1820 heuristic: true, 1821 iconUri: origins ? "" : `page-icon:http://${host}/`, 1822 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1823 }), 1824 ], 1825 }); 1826 await cleanup(); 1827 } 1828 ); 1829 1830 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1831 // 1832 // Config: 1833 // suggest.history = true 1834 // suggest.bookmark = false 1835 // search for: unvisited bookmark 1836 // prefix search: yes 1837 // prefix matches search: no 1838 // origin matches search: no 1839 // 1840 // Expected result: 1841 // should autofill: no 1842 add_autofill_task( 1843 async function suggestBookmarkFalse_unvisitedBookmark_prefix_3() { 1844 await PlacesTestUtils.addBookmarkWithDetails({ 1845 uri: "ftp://non-matching-" + url, 1846 }); 1847 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1848 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1849 let context = createContext("http://" + search, { isPrivate: false }); 1850 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1851 await check_results({ 1852 context, 1853 matches: [ 1854 makeVisitResult(context, { 1855 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1856 uri: prefixedUrl, 1857 title: prefixedUrl, 1858 heuristic: true, 1859 iconUri: origins ? "" : `page-icon:http://${host}/`, 1860 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1861 }), 1862 ], 1863 }); 1864 await cleanup(); 1865 } 1866 ); 1867 1868 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1869 // 1870 // Config: 1871 // suggest.history = true 1872 // suggest.bookmark = false 1873 // search for: visited bookmark above autofill threshold 1874 // prefix search: no 1875 // prefix matches search: n/a 1876 // origin matches search: yes 1877 // 1878 // Expected result: 1879 // should autofill: yes 1880 add_autofill_task(async function suggestBookmarkFalse_visitedBookmark_above() { 1881 await PlacesTestUtils.addVisits("http://" + url); 1882 await PlacesTestUtils.addBookmarkWithDetails({ 1883 uri: "http://" + url, 1884 }); 1885 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1886 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1887 let context = createContext(search, { isPrivate: false }); 1888 await check_results({ 1889 context, 1890 autofilled: url, 1891 completed: "http://" + url, 1892 matches: [ 1893 makeVisitResult(context, { 1894 uri: "http://" + url, 1895 title: visitTitle("http", ""), 1896 heuristic: true, 1897 }), 1898 ], 1899 }); 1900 await cleanup(); 1901 }); 1902 1903 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1904 // 1905 // Config: 1906 // suggest.history = true 1907 // suggest.bookmark = false 1908 // search for: visited bookmark above autofill threshold 1909 // prefix search: yes 1910 // prefix matches search: yes 1911 // origin matches search: yes 1912 // 1913 // Expected result: 1914 // should autofill: yes 1915 add_autofill_task( 1916 async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_0() { 1917 await PlacesTestUtils.addVisits("http://" + url); 1918 await PlacesTestUtils.addBookmarkWithDetails({ 1919 uri: "http://" + url, 1920 }); 1921 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1922 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1923 let context = createContext("http://" + search, { isPrivate: false }); 1924 await check_results({ 1925 context, 1926 autofilled: "http://" + url, 1927 completed: "http://" + url, 1928 matches: [ 1929 makeVisitResult(context, { 1930 uri: "http://" + url, 1931 title: visitTitle("http", ""), 1932 heuristic: true, 1933 }), 1934 ], 1935 }); 1936 await cleanup(); 1937 } 1938 ); 1939 1940 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1941 // 1942 // Config: 1943 // suggest.history = true 1944 // suggest.bookmark = false 1945 // search for: visited bookmark above autofill threshold 1946 // prefix search: yes 1947 // prefix matches search: no 1948 // origin matches search: yes 1949 // 1950 // Expected result: 1951 // should autofill: no 1952 add_autofill_task( 1953 async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_1() { 1954 await PlacesTestUtils.addVisits("ftp://" + url); 1955 await PlacesTestUtils.addBookmarkWithDetails({ 1956 uri: "ftp://" + url, 1957 }); 1958 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 1959 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 1960 let context = createContext("http://" + search, { isPrivate: false }); 1961 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 1962 await check_results({ 1963 context, 1964 matches: [ 1965 makeVisitResult(context, { 1966 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 1967 uri: prefixedUrl, 1968 title: prefixedUrl, 1969 heuristic: true, 1970 iconUri: origins ? "" : `page-icon:http://${host}/`, 1971 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 1972 }), 1973 makeBookmarkResult(context, { 1974 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 1975 uri: "ftp://" + url, 1976 title: "A bookmark", 1977 }), 1978 ], 1979 }); 1980 await cleanup(); 1981 } 1982 ); 1983 1984 // Tests interaction between the suggest.history and suggest.bookmark prefs. 1985 // 1986 // Config: 1987 // suggest.history = true 1988 // suggest.bookmark = false 1989 // search for: visited bookmark above autofill threshold 1990 // prefix search: yes 1991 // prefix matches search: yes 1992 // origin matches search: no 1993 // 1994 // Expected result: 1995 // should autofill: no 1996 add_autofill_task( 1997 async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_2() { 1998 await PlacesTestUtils.addVisits("http://non-matching-" + url); 1999 await PlacesTestUtils.addBookmarkWithDetails({ 2000 uri: "http://non-matching-" + url, 2001 }); 2002 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2003 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2004 let context = createContext("http://" + search, { isPrivate: false }); 2005 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 2006 await check_results({ 2007 context, 2008 matches: [ 2009 makeVisitResult(context, { 2010 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2011 uri: prefixedUrl, 2012 title: prefixedUrl, 2013 heuristic: true, 2014 iconUri: origins ? "" : `page-icon:http://${host}/`, 2015 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2016 }), 2017 makeBookmarkResult(context, { 2018 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 2019 uri: "http://non-matching-" + url, 2020 title: "A bookmark", 2021 }), 2022 ], 2023 }); 2024 await cleanup(); 2025 } 2026 ); 2027 2028 // Tests interaction between the suggest.history and suggest.bookmark prefs. 2029 // 2030 // Config: 2031 // suggest.history = true 2032 // suggest.bookmark = false 2033 // search for: visited bookmark above autofill threshold 2034 // prefix search: yes 2035 // prefix matches search: no 2036 // origin matches search: no 2037 // 2038 // Expected result: 2039 // should autofill: no 2040 add_autofill_task( 2041 async function suggestBookmarkFalse_visitedBookmarkAbove_prefix_3() { 2042 await PlacesTestUtils.addVisits("ftp://non-matching-" + url); 2043 await PlacesTestUtils.addBookmarkWithDetails({ 2044 uri: "ftp://non-matching-" + url, 2045 }); 2046 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2047 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2048 let context = createContext("http://" + search, { isPrivate: false }); 2049 let prefixedUrl = origins ? `http://${search}/` : `http://${search}`; 2050 await check_results({ 2051 context, 2052 matches: [ 2053 makeVisitResult(context, { 2054 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2055 uri: prefixedUrl, 2056 title: prefixedUrl, 2057 heuristic: true, 2058 iconUri: origins ? "" : `page-icon:http://${host}/`, 2059 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2060 }), 2061 makeBookmarkResult(context, { 2062 source: UrlbarUtils.RESULT_SOURCE.HISTORY, 2063 uri: "ftp://non-matching-" + url, 2064 title: "A bookmark", 2065 }), 2066 ], 2067 }); 2068 await cleanup(); 2069 } 2070 ); 2071 2072 // The following suggestBookmarkFalse_visitedBookmarkBelow* tests are similar 2073 // to the suggestBookmarkFalse_visitedBookmarkAbove* tests, but instead of 2074 // checking visited bookmarks above the autofill threshold, they check visited 2075 // bookmarks below the threshold. These tests don't make sense for URL 2076 // queries (as opposed to origin queries) because URL queries don't use the 2077 // same autofill threshold, so we skip them when !origins. 2078 2079 // Tests interaction between the suggest.history and suggest.bookmark prefs. 2080 // 2081 // Config: 2082 // suggest.history = true 2083 // suggest.bookmark = false 2084 // search for: visited bookmark below autofill threshold 2085 // prefix search: no 2086 // prefix matches search: n/a 2087 // origin matches search: yes 2088 // 2089 // Expected result: 2090 // should autofill: no 2091 add_autofill_task(async function suggestBookmarkFalse_visitedBookmarkBelow() { 2092 if (!origins) { 2093 // See comment above suggestBookmarkFalse_visitedBookmarkBelow. 2094 return; 2095 } 2096 // First, make sure that `url` is below the autofill threshold. 2097 await PlacesTestUtils.addVisits({ 2098 uri: "http://" + url, 2099 visitDate: daysAgo(30), 2100 }); 2101 await PlacesTestUtils.addVisits({ 2102 uri: "http://some-other-" + url, 2103 }); 2104 await PlacesTestUtils.addVisits("http://other-website.com"); 2105 2106 let context = createContext(search, { isPrivate: false }); 2107 await check_results({ 2108 context, 2109 matches: [ 2110 makeSearchResult(context, { 2111 engineName: SUGGESTIONS_ENGINE_NAME, 2112 heuristic: true, 2113 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2114 }), 2115 makeVisitResult(context, { 2116 uri: "http://some-other-" + url, 2117 title: "test visit for http://some-other-" + url, 2118 providerName: PLACES_PROVIDERNAME, 2119 }), 2120 makeVisitResult(context, { 2121 uri: "http://" + url, 2122 title: "test visit for http://" + url, 2123 providerName: PLACES_PROVIDERNAME, 2124 }), 2125 ], 2126 }); 2127 // Now bookmark it and set suggest.bookmark to false. 2128 await PlacesTestUtils.addBookmarkWithDetails({ 2129 uri: "http://" + url, 2130 }); 2131 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2132 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2133 context = createContext(search, { isPrivate: false }); 2134 await check_results({ 2135 context, 2136 matches: [ 2137 makeSearchResult(context, { 2138 engineName: SUGGESTIONS_ENGINE_NAME, 2139 heuristic: true, 2140 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2141 }), 2142 makeVisitResult(context, { 2143 uri: "http://some-other-" + url, 2144 title: "test visit for http://some-other-" + url, 2145 providerName: PLACES_PROVIDERNAME, 2146 }), 2147 makeVisitResult(context, { 2148 uri: "http://" + url, 2149 title: "A bookmark", 2150 providerName: PLACES_PROVIDERNAME, 2151 }), 2152 ], 2153 }); 2154 await cleanup(); 2155 }); 2156 2157 // Tests interaction between the suggest.history and suggest.bookmark prefs. 2158 // 2159 // Config: 2160 // suggest.history = true 2161 // suggest.bookmark = false 2162 // search for: visited bookmark below autofill threshold 2163 // prefix search: yes 2164 // prefix matches search: yes 2165 // origin matches search: yes 2166 // 2167 // Expected result: 2168 // should autofill: no 2169 add_autofill_task( 2170 async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_0() { 2171 if (!origins) { 2172 // See comment above suggestBookmarkFalse_visitedBookmarkBelow. 2173 return; 2174 } 2175 // First, make sure that `url` is below the autofill threshold. 2176 await PlacesTestUtils.addVisits({ 2177 uri: "http://" + url, 2178 visitDate: daysAgo(30), 2179 }); 2180 await PlacesTestUtils.addVisits("http://some-other-" + url); 2181 await PlacesTestUtils.addVisits("http://other-website.com"); 2182 2183 let context = createContext("http://" + search, { isPrivate: false }); 2184 await check_results({ 2185 context, 2186 matches: [ 2187 makeVisitResult(context, { 2188 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2189 uri: `http://${search}/`, 2190 title: `http://${search}/`, 2191 heuristic: true, 2192 iconUri: "", 2193 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2194 }), 2195 makeVisitResult(context, { 2196 uri: "http://some-other-" + url, 2197 title: "test visit for http://some-other-" + url, 2198 providerName: PLACES_PROVIDERNAME, 2199 }), 2200 makeVisitResult(context, { 2201 uri: "http://" + url, 2202 title: "test visit for http://" + url, 2203 providerName: PLACES_PROVIDERNAME, 2204 }), 2205 ], 2206 }); 2207 // Now bookmark it and set suggest.bookmark to false. 2208 await PlacesTestUtils.addBookmarkWithDetails({ 2209 uri: "http://" + url, 2210 }); 2211 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2212 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2213 context = createContext("http://" + search, { isPrivate: false }); 2214 await check_results({ 2215 context, 2216 matches: [ 2217 makeVisitResult(context, { 2218 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2219 uri: `http://${search}/`, 2220 title: `http://${search}/`, 2221 heuristic: true, 2222 iconUri: "", 2223 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2224 }), 2225 makeVisitResult(context, { 2226 uri: "http://some-other-" + url, 2227 title: "test visit for http://some-other-" + url, 2228 providerName: PLACES_PROVIDERNAME, 2229 }), 2230 makeVisitResult(context, { 2231 uri: "http://" + url, 2232 title: "A bookmark", 2233 providerName: PLACES_PROVIDERNAME, 2234 }), 2235 ], 2236 }); 2237 await cleanup(); 2238 } 2239 ); 2240 2241 // Tests interaction between the suggest.history and suggest.bookmark prefs. 2242 // 2243 // Config: 2244 // suggest.history = true 2245 // suggest.bookmark = false 2246 // search for: visited bookmark below autofill threshold 2247 // prefix search: yes 2248 // prefix matches search: no 2249 // origin matches search: yes 2250 // 2251 // Expected result: 2252 // should autofill: no 2253 add_autofill_task( 2254 async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_1() { 2255 if (!origins) { 2256 // See comment above suggestBookmarkFalse_visitedBookmarkBelow. 2257 return; 2258 } 2259 // First, make sure that `url` is below the autofill threshold. 2260 await PlacesTestUtils.addVisits("ftp://" + url); 2261 for (let i = 0; i < 3; i++) { 2262 await PlacesTestUtils.addVisits("ftp://some-other-" + url); 2263 } 2264 let context = createContext("http://" + search, { isPrivate: false }); 2265 await check_results({ 2266 context, 2267 matches: [ 2268 makeVisitResult(context, { 2269 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2270 uri: `http://${search}/`, 2271 title: `http://${search}/`, 2272 heuristic: true, 2273 iconUri: "", 2274 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2275 }), 2276 makeVisitResult(context, { 2277 uri: "ftp://some-other-" + url, 2278 title: "test visit for ftp://some-other-" + url, 2279 providerName: PLACES_PROVIDERNAME, 2280 }), 2281 makeVisitResult(context, { 2282 uri: "ftp://" + url, 2283 title: "test visit for ftp://" + url, 2284 providerName: PLACES_PROVIDERNAME, 2285 }), 2286 ], 2287 }); 2288 // Now bookmark it and set suggest.bookmark to false. 2289 await PlacesTestUtils.addBookmarkWithDetails({ 2290 uri: "ftp://" + url, 2291 }); 2292 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2293 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2294 context = createContext("http://" + search, { isPrivate: false }); 2295 await check_results({ 2296 context, 2297 matches: [ 2298 makeVisitResult(context, { 2299 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2300 uri: `http://${search}/`, 2301 title: `http://${search}/`, 2302 heuristic: true, 2303 iconUri: "", 2304 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2305 }), 2306 makeVisitResult(context, { 2307 uri: "ftp://some-other-" + url, 2308 title: "test visit for ftp://some-other-" + url, 2309 providerName: PLACES_PROVIDERNAME, 2310 }), 2311 makeVisitResult(context, { 2312 uri: "ftp://" + url, 2313 title: "A bookmark", 2314 providerName: PLACES_PROVIDERNAME, 2315 }), 2316 ], 2317 }); 2318 await cleanup(); 2319 } 2320 ); 2321 2322 // Tests interaction between the suggest.history and suggest.bookmark prefs. 2323 // 2324 // Config: 2325 // suggest.history = true 2326 // suggest.bookmark = false 2327 // search for: visited bookmark below autofill threshold 2328 // prefix search: yes 2329 // prefix matches search: yes 2330 // origin matches search: no 2331 // 2332 // Expected result: 2333 // should autofill: no 2334 add_autofill_task( 2335 async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_2() { 2336 if (!origins) { 2337 // See comment above suggestBookmarkFalse_visitedBookmarkBelow. 2338 return; 2339 } 2340 // First, make sure that `url` is below the autofill threshold. 2341 await PlacesTestUtils.addVisits("http://non-matching-" + url); 2342 for (let i = 0; i < 3; i++) { 2343 await PlacesTestUtils.addVisits("http://some-other-" + url); 2344 } 2345 let context = createContext("http://" + search, { isPrivate: false }); 2346 await check_results({ 2347 context, 2348 matches: [ 2349 makeVisitResult(context, { 2350 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2351 uri: `http://${search}/`, 2352 title: `http://${search}/`, 2353 heuristic: true, 2354 iconUri: "", 2355 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2356 }), 2357 makeVisitResult(context, { 2358 uri: "http://some-other-" + url, 2359 title: "test visit for http://some-other-" + url, 2360 providerName: PLACES_PROVIDERNAME, 2361 }), 2362 makeVisitResult(context, { 2363 uri: "http://non-matching-" + url, 2364 title: "test visit for http://non-matching-" + url, 2365 providerName: PLACES_PROVIDERNAME, 2366 }), 2367 ], 2368 }); 2369 // Now bookmark it and set suggest.bookmark to false. 2370 await PlacesTestUtils.addBookmarkWithDetails({ 2371 uri: "http://non-matching-" + url, 2372 }); 2373 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2374 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2375 context = createContext("http://" + search, { isPrivate: false }); 2376 await check_results({ 2377 context, 2378 matches: [ 2379 makeVisitResult(context, { 2380 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2381 uri: `http://${search}/`, 2382 title: `http://${search}/`, 2383 heuristic: true, 2384 iconUri: "", 2385 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2386 }), 2387 makeVisitResult(context, { 2388 uri: "http://some-other-" + url, 2389 title: "test visit for http://some-other-" + url, 2390 providerName: PLACES_PROVIDERNAME, 2391 }), 2392 makeVisitResult(context, { 2393 uri: "http://non-matching-" + url, 2394 title: "A bookmark", 2395 providerName: PLACES_PROVIDERNAME, 2396 }), 2397 ], 2398 }); 2399 await cleanup(); 2400 } 2401 ); 2402 2403 // Tests interaction between the suggest.history and suggest.bookmark prefs. 2404 // 2405 // Config: 2406 // suggest.history = true 2407 // suggest.bookmark = false 2408 // search for: visited bookmark below autofill threshold 2409 // prefix search: yes 2410 // prefix matches search: no 2411 // origin matches search: no 2412 // 2413 // Expected result: 2414 // should autofill: no 2415 add_autofill_task( 2416 async function suggestBookmarkFalse_visitedBookmarkBelow_prefix_3() { 2417 if (!origins) { 2418 // See comment above suggestBookmarkFalse_visitedBookmarkBelow. 2419 return; 2420 } 2421 // First, make sure that `url` is below the autofill threshold. 2422 await PlacesTestUtils.addVisits("ftp://non-matching-" + url); 2423 for (let i = 0; i < 3; i++) { 2424 await PlacesTestUtils.addVisits("ftp://some-other-" + url); 2425 } 2426 let context = createContext("http://" + search, { isPrivate: false }); 2427 await check_results({ 2428 context, 2429 matches: [ 2430 makeVisitResult(context, { 2431 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2432 uri: `http://${search}/`, 2433 title: `http://${search}/`, 2434 heuristic: true, 2435 iconUri: "", 2436 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2437 }), 2438 makeVisitResult(context, { 2439 uri: "ftp://some-other-" + url, 2440 title: "test visit for ftp://some-other-" + url, 2441 providerName: PLACES_PROVIDERNAME, 2442 }), 2443 makeVisitResult(context, { 2444 uri: "ftp://non-matching-" + url, 2445 title: "test visit for ftp://non-matching-" + url, 2446 providerName: PLACES_PROVIDERNAME, 2447 }), 2448 ], 2449 }); 2450 // Now bookmark it and set suggest.bookmark to false. 2451 await PlacesTestUtils.addBookmarkWithDetails({ 2452 uri: "ftp://non-matching-" + url, 2453 }); 2454 await PlacesFrecencyRecalculator.recalculateAnyOutdatedFrecencies(); 2455 Services.prefs.setBoolPref("browser.urlbar.suggest.bookmark", false); 2456 context = createContext("http://" + search, { isPrivate: false }); 2457 await check_results({ 2458 context, 2459 matches: [ 2460 makeVisitResult(context, { 2461 source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL, 2462 uri: `http://${search}/`, 2463 title: `http://${search}/`, 2464 heuristic: true, 2465 iconUri: "", 2466 providerName: HEURISTIC_FALLBACK_PROVIDERNAME, 2467 }), 2468 makeVisitResult(context, { 2469 uri: "ftp://some-other-" + url, 2470 title: "test visit for ftp://some-other-" + url, 2471 providerName: PLACES_PROVIDERNAME, 2472 }), 2473 makeVisitResult(context, { 2474 uri: "ftp://non-matching-" + url, 2475 title: "A bookmark", 2476 providerName: PLACES_PROVIDERNAME, 2477 }), 2478 ], 2479 }); 2480 await cleanup(); 2481 } 2482 ); 2483 2484 // When the heuristic is hidden, "ex" should autofill http://example.com/, and 2485 // there should be an additional http://example.com/ non-autofill result. 2486 add_autofill_task(async function hideHeuristic() { 2487 UrlbarPrefs.set("experimental.hideHeuristic", true); 2488 await PlacesTestUtils.addVisits("http://" + url); 2489 let context = createContext(search, { isPrivate: false }); 2490 await check_results({ 2491 context, 2492 autofilled: url, 2493 completed: "http://" + url, 2494 matches: [ 2495 makeVisitResult(context, { 2496 uri: "http://" + url, 2497 title: visitTitle("http", ""), 2498 heuristic: true, 2499 }), 2500 makeVisitResult(context, { 2501 uri: "http://" + url, 2502 title: "test visit for http://" + url, 2503 }), 2504 ], 2505 }); 2506 await cleanup(); 2507 UrlbarPrefs.set("experimental.hideHeuristic", false); 2508 });