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

"use strict";

const lazy = {};

const { promiseShutdownManager, promiseStartupManager } = AddonTestUtils;

ChromeUtils.defineESModuleGetters(lazy, {
  ExtensionTestUtils:
    "resource://testing-common/ExtensionXPCShellUtils.sys.mjs",
});

add_setup(async function () {
  let server = useHttpServer();
  server.registerContentType("sjs", "sjs");
  await SearchTestUtils.useTestEngines("test-extensions");
  await promiseStartupManager();

  registerCleanupFunction(async () => {
    await promiseShutdownManager();
  });
});

add_task(async function test_install_duplicate_engine_startup() {
  let name = "Plain";
  let id = "plain@tests.mozilla.org";
  consoleAllowList.push(
    `#installExtensionEngine failed for ${id}`,
    `An engine called ${name} already exists`
  );
  // Do not use SearchTestUtils.installSearchExtension, as we need to manually
  // start the search service after installing the extension.
  let extensionInfo = {
    useAddonManager: "permanent",
    files: {},
    manifest: SearchTestUtils.createEngineManifest({
      name,
      search_url: "https://example.com/plain",
    }),
  };

  let extension = lazy.ExtensionTestUtils.loadExtension(extensionInfo);
  await extension.startup();

  await Services.search.init();

  await AddonTestUtils.waitForSearchProviderStartup(extension);
  let engine = await Services.search.getEngineByName(name);
  let submission = engine.getSubmission("foo");
  Assert.equal(
    submission.uri.spec,
    "https://duckduckgo.com/?q=foo&t=ffsb",
    "Should have not changed the app provided engine."
  );

  await extension.unload();
});