summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/test/browser/browser_aboutprofiling-threads-behavior.js
blob: c2512dcc055bd535480e96c4a9426572c4180130 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/* 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";

add_task(async function test() {
  info(
    "Test the behavior of thread toggling and the text summary works as expected."
  );

  // This test assumes that the Web Developer preset is set by default, which is
  // not the case on Nightly and custom builds.
  BackgroundJSM.changePreset(
    "aboutprofiling",
    "web-developer",
    Services.profiler.GetFeatures()
  );

  await withAboutProfiling(async document => {
    const threadTextEl = await getNearestInputFromText(
      document,
      "Add custom threads by name:"
    );

    is(
      getActiveConfiguration().threads.join(","),
      "GeckoMain,Compositor,Renderer,DOM Worker",
      "The threads starts out with the default"
    );
    is(
      threadTextEl.value,
      "GeckoMain,Compositor,Renderer,DOM Worker",
      "The threads starts out with the default in the thread text input"
    );

    await clickThreadCheckbox(document, "Compositor", "Toggle off");

    is(
      getActiveConfiguration().threads.join(","),
      "GeckoMain,Renderer,DOM Worker",
      "The threads have been updated"
    );
    is(
      threadTextEl.value,
      "GeckoMain,Renderer,DOM Worker",
      "The threads have been updated in the thread text input"
    );

    await clickThreadCheckbox(document, "DNS Resolver", "Toggle on");

    is(
      getActiveConfiguration().threads.join(","),
      "GeckoMain,Renderer,DOM Worker,DNS Resolver",
      "Another thread was added"
    );
    is(
      threadTextEl.value,
      "GeckoMain,Renderer,DOM Worker,DNS Resolver",
      "Another thread was in the thread text input"
    );

    const styleThreadCheckbox = await getNearestInputFromText(
      document,
      "StyleThread"
    );
    ok(!styleThreadCheckbox.checked, "The style thread is not checked.");

    // Set the input box directly
    setReactFriendlyInputValue(
      threadTextEl,
      "GeckoMain,DOM Worker,DNS Resolver,StyleThread"
    );
    threadTextEl.dispatchEvent(new Event("blur", { bubbles: true }));

    ok(styleThreadCheckbox.checked, "The style thread is now checked.");
    is(
      getActiveConfiguration().threads.join(","),
      "GeckoMain,DOM Worker,DNS Resolver,StyleThread",
      "Another thread was added"
    );
    is(
      threadTextEl.value,
      "GeckoMain,DOM Worker,DNS Resolver,StyleThread",
      "Another thread was in the thread text input"
    );

    // The all threads checkbox has nested text elements, so it's not easy to select
    // by its label value. Select it by ID.
    const allThreadsCheckbox = document.querySelector(
      "#perf-settings-thread-checkbox-all-threads"
    );
    info(`Turning on "All Threads" by clicking it."`);
    allThreadsCheckbox.click();

    is(
      getActiveConfiguration().threads.join(","),
      "GeckoMain,DOM Worker,DNS Resolver,StyleThread,*",
      "Asterisk was added"
    );
    is(
      threadTextEl.value,
      "GeckoMain,DOM Worker,DNS Resolver,StyleThread,*",
      "Asterisk was in the thread text input"
    );

    is(styleThreadCheckbox.disabled, true, "The Style Thread is now disabled.");

    // Remove the asterisk
    setReactFriendlyInputValue(
      threadTextEl,
      "GeckoMain,DOM Worker,DNS Resolver,StyleThread"
    );
    threadTextEl.dispatchEvent(new Event("blur", { bubbles: true }));

    ok(!allThreadsCheckbox.checked, "The all threads checkbox is not checked.");
    is(styleThreadCheckbox.disabled, false, "The Style Thread is now enabled.");
  });
});

/**
 * @param {Document} document
 * @param {string} threadName
 * @param {string} action - This is the intent of the click.
 */
async function clickThreadCheckbox(document, threadName, action) {
  info(`${action} "${threadName}" by clicking it.`);
  const checkbox = await getNearestInputFromText(document, threadName);
  checkbox.click();
}