summaryrefslogtreecommitdiffstats
path: root/toolkit/components/search/tests/xpcshell/test_require_engines_in_cache.js
blob: 299121c4f4bfd401c6d0dba46a1b1e907da13c40 (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/ */

function run_test() {
  removeMetadata();
  removeCacheFile();

  do_load_manifest("data/chrome.manifest");

  configureToLoadJarEngines();
  do_check_false(Services.search.isInitialized);

  run_next_test();
}

add_task(function* ignore_cache_files_without_engines() {
  let commitPromise = promiseAfterCache()
  yield asyncInit();

  let engineCount = Services.search.getEngines().length;
  do_check_eq(engineCount, 1);

  // Wait for the file to be saved to disk, so that we can mess with it.
  yield commitPromise;

  // Remove all engines from the cache file.
  let cache = yield promiseCacheData();
  cache.engines = [];
  yield promiseSaveCacheData(cache);

  // Check that after an async re-initialization, we still have the same engine count.
  commitPromise = promiseAfterCache()
  yield asyncReInit();
  do_check_eq(engineCount, Services.search.getEngines().length);
  yield commitPromise;

  // Check that after a sync re-initialization, we still have the same engine count.
  yield promiseSaveCacheData(cache);
  let unInitPromise = waitForSearchNotification("uninit-complete");
  let reInitPromise = asyncReInit();
  yield unInitPromise;
  do_check_false(Services.search.isInitialized);
  // Synchronously check the engine count; will force a sync init.
  do_check_eq(engineCount, Services.search.getEngines().length);
  do_check_true(Services.search.isInitialized);
  yield reInitPromise;
});

add_task(function* skip_writing_cache_without_engines() {
  let unInitPromise = waitForSearchNotification("uninit-complete");
  let reInitPromise = asyncReInit();
  yield unInitPromise;

  // Configure so that no engines will be found.
  do_check_true(removeCacheFile());
  let resProt = Services.io.getProtocolHandler("resource")
                        .QueryInterface(Ci.nsIResProtocolHandler);
  resProt.setSubstitution("search-plugins",
                          Services.io.newURI("about:blank", null, null));

  // Let the async-reInit happen.
  yield reInitPromise;
  do_check_eq(0, Services.search.getEngines().length);

  // Trigger yet another re-init, to flush of any pending cache writing task.
  unInitPromise = waitForSearchNotification("uninit-complete");
  reInitPromise = asyncReInit();
  yield unInitPromise;

  // Now check that a cache file doesn't exist.
  do_check_false(removeCacheFile());

  yield reInitPromise;
});