summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_searchSuggest_extraParams.js
blob: 8ecf4b02f36eed172576afdb282453bc7df081a0 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

const TEST_CONFIG = [
  {
    webExtension: {
      id: "get@search.mozilla.org",
      name: "Get Engine",
      search_url: "https://example.com",
      search_url_get_params: "webExtension=1&search={searchTerms}",
      suggest_url: "https://example.com",
      suggest_url_get_params: "webExtension=1&suggest={searchTerms}",
    },
    appliesTo: [{ included: { everywhere: true } }],
    suggestExtraParams: [
      {
        name: "custom_param",
        pref: "test_pref_param",
        condition: "pref",
      },
    ],
  },
];

add_setup(async function () {
  await SearchTestUtils.useTestEngines("method-extensions", null, TEST_CONFIG);
  await AddonTestUtils.promiseStartupManager();
  await Services.search.init();
});

add_task(async function test_custom_suggest_param() {
  let engine = Services.search.getEngineByName("Get Engine");
  Assert.notEqual(engine, null, "Should have found an engine");

  let submissionSuggest = engine.getSubmission(
    "bar",
    SearchUtils.URL_TYPE.SUGGEST_JSON
  );
  Assert.equal(
    submissionSuggest.uri.spec,
    "https://example.com/?webExtension=1&suggest=bar",
    "Suggest URLs should match"
  );

  let defaultBranch = Services.prefs.getDefaultBranch("browser.search.");
  defaultBranch.setCharPref("param.test_pref_param", "good");

  let nextSubmissionSuggest = engine.getSubmission(
    "bar",
    SearchUtils.URL_TYPE.SUGGEST_JSON
  );
  Assert.equal(
    nextSubmissionSuggest.uri.spec,
    "https://example.com/?custom_param=good&webExtension=1&suggest=bar",
    "Suggest URLs should include custom param"
  );
});