summaryrefslogtreecommitdiffstats
path: root/browser/components/urlbar/tests/unit/test_providersManager.js
blob: 8446ed0675855ea79b87c940df0fc0eadc6ef102 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_providers() {
  Assert.throws(
    () => UrlbarProvidersManager.registerProvider(),
    /invalid provider/,
    "Should throw with no arguments"
  );
  Assert.throws(
    () => UrlbarProvidersManager.registerProvider({}),
    /invalid provider/,
    "Should throw with empty object"
  );
  Assert.throws(
    () =>
      UrlbarProvidersManager.registerProvider({
        name: "",
      }),
    /invalid provider/,
    "Should throw with empty name"
  );
  Assert.throws(
    () =>
      UrlbarProvidersManager.registerProvider({
        name: "test",
        startQuery: "no",
      }),
    /invalid provider/,
    "Should throw with invalid startQuery"
  );
  Assert.throws(
    () =>
      UrlbarProvidersManager.registerProvider({
        name: "test",
        startQuery: () => {},
        cancelQuery: "no",
      }),
    /invalid provider/,
    "Should throw with invalid cancelQuery"
  );

  let match = new UrlbarResult(
    UrlbarUtils.RESULT_TYPE.TAB_SWITCH,
    UrlbarUtils.RESULT_SOURCE.TABS,
    { url: "http://mozilla.org/foo/" }
  );

  let provider = registerBasicTestProvider([match]);
  let context = createContext(undefined, { providers: [provider.name] });
  let controller = UrlbarTestUtils.newMockController();
  let resultsPromise = promiseControllerNotification(
    controller,
    "onQueryResults"
  );

  await UrlbarProvidersManager.startQuery(context, controller);
  // Sanity check that this doesn't throw. It should be a no-op since we await
  // for startQuery.
  UrlbarProvidersManager.cancelQuery(context);

  let params = await resultsPromise;
  Assert.deepEqual(params[0].results, [match]);
});

add_task(async function test_criticalSection() {
  // Just a sanity check, this shouldn't throw.
  await UrlbarProvidersManager.runInCriticalSection(async () => {
    let db = await PlacesUtils.promiseLargeCacheDBConnection();
    await db.execute(`PRAGMA page_cache`);
  });
});