summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/test/xpcshell/test_popup_initial_state.js
blob: 821d9af2c2320576c8519d92ad6904a3a5c57d93 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";

/**
 * Tests the initial state of the background script for the popup.
 */

function setupBackgroundJsm() {
  return ChromeUtils.import(
    "resource://devtools/client/performance-new/shared/background.jsm.js"
  );
}

add_task(function test() {
  info("Test that we get the default preference values from the browser.");
  const { getRecordingSettings } = setupBackgroundJsm();

  const preferences = getRecordingSettings(
    "aboutprofiling",
    Services.profiler.GetFeatures()
  );

  Assert.notEqual(
    preferences.entries,
    undefined,
    "The initial state has the default entries."
  );
  Assert.notEqual(
    preferences.interval,
    undefined,
    "The initial state has the default interval."
  );
  Assert.notEqual(
    preferences.features,
    undefined,
    "The initial state has the default features."
  );
  Assert.equal(
    preferences.features.includes("js"),
    true,
    "The js feature is initialized to the default."
  );
  Assert.notEqual(
    preferences.threads,
    undefined,
    "The initial state has the default threads."
  );
  Assert.equal(
    preferences.threads.includes("GeckoMain"),
    true,
    "The GeckoMain thread is initialized to the default."
  );
  Assert.notEqual(
    preferences.objdirs,
    undefined,
    "The initial state has the default objdirs."
  );
  Assert.notEqual(
    preferences.duration,
    undefined,
    "The duration is initialized to the duration."
  );
});

add_task(function test() {
  info(
    "Test that the state and features are properly validated. This ensures that as " +
      "we add and remove features, the stored preferences do not cause the Gecko " +
      "Profiler interface to crash with invalid values."
  );
  const { getRecordingSettings, setRecordingSettings, changePreset } =
    setupBackgroundJsm();

  const supportedFeatures = Services.profiler.GetFeatures();

  changePreset("aboutprofiling", "custom", supportedFeatures);

  Assert.ok(
    getRecordingSettings("aboutprofiling", supportedFeatures).features.includes(
      "js"
    ),
    "The js preference is present initially."
  );

  const settings = getRecordingSettings("aboutprofiling", supportedFeatures);
  settings.features = settings.features.filter(feature => feature !== "js");
  settings.features.push("UNKNOWN_FEATURE_FOR_TESTS");
  setRecordingSettings("aboutprofiling", settings);

  Assert.ok(
    !getRecordingSettings(
      "aboutprofiling",
      supportedFeatures
    ).features.includes("UNKNOWN_FEATURE_FOR_TESTS"),
    "The unknown feature is removed."
  );
  Assert.ok(
    !getRecordingSettings(
      "aboutprofiling",
      supportedFeatures
    ).features.includes("js"),
    "The js preference is still flipped from the default."
  );
});