File: test_setting_group.html

package info (click to toggle)
firefox 141.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,550,588 kB
  • sloc: cpp: 7,426,506; javascript: 6,367,238; ansic: 3,707,351; python: 1,369,002; xml: 623,983; asm: 426,918; java: 184,324; sh: 64,488; makefile: 19,203; objc: 13,059; perl: 12,955; yacc: 4,583; cs: 3,846; pascal: 3,352; lex: 1,720; ruby: 1,071; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (125 lines) | stat: -rw-r--r-- 4,148 bytes parent folder | download | duplicates (3)
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
<!doctype html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>setting-group Tests</title>
    <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <link
      rel="stylesheet"
      href="chrome://mochikit/content/tests/SimpleTest/test.css"
    />
    <link rel="stylesheet" href="chrome://global/skin/global.css" />
    <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
    <script src="../../../../../toolkit/content/tests/widgets/lit-test-helpers.js"></script>
    <script
      type="module"
      src="chrome://browser/content/preferences/widgets/setting-group.mjs"
    ></script>
    <script
      type="module"
      src="chrome://browser/content/preferences/widgets/setting-control.mjs"
    ></script>
    <script
      type="module"
      src="chrome://global/content/elements/moz-support-link.mjs"
    ></script>
    <script
      type="application/javascript"
      src="chrome://global/content/preferencesBindings.js"
    ></script>
    <script>
      /* import-globals-from /toolkit/content/preferencesBindings.js */
      let html, testHelpers;

      const LABEL_L10N_ID = "browsing-use-autoscroll";
      const GROUP_L10N_ID = "pane-experimental-reset";

      function renderTemplate(config) {
        return testHelpers.renderTemplate(html`
          <setting-group
            .config=${config}
            .getSetting=${(...args) => Preferences.getSetting(...args)}
          ></setting-group>
        `);
      }

      function waitForSettingChange(setting) {
        return new Promise(resolve => {
          setting.on("change", function handler() {
            setting.off("change", handler);
            resolve();
          });
        });
      }

      add_setup(async function setup() {
        testHelpers = new InputTestHelpers();
        ({ html } = await testHelpers.setupLit());
        testHelpers.setupTests({
          templateFn: () => html`<setting-group></setting-group>`,
        });
        MozXULElement.insertFTLIfNeeded("branding/brand.ftl");
        MozXULElement.insertFTLIfNeeded("browser/preferences/preferences.ftl");
      });

      add_task(async function testSettingGroupSimple() {
        const PREF_ONE = "test.settings-group.itemone";
        const SETTING_ONE = "setting-item-one";
        const PREF_TWO = "test.settings-group.itemtwo";
        const SETTING_TWO = "setting-item-two";
        await SpecialPowers.pushPrefEnv({
          set: [
            [PREF_ONE, true],
            [PREF_TWO, false],
            ["settings.revamp.design", true],
          ],
        });
        Preferences.addAll([
          { id: PREF_ONE, type: "bool" },
          { id: PREF_TWO, type: "bool" },
        ]);
        Preferences.addSetting({
          id: SETTING_ONE,
          pref: PREF_ONE,
        });
        Preferences.addSetting({
          id: SETTING_TWO,
          pref: PREF_TWO,
        });
        let config = {
          l10nId: GROUP_L10N_ID,
          items: [
            { l10nId: LABEL_L10N_ID, id: SETTING_ONE },
            { l10nId: LABEL_L10N_ID, id: SETTING_TWO },
          ],
        };

        let result = await renderTemplate(config);
        let group = result.querySelector("setting-group");
        ok(group, "setting-group is created");
        ok(group.config, "it got a config");
        let fieldset = group.children[0];
        is(fieldset.localName, "moz-fieldset", "First child is a fieldset");
        is(
          fieldset.dataset.l10nId,
          GROUP_L10N_ID,
          "Fieldset has the group label"
        );
        let [item1, item2] = fieldset.children;
        is(item1.localName, "setting-control", "First setting-control");
        is(item1.config.id, SETTING_ONE, "First setting-control id is correct");
        is(item2.localName, "setting-control", "Second setting-control");
        is(
          item2.config.id,
          SETTING_TWO,
          "Second setting-control id is correct"
        );
      });
    </script>
  </head>
  <body>
    <p id="display"></p>
    <div id="content" style="display: none"></div>
    <pre id="test"></pre>
  </body>
</html>