summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_providersManager_maxResults.js
blob: b30b9352cd71893ba44358c5d8ca42736ebbf53b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_maxResults() {
  const MATCHES_LENGTH = 20;
  let matches = [];
  for (let i = 0; i < MATCHES_LENGTH; i++) {
    matches.push(
      new UrlbarResult(
        UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
        UrlbarUtils.RESULT_SOURCE.TABS,
        { url: `http://mozilla.org/foo/${i}` }
      )
    );
  }
  let provider = registerBasicTestProvider(matches);
  let context = createContext(undefined, { providers: [provider.name] });
  let controller = UrlbarTestUtils.newMockController();

  async function test_count(count) {
    let promise = promiseControllerNotification(controller, "onQueryFinished");
    context.maxResults = count;
    await controller.startQuery(context);
    await promise;
    Assert.equal(
      context.results.length,
      Math.min(MATCHES_LENGTH, count),
      "Check count"
    );
    Assert.deepEqual(context.results, matches.slice(0, count), "Check results");
  }
  await test_count(10);
  await test_count(1);
  await test_count(30);
});