summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_enabled.js
blob: 993225de00ca46511dd6a0b62564e0ee9ddb5638 (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
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test that style sheets can be disabled and enabled.

// https rather than chrome to improve coverage
const TESTCASE_URI = TEST_BASE_HTTPS + "simple.html";

add_task(function* () {
  let { panel, ui } = yield openStyleEditorForURL(TESTCASE_URI);
  let editor = yield ui.editors[0].getSourceEditor();

  let summary = editor.summary;
  let enabledToggle = summary.querySelector(".stylesheet-enabled");
  ok(enabledToggle, "enabled toggle button exists");

  is(editor.styleSheet.disabled, false,
     "first stylesheet is initially enabled");

  is(summary.classList.contains("disabled"), false,
     "first stylesheet is initially enabled, UI does not have DISABLED class");

  info("Disabling the first stylesheet.");
  yield toggleEnabled(editor, enabledToggle, panel.panelWindow);

  is(editor.styleSheet.disabled, true, "first stylesheet is now disabled");
  is(summary.classList.contains("disabled"), true,
     "first stylesheet is now disabled, UI has DISABLED class");

  info("Enabling the first stylesheet again.");
  yield toggleEnabled(editor, enabledToggle, panel.panelWindow);

  is(editor.styleSheet.disabled, false,
     "first stylesheet is now enabled again");
  is(summary.classList.contains("disabled"), false,
     "first stylesheet is now enabled again, UI does not have DISABLED class");
});

function* toggleEnabled(editor, enabledToggle, panelWindow) {
  let changed = editor.once("property-change");

  info("Waiting for focus.");
  yield SimpleTest.promiseFocus(panelWindow);

  info("Clicking on the toggle.");
  EventUtils.synthesizeMouseAtCenter(enabledToggle, {}, panelWindow);

  info("Waiting for stylesheet to be disabled.");
  let property = yield changed;
  while (property !== "disabled") {
    info("Ignoring property-change for '" + property + "'.");
    property = yield editor.once("property-change");
  }
}