summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_settings_obsolete.js
blob: 459a9d8aa1d6e8b63907aad55289e9c5c2f0d44b (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
75
76
77
78
79
80
81
82
83
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/*
 * Test removing obsolete engine types on upgrade of settings.
 */

"use strict";

async function loadSettingsFile(settingsFile, name) {
  let settings = await readJSONFile(do_get_file(settingsFile));

  settings.metaData.current = name;
  settings.metaData.hash = SearchUtils.getVerificationHash(name);

  await promiseSaveSettingsData(settings);
}

/**
 * Start the search service and confirm the engine properties match the expected values.
 *
 * @param {string} settingsFile
 *   The path to the settings file to use.
 * @param {string} engineName
 *   The engine name that should be default and is being removed.
 */
async function checkLoadSettingProperties(settingsFile, engineName) {
  await loadSettingsFile(settingsFile, engineName);

  const settingsFileWritten = promiseAfterSettings();
  let ss = new SearchService();
  let result = await ss.init();

  Assert.ok(
    Components.isSuccessCode(result),
    "Should have successfully initialized the search service"
  );

  await settingsFileWritten;

  let engines = await ss.getEngines();

  Assert.deepEqual(
    engines.map(e => e.name),
    ["engine1", "engine2"],
    "Should have only loaded the app-provided engines"
  );

  Assert.equal(
    (await Services.search.getDefault()).name,
    "engine1",
    "Should have used the configured default engine"
  );

  removeSettingsFile();
  ss._removeObservers();
}

/**
 * Test reading from search.json.mozlz4
 */
add_task(async function setup() {
  await SearchTestUtils.useTestEngines("data1");
  await AddonTestUtils.promiseStartupManager();
});

add_task(async function test_obsolete_distribution_engine() {
  await checkLoadSettingProperties(
    "data/search-obsolete-distribution.json",
    "Distribution"
  );
});

add_task(async function test_obsolete_langpack_engine() {
  await checkLoadSettingProperties(
    "data/search-obsolete-langpack.json",
    "Langpack"
  );
});

add_task(async function test_obsolete_app_engine() {
  await checkLoadSettingProperties("data/search-obsolete-app.json", "App");
});