summaryrefslogtreecommitdiffstats
path: root/services/sync/tests/unit/test_service_startup.js
blob: 177398d24f990b88c672220ca8c13abebe6f7d3f (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

const { AppConstants } = ChromeUtils.importESModule(
  "resource://gre/modules/AppConstants.sys.mjs"
);

Svc.Prefs.set("registerEngines", "Tab,Bookmarks,Form,History");

add_task(async function run_test() {
  validate_all_future_pings();
  _("When imported, Service.onStartup is called");

  let xps = Cc["@mozilla.org/weave/service;1"].getService(Ci.nsISupports)
    .wrappedJSObject;
  Assert.ok(!xps.enabled);

  // Test fixtures
  let { Service } = ChromeUtils.import("resource://services-sync/service.js");
  Services.prefs.setStringPref("services.sync.username", "johndoe");
  Assert.ok(xps.enabled);

  _("Service is enabled.");
  Assert.equal(Service.enabled, true);

  _("Observers are notified of startup");
  Assert.ok(!Service.status.ready);
  Assert.ok(!xps.ready);

  await promiseOneObserver("weave:service:ready");

  Assert.ok(Service.status.ready);
  Assert.ok(xps.ready);

  _("Engines are registered.");
  let engines = Service.engineManager.getAll();
  if (AppConstants.MOZ_APP_NAME == "thunderbird") {
    // Thunderbird's engines are registered later, so they're not here yet.
    Assert.deepEqual(
      engines.map(engine => engine.name),
      []
    );
  } else {
    Assert.deepEqual(
      engines.map(engine => engine.name),
      ["tabs", "bookmarks", "forms", "history"]
    );
  }

  // Clean up.
  Svc.Prefs.resetBranch("");

  do_test_finished();
});