summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance-new/test/browser/browser_aboutprofiling-features-disabled.js
blob: ce91f421678f260ded5a291ea42e43c485ad9811 (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
/* 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 that features that are disabled on the platform are disabled in about:profiling."
  );

  const supportedFeatures = Services.profiler.GetFeatures();
  const allFeatures = Services.profiler.GetAllFeatures();
  const unsupportedFeatures = allFeatures.filter(
    feature => !supportedFeatures.includes(feature)
  );

  if (unsupportedFeatures.length === 0) {
    ok(true, "This platform has no unsupported features. Skip this test.");
    return;
  }

  await withAboutProfiling(async document => {
    {
      info("Find and click a supported feature to toggle it.");
      const [firstSupportedFeature] = supportedFeatures;
      const checkbox = getFeatureCheckbox(document, firstSupportedFeature);
      const initialValue = checkbox.checked;
      info("Click the supported checkbox.");
      checkbox.click();
      is(
        initialValue,
        !checkbox.checked,
        "A supported feature can be toggled."
      );
      checkbox.click();
    }

    {
      info("Find and click an unsupported feature, it should be disabled.");
      const [firstUnsupportedFeature] = unsupportedFeatures;
      const checkbox = getFeatureCheckbox(document, firstUnsupportedFeature);
      is(checkbox.checked, false, "The unsupported feature is not checked.");

      info("Click the unsupported checkbox.");
      checkbox.click();
      is(checkbox.checked, false, "After clicking it, it's still not checked.");
    }
  });
});

/**
 * @param {HTMLDocument} document
 * @param {string} feature
 * @return {HTMLElement}
 */
function getFeatureCheckbox(document, feature) {
  const element = document.querySelector(`input[value="${feature}"]`);
  if (!element) {
    throw new Error("Could not find the checkbox for the feature: " + feature);
  }
  return element;
}