summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/rules/test/browser_rules_add-rule-and-remove-style-node.js
blob: 1505f70c3230445db3f086dcb4678d1e19f6be6b (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
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that bug 1736412 is fixed
// We press "add new rule", then we remove the style node
// We then try to press "add new rule again"

const TEST_URI = '<div id="testid">Test Node</div>';

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

  await selectNode("#testid", inspector);
  await addNewRule(inspector, view);
  await testNewRule(view, 1);
  await testRemoveStyleNode();
  await addNewRule(inspector, view);
  await testNewRule(view, 1);
});

function testNewRule(view) {
  const ruleEditor = getRuleViewRuleEditor(view, 1);
  const editor = ruleEditor.selectorText.ownerDocument.activeElement;
  is(editor.value, "#testid", "Selector editor value is as expected");
  info("Escaping from the selector field the change");
  EventUtils.synthesizeKey("KEY_Escape");
}

async function testRemoveStyleNode() {
  info("Removing the style node from the dom");
  const nbStyleSheets = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [],
    () => {
      content.document.styleSheets[0].ownerNode.remove();
      return content.document.styleSheets.length;
    }
  );
  is(nbStyleSheets, 0, "Style node has been removed");
}