summaryrefslogtreecommitdiffstats
path: root/toolkit/modules/tests/xpcshell/test_firstStartup.js
blob: a5fce5b563bb597dc3011f90e6e91df97145423a (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
"use strict";

const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);
const { FirstStartup } = ChromeUtils.import(
  "resource://gre/modules/FirstStartup.jsm"
);
const { updateAppInfo } = ChromeUtils.import(
  "resource://testing-common/AppInfo.jsm"
);

const PREF_TIMEOUT = "first-startup.timeout";
const PROBE_NAME = "firstStartup.statusCode";

add_task(async function test_success() {
  updateAppInfo();
  FirstStartup.init();
  if (AppConstants.MOZ_NORMANDY) {
    equal(FirstStartup.state, FirstStartup.SUCCESS);
  } else {
    equal(FirstStartup.state, FirstStartup.UNSUPPORTED);
  }

  const scalars = Services.telemetry.getSnapshotForScalars("main", false)
    .parent;
  ok(PROBE_NAME in scalars);

  if (AppConstants.MOZ_NORMANDY) {
    equal(scalars[PROBE_NAME], FirstStartup.SUCCESS);
  } else {
    equal(scalars[PROBE_NAME], FirstStartup.UNSUPPORTED);
  }
});

add_task(async function test_timeout() {
  updateAppInfo();
  Services.prefs.setIntPref(PREF_TIMEOUT, 0);
  FirstStartup.init();

  if (AppConstants.MOZ_NORMANDY) {
    equal(FirstStartup.state, FirstStartup.TIMED_OUT);
  } else {
    equal(FirstStartup.state, FirstStartup.UNSUPPORTED);
  }

  const scalars = Services.telemetry.getSnapshotForScalars("main", false)
    .parent;
  ok(PROBE_NAME in scalars);
  if (AppConstants.MOZ_NORMANDY) {
    equal(scalars[PROBE_NAME], FirstStartup.TIMED_OUT);
  } else {
    equal(scalars[PROBE_NAME], FirstStartup.UNSUPPORTED);
  }
});