tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_muxer.js (21381B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const lazy = {};
      7 
      8 ChromeUtils.defineESModuleGetters(lazy, {
      9  sinon: "resource://testing-common/Sinon.sys.mjs",
     10 });
     11 
     12 let sandbox;
     13 
     14 add_setup(async function () {
     15  sandbox = lazy.sinon.createSandbox();
     16  registerCleanupFunction(() => {
     17    sandbox.restore();
     18  });
     19 });
     20 
     21 add_task(async function test_muxer() {
     22  Assert.throws(
     23    () => UrlbarProvidersManager.registerMuxer(),
     24    /invalid muxer/,
     25    "Should throw with no arguments"
     26  );
     27  Assert.throws(
     28    () => UrlbarProvidersManager.registerMuxer({}),
     29    /invalid muxer/,
     30    "Should throw with empty object"
     31  );
     32  Assert.throws(
     33    () =>
     34      UrlbarProvidersManager.registerMuxer({
     35        name: "",
     36      }),
     37    /invalid muxer/,
     38    "Should throw with empty name"
     39  );
     40  Assert.throws(
     41    () =>
     42      UrlbarProvidersManager.registerMuxer({
     43        name: "test",
     44        sort: "no",
     45      }),
     46    /invalid muxer/,
     47    "Should throw with invalid sort"
     48  );
     49 
     50  let matches = [
     51    new UrlbarResult({
     52      type: UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
     53      source: UrlbarUtils.RESULT_SOURCE.TABS,
     54      payload: { url: "http://mozilla.org/tab/" },
     55    }),
     56    new UrlbarResult({
     57      type: UrlbarUtils.RESULT_TYPE.URL,
     58      source: UrlbarUtils.RESULT_SOURCE.BOOKMARKS,
     59      payload: { url: "http://mozilla.org/bookmark/" },
     60    }),
     61    new UrlbarResult({
     62      type: UrlbarUtils.RESULT_TYPE.URL,
     63      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
     64      payload: { url: "http://mozilla.org/history/" },
     65    }),
     66  ];
     67 
     68  let provider = registerBasicTestProvider(matches);
     69  let context = createContext(undefined, { providers: [provider.name] });
     70  let controller = UrlbarTestUtils.newMockController();
     71  /**
     72   * A test muxer.
     73   */
     74  class TestMuxer extends UrlbarMuxer {
     75    get name() {
     76      return "TestMuxer";
     77    }
     78    sort(queryContext, unsortedResults) {
     79      queryContext.results = [...unsortedResults].sort((a, b) => {
     80        if (b.source == UrlbarUtils.RESULT_SOURCE.TABS) {
     81          return -1;
     82        }
     83        if (b.source == UrlbarUtils.RESULT_SOURCE.BOOKMARKS) {
     84          return 1;
     85        }
     86        return a.source == UrlbarUtils.RESULT_SOURCE.BOOKMARKS ? -1 : 1;
     87      });
     88    }
     89  }
     90  let muxer = new TestMuxer();
     91 
     92  UrlbarProvidersManager.registerMuxer(muxer);
     93  context.muxer = "TestMuxer";
     94 
     95  info("Check results, the order should be: bookmark, history, tab");
     96  await UrlbarProvidersManager.startQuery(context, controller);
     97  Assert.deepEqual(context.results, [matches[1], matches[2], matches[0]]);
     98 
     99  // Sanity check, should not throw.
    100  UrlbarProvidersManager.unregisterMuxer(muxer);
    101  UrlbarProvidersManager.unregisterMuxer("TestMuxer"); // no-op.
    102 });
    103 
    104 add_task(async function test_preselectedHeuristic_singleProvider() {
    105  let matches = [
    106    new UrlbarResult({
    107      type: UrlbarUtils.RESULT_TYPE.URL,
    108      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    109      payload: { url: "http://mozilla.org/a" },
    110    }),
    111    new UrlbarResult({
    112      type: UrlbarUtils.RESULT_TYPE.URL,
    113      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    114      heuristic: true,
    115      payload: { url: "http://mozilla.org/b" },
    116    }),
    117    new UrlbarResult({
    118      type: UrlbarUtils.RESULT_TYPE.URL,
    119      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    120      payload: { url: "http://mozilla.org/c" },
    121    }),
    122  ];
    123 
    124  let provider = registerBasicTestProvider(matches);
    125  let context = createContext(undefined, {
    126    providers: [provider.name],
    127  });
    128  let controller = UrlbarTestUtils.newMockController();
    129 
    130  info("Check results, the order should be: b (heuristic), a, c");
    131  await UrlbarProvidersManager.startQuery(context, controller);
    132  Assert.deepEqual(context.results, [matches[1], matches[0], matches[2]]);
    133 });
    134 
    135 add_task(async function test_preselectedHeuristic_multiProviders() {
    136  let matches1 = [
    137    new UrlbarResult({
    138      type: UrlbarUtils.RESULT_TYPE.URL,
    139      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    140      payload: { url: "http://mozilla.org/a" },
    141    }),
    142    new UrlbarResult({
    143      type: UrlbarUtils.RESULT_TYPE.URL,
    144      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    145      payload: { url: "http://mozilla.org/b" },
    146    }),
    147    new UrlbarResult({
    148      type: UrlbarUtils.RESULT_TYPE.URL,
    149      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    150      payload: { url: "http://mozilla.org/c" },
    151    }),
    152  ];
    153 
    154  let matches2 = [
    155    new UrlbarResult({
    156      type: UrlbarUtils.RESULT_TYPE.URL,
    157      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    158      payload: { url: "http://mozilla.org/d" },
    159    }),
    160    new UrlbarResult({
    161      type: UrlbarUtils.RESULT_TYPE.URL,
    162      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    163      heuristic: true,
    164      payload: { url: "http://mozilla.org/e" },
    165    }),
    166    new UrlbarResult({
    167      type: UrlbarUtils.RESULT_TYPE.URL,
    168      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    169      payload: { url: "http://mozilla.org/f" },
    170    }),
    171  ];
    172 
    173  let provider1 = registerBasicTestProvider(matches1);
    174  let provider2 = registerBasicTestProvider(matches2);
    175 
    176  let context = createContext(undefined, {
    177    providers: [provider1.name, provider2.name],
    178  });
    179  let controller = UrlbarTestUtils.newMockController();
    180 
    181  info("Check results, the order should be: e (heuristic), a, b, c, d, f");
    182  await UrlbarProvidersManager.startQuery(context, controller);
    183  Assert.deepEqual(context.results, [
    184    matches2[1],
    185    ...matches1,
    186    matches2[0],
    187    matches2[2],
    188  ]);
    189 });
    190 
    191 add_task(async function test_suggestions() {
    192  Services.prefs.setIntPref("browser.urlbar.maxHistoricalSearchSuggestions", 1);
    193 
    194  let matches = [
    195    new UrlbarResult({
    196      type: UrlbarUtils.RESULT_TYPE.URL,
    197      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    198      payload: { url: "http://mozilla.org/a" },
    199    }),
    200    new UrlbarResult({
    201      type: UrlbarUtils.RESULT_TYPE.URL,
    202      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    203      payload: { url: "http://mozilla.org/b" },
    204    }),
    205    new UrlbarResult({
    206      type: UrlbarUtils.RESULT_TYPE.SEARCH,
    207      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    208      payload: {
    209        engine: "mozSearch",
    210        query: "moz",
    211        suggestion: "mozzarella",
    212        lowerCaseSuggestion: "mozzarella",
    213      },
    214    }),
    215    new UrlbarResult({
    216      type: UrlbarUtils.RESULT_TYPE.SEARCH,
    217      source: UrlbarUtils.RESULT_SOURCE.SEARCH,
    218      payload: {
    219        engine: "mozSearch",
    220        query: "moz",
    221        suggestion: "mozilla",
    222        lowerCaseSuggestion: "mozilla",
    223      },
    224    }),
    225    new UrlbarResult({
    226      type: UrlbarUtils.RESULT_TYPE.SEARCH,
    227      source: UrlbarUtils.RESULT_SOURCE.SEARCH,
    228      payload: {
    229        engine: "mozSearch",
    230        query: "moz",
    231        providesSearchMode: true,
    232        keyword: "@moz",
    233      },
    234    }),
    235    new UrlbarResult({
    236      type: UrlbarUtils.RESULT_TYPE.URL,
    237      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    238      payload: { url: "http://mozilla.org/c" },
    239    }),
    240  ];
    241 
    242  let provider = registerBasicTestProvider(matches);
    243 
    244  let context = createContext(undefined, {
    245    providers: [provider.name],
    246  });
    247  let controller = UrlbarTestUtils.newMockController();
    248 
    249  info("Check results, the order should be: mozzarella, moz, a, b, @moz, c");
    250  await UrlbarProvidersManager.startQuery(context, controller);
    251  Assert.deepEqual(context.results, [
    252    matches[2],
    253    matches[3],
    254    matches[0],
    255    matches[1],
    256    matches[4],
    257    matches[5],
    258  ]);
    259 
    260  Services.prefs.clearUserPref("browser.urlbar.maxHistoricalSearchSuggestions");
    261 });
    262 
    263 add_task(async function test_deduplicate_for_unitConversion() {
    264  const searchSuggestion = new UrlbarResult({
    265    type: UrlbarUtils.RESULT_TYPE.SEARCH,
    266    source: UrlbarUtils.RESULT_SOURCE.SEARCH,
    267    payload: {
    268      engine: "Google",
    269      query: "10cm to m",
    270      suggestion: "= 0.1 meters",
    271    },
    272  });
    273  const searchProvider = registerBasicTestProvider(
    274    [searchSuggestion],
    275    null,
    276    UrlbarUtils.PROVIDER_TYPE.PROFILE
    277  );
    278 
    279  const unitConversionSuggestion = new UrlbarResult({
    280    type: UrlbarUtils.RESULT_TYPE.DYNAMIC,
    281    source: UrlbarUtils.RESULT_SOURCE.OTHER_LOCAL,
    282    suggestedIndex: 1,
    283    payload: {
    284      dynamicType: "unitConversion",
    285      output: "0.1 m",
    286      input: "10cm to m",
    287    },
    288  });
    289 
    290  const unitConversion = registerBasicTestProvider(
    291    [unitConversionSuggestion],
    292    null,
    293    UrlbarUtils.PROVIDER_TYPE.PROFILE,
    294    "UrlbarProviderUnitConversion"
    295  );
    296 
    297  const context = createContext(undefined, {
    298    providers: [searchProvider.name, unitConversion.name],
    299  });
    300  const controller = UrlbarTestUtils.newMockController();
    301  await UrlbarProvidersManager.startQuery(context, controller);
    302  Assert.deepEqual(context.results, [unitConversionSuggestion]);
    303 });
    304 
    305 // These results are used in the badHeuristicGroups tests below.  The order of
    306 // the results in the array isn't important because they all get added at the
    307 // same time.  It's the resultGroups in each test that is important.
    308 const BAD_HEURISTIC_RESULTS = [
    309  // heuristic
    310  new UrlbarResult({
    311    type: UrlbarUtils.RESULT_TYPE.URL,
    312    source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    313    heuristic: true,
    314    payload: { url: "http://mozilla.org/heuristic-0" },
    315  }),
    316  // heuristic
    317  new UrlbarResult({
    318    type: UrlbarUtils.RESULT_TYPE.URL,
    319    source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    320    heuristic: true,
    321    payload: { url: "http://mozilla.org/heuristic-1" },
    322  }),
    323  // non-heuristic
    324  new UrlbarResult({
    325    type: UrlbarUtils.RESULT_TYPE.URL,
    326    source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    327    payload: { url: "http://mozilla.org/non-heuristic-0" },
    328  }),
    329  // non-heuristic
    330  new UrlbarResult({
    331    type: UrlbarUtils.RESULT_TYPE.URL,
    332    source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    333    payload: { url: "http://mozilla.org/non-heuristic-1" },
    334  }),
    335 ];
    336 
    337 const BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC = BAD_HEURISTIC_RESULTS[0];
    338 const BAD_HEURISTIC_RESULTS_GENERAL = [
    339  BAD_HEURISTIC_RESULTS[2],
    340  BAD_HEURISTIC_RESULTS[3],
    341 ];
    342 
    343 add_task(async function test_badHeuristicGroups_multiple_0() {
    344  await doBadHeuristicGroupsTest(
    345    [
    346      // 2 heuristics with child groups
    347      {
    348        maxResultCount: 2,
    349        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    350      },
    351      // infinite general
    352      {
    353        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    354      },
    355    ],
    356    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    357  );
    358 });
    359 
    360 add_task(async function test_badHeuristicGroups_multiple_1() {
    361  await doBadHeuristicGroupsTest(
    362    [
    363      // infinite heuristics with child groups
    364      {
    365        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    366      },
    367      // infinite general
    368      {
    369        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    370      },
    371    ],
    372    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    373  );
    374 });
    375 
    376 add_task(async function test_badHeuristicGroups_multiple_2() {
    377  await doBadHeuristicGroupsTest(
    378    [
    379      // 2 heuristics
    380      {
    381        maxResultCount: 2,
    382        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    383      },
    384      // infinite general
    385      {
    386        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    387      },
    388    ],
    389    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    390  );
    391 });
    392 
    393 add_task(async function test_badHeuristicGroups_multiple_3() {
    394  await doBadHeuristicGroupsTest(
    395    [
    396      // infinite heuristics
    397      {
    398        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    399      },
    400      // infinite general
    401      {
    402        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    403      },
    404    ],
    405    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    406  );
    407 });
    408 
    409 add_task(async function test_badHeuristicGroups_multiple_4() {
    410  await doBadHeuristicGroupsTest(
    411    [
    412      // 1 heuristic with child groups
    413      {
    414        maxResultCount: 1,
    415        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    416      },
    417      // infinite general
    418      {
    419        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    420      },
    421      // 1 heuristic with child groups
    422      {
    423        maxResultCount: 1,
    424        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    425      },
    426    ],
    427    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    428  );
    429 });
    430 
    431 add_task(async function test_badHeuristicGroups_multiple_5() {
    432  await doBadHeuristicGroupsTest(
    433    [
    434      // infinite heuristics with child groups
    435      {
    436        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    437      },
    438      // infinite general
    439      {
    440        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    441      },
    442      // infinite heuristics with child groups
    443      {
    444        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    445      },
    446    ],
    447    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    448  );
    449 });
    450 
    451 add_task(async function test_badHeuristicGroups_multiple_6() {
    452  await doBadHeuristicGroupsTest(
    453    [
    454      // 1 heuristic
    455      {
    456        maxResultCount: 1,
    457        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    458      },
    459      // infinite general
    460      {
    461        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    462      },
    463      // 1 heuristic
    464      {
    465        maxResultCount: 1,
    466        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    467      },
    468    ],
    469    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    470  );
    471 });
    472 
    473 add_task(async function test_badHeuristicGroups_multiple_7() {
    474  await doBadHeuristicGroupsTest(
    475    [
    476      // infinite heuristics
    477      {
    478        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    479      },
    480      // infinite general
    481      {
    482        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    483      },
    484      // infinite heuristics
    485      {
    486        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    487      },
    488    ],
    489    [BAD_HEURISTIC_RESULTS_FIRST_HEURISTIC, ...BAD_HEURISTIC_RESULTS_GENERAL]
    490  );
    491 });
    492 
    493 add_task(async function test_badHeuristicsGroups_notFirst_0() {
    494  await doBadHeuristicGroupsTest(
    495    [
    496      // infinite general first
    497      {
    498        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    499      },
    500      // 1 heuristic with child groups second
    501      {
    502        maxResultCount: 1,
    503        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    504      },
    505    ],
    506    [...BAD_HEURISTIC_RESULTS_GENERAL]
    507  );
    508 });
    509 
    510 add_task(async function test_badHeuristicsGroups_notFirst_1() {
    511  await doBadHeuristicGroupsTest(
    512    [
    513      // infinite general first
    514      {
    515        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    516      },
    517      // infinite heuristics with child groups second
    518      {
    519        children: [{ group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST }],
    520      },
    521    ],
    522    [...BAD_HEURISTIC_RESULTS_GENERAL]
    523  );
    524 });
    525 
    526 add_task(async function test_badHeuristicsGroups_notFirst_2() {
    527  await doBadHeuristicGroupsTest(
    528    [
    529      // infinite general first
    530      {
    531        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    532      },
    533      // 1 heuristic second
    534      {
    535        maxResultCount: 1,
    536        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    537      },
    538    ],
    539    [...BAD_HEURISTIC_RESULTS_GENERAL]
    540  );
    541 });
    542 
    543 add_task(async function test_badHeuristicsGroups_notFirst_3() {
    544  await doBadHeuristicGroupsTest(
    545    [
    546      // infinite general first
    547      {
    548        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    549      },
    550      // infinite heuristics second
    551      {
    552        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    553      },
    554    ],
    555    [...BAD_HEURISTIC_RESULTS_GENERAL]
    556  );
    557 });
    558 
    559 add_task(async function test_badHeuristicsGroups_notFirst_4() {
    560  await doBadHeuristicGroupsTest(
    561    [
    562      // 1 general first
    563      {
    564        maxResultCount: 1,
    565        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    566      },
    567      // infinite heuristics second
    568      {
    569        group: UrlbarUtils.RESULT_GROUP.HEURISTIC_TEST,
    570      },
    571      // infinite general third
    572      {
    573        group: UrlbarUtils.RESULT_GROUP.GENERAL,
    574      },
    575    ],
    576    [...BAD_HEURISTIC_RESULTS_GENERAL]
    577  );
    578 });
    579 
    580 /**
    581 * Sets the resultGroups pref, performs a search, and then checks the results.
    582 * Regardless of the groups, the muxer should include at most one heuristic in
    583 * its results and it should always be the first result.
    584 *
    585 * @param {Array} resultGroups
    586 *   The result groups.
    587 * @param {Array} expectedResults
    588 *   The expected results.
    589 */
    590 async function doBadHeuristicGroupsTest(resultGroups, expectedResults) {
    591  sandbox
    592    .stub(UrlbarPrefs, "getResultGroups")
    593    .returns({ children: resultGroups });
    594 
    595  let provider = registerBasicTestProvider(BAD_HEURISTIC_RESULTS);
    596  let context = createContext("foo", { providers: [provider.name] });
    597  let controller = UrlbarTestUtils.newMockController();
    598  await UrlbarProvidersManager.startQuery(context, controller);
    599  Assert.deepEqual(context.results, expectedResults);
    600 
    601  sandbox.restore();
    602 }
    603 
    604 // When `maxRichResults` is positive and taken up by suggested-index result(s),
    605 // both the heuristic and suggested-index results should be included because we
    606 // (a) make room for the heuristic and (b) assume all suggested-index results
    607 // should be included even if it means exceeding `maxRichResults`. The specified
    608 // `maxRichResults` span will be exceeded in this case.
    609 add_task(async function roomForHeuristic_suggestedIndex() {
    610  let results = [
    611    new UrlbarResult({
    612      type: UrlbarUtils.RESULT_TYPE.URL,
    613      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    614      heuristic: true,
    615      payload: { url: "http://example.com/heuristic" },
    616    }),
    617    new UrlbarResult({
    618      type: UrlbarUtils.RESULT_TYPE.URL,
    619      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    620      suggestedIndex: 1,
    621      payload: { url: "http://example.com/suggestedIndex" },
    622    }),
    623  ];
    624 
    625  UrlbarPrefs.set("maxRichResults", 1);
    626 
    627  let provider = registerBasicTestProvider(results);
    628  let context = createContext(undefined, { providers: [provider.name] });
    629  await check_results({
    630    context,
    631    matches: results,
    632  });
    633 
    634  UrlbarPrefs.clear("maxRichResults");
    635 });
    636 
    637 // When `maxRichResults` is positive but less than the heuristic's result span,
    638 // the heuristic should be included because we make room for it even if it means
    639 // exceeding `maxRichResults`. The specified `maxRichResults` span will be
    640 // exceeded in this case.
    641 add_task(async function roomForHeuristic_largeResultSpan() {
    642  let results = [
    643    new UrlbarResult({
    644      type: UrlbarUtils.RESULT_TYPE.URL,
    645      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    646      heuristic: true,
    647      resultSpan: 2,
    648      payload: { url: "http://example.com/heuristic" },
    649    }),
    650  ];
    651 
    652  UrlbarPrefs.set("maxRichResults", 1);
    653 
    654  let provider = registerBasicTestProvider(results);
    655  let context = createContext(undefined, { providers: [provider.name] });
    656  await check_results({
    657    context,
    658    matches: results,
    659  });
    660 
    661  UrlbarPrefs.clear("maxRichResults");
    662 });
    663 
    664 // When `maxRichResults` is zero and there are no suggested-index results, the
    665 // heuristic should not be included.
    666 add_task(async function roomForHeuristic_maxRichResultsZero() {
    667  let results = [
    668    new UrlbarResult({
    669      type: UrlbarUtils.RESULT_TYPE.URL,
    670      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    671      heuristic: true,
    672      payload: { url: "http://example.com/heuristic" },
    673    }),
    674  ];
    675 
    676  UrlbarPrefs.set("maxRichResults", 0);
    677 
    678  let provider = registerBasicTestProvider(results);
    679  let context = createContext(undefined, { providers: [provider.name] });
    680  await check_results({
    681    context,
    682    matches: [],
    683  });
    684 
    685  UrlbarPrefs.clear("maxRichResults");
    686 });
    687 
    688 // When `maxRichResults` is zero and suggested-index results are present,
    689 // neither the heuristic nor the suggested-index results should be included.
    690 add_task(async function roomForHeuristic_maxRichResultsZero_suggestedIndex() {
    691  let results = [
    692    new UrlbarResult({
    693      type: UrlbarUtils.RESULT_TYPE.URL,
    694      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    695      heuristic: true,
    696      payload: { url: "http://example.com/heuristic" },
    697    }),
    698    new UrlbarResult({
    699      type: UrlbarUtils.RESULT_TYPE.URL,
    700      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    701      suggestedIndex: 1,
    702      payload: { url: "http://example.com/suggestedIndex" },
    703    }),
    704  ];
    705 
    706  UrlbarPrefs.set("maxRichResults", 0);
    707 
    708  let provider = registerBasicTestProvider(results);
    709  let context = createContext(undefined, { providers: [provider.name] });
    710  await check_results({
    711    context,
    712    matches: [],
    713  });
    714 
    715  UrlbarPrefs.clear("maxRichResults");
    716 });
    717 
    718 add_task(async function test_orderBy() {
    719  // The GENERAL groups has an orderBy property, so let's just add to history.
    720  let results1 = [
    721    new UrlbarResult({
    722      type: UrlbarUtils.RESULT_TYPE.URL,
    723      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    724      payload: { url: "http://example.com/test1", frecency: 10 },
    725    }),
    726    new UrlbarResult({
    727      type: UrlbarUtils.RESULT_TYPE.URL,
    728      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    729      payload: { url: "http://example.com/test2", frecency: 1000 },
    730    }),
    731  ];
    732  let provider1 = registerBasicTestProvider(results1);
    733  let results2 = [
    734    new UrlbarResult({
    735      type: UrlbarUtils.RESULT_TYPE.URL,
    736      source: UrlbarUtils.RESULT_SOURCE.HISTORY,
    737      payload: { url: "http://example.com/test3", frecency: 100 },
    738    }),
    739  ];
    740  let provider2 = registerBasicTestProvider(results2);
    741 
    742  let context = createContext(undefined, {
    743    providers: [provider1.name, provider2.name],
    744  });
    745  await check_results({
    746    context,
    747    matches: [
    748      results1[1], // 1000
    749      results2[0], // 100
    750      results1[0], // 10
    751    ],
    752  });
    753 });