summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_transition_rule.js
blob: 7fd1c0bd1bb070f340851a24b7ccd95ef309f705 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html";

const NEW_RULE = "body { background-color: purple; }";

add_task(async function () {
  const { ui } = await openStyleEditorForURL(TESTCASE_URI);

  is(ui.editors.length, 2, "correct number of editors");

  const editor = ui.editors[0];
  await openEditor(editor);

  // Set text twice in a row
  const styleChanges = listenForStyleChange(editor);

  editor.sourceEditor.setText(NEW_RULE);
  editor.sourceEditor.setText(NEW_RULE + " ");

  await styleChanges;

  const rules = await SpecialPowers.spawn(
    gBrowser.selectedBrowser,
    [0],
    async function (index) {
      const sheet = content.document.styleSheets[index];
      return [...sheet.cssRules].map(rule => rule.cssText);
    }
  );

  // Test that we removed the transition rule, but kept the rule we added
  is(rules.length, 1, "only one rule in stylesheet");
  is(rules[0], NEW_RULE, "stylesheet only contains rule we added");
});

/* Helpers */

function openEditor(editor) {
  const link = editor.summary.querySelector(".stylesheet-name");
  link.click();

  return editor.getSourceEditor();
}

function listenForStyleChange(editor) {
  return editor.once("style-applied");
}