summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_add-rule-pseudo-class.js
blob: 2963da90348db2a89701942fee80cb6537e1156f (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests adding a rule with pseudo class locks on.

const TEST_URI = "<p id='element'>Test element</p>";

const EXPECTED_SELECTOR = "#element";
const TEST_DATA = [
  [],
  [":hover"],
  [":hover", ":active"],
  [":hover", ":active", ":focus"],
  [":active"],
  [":active", ":focus"],
  [":focus"],
  [":focus-within"],
  [":hover", ":focus-within"],
  [":hover", ":active", ":focus-within"],
];

add_task(async function () {
  await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI));
  const { inspector, view } = await openRuleView();
  await selectNode("#element", inspector);

  for (const data of TEST_DATA) {
    await runTestData(inspector, view, data);
  }
});

async function runTestData(inspector, view, pseudoClasses) {
  await setPseudoLocks(inspector, view, pseudoClasses);

  const expected = EXPECTED_SELECTOR + pseudoClasses.join("");
  await addNewRuleAndDismissEditor(inspector, view, expected, 1);

  await resetPseudoLocks(inspector, view);
}

async function setPseudoLocks(inspector, view, pseudoClasses) {
  if (!pseudoClasses.length) {
    return;
  }

  for (const pseudoClass of pseudoClasses) {
    const checkbox = getPseudoClassCheckbox(view, pseudoClass);
    if (checkbox) {
      checkbox.click();
    }
    await inspector.once("rule-view-refreshed");
  }
}

async function resetPseudoLocks(inspector, view) {
  for (const checkbox of view.pseudoClassCheckboxes) {
    if (checkbox.checked) {
      checkbox.click();
      await inspector.once("rule-view-refreshed");
    }
  }
}