summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps_inline.js
blob: ae7279858d28aff53cf9db270cef7f34f35efbe5 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* 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";

// https rather than chrome to improve coverage
const TESTCASE_URI = TEST_BASE_HTTPS + "sourcemaps-inline.html";
const PREF = "devtools.styleeditor.source-maps-enabled";

const sassContent = `body {
  background-color: black;
  & > h1 {
    color: white;
  }
}
`;

const cssContent = `body {
  background-color: black;
}
body > h1 {
  color: white;
}
` +
"/*# sourceMappingURL=data:application/json;base64,ewoidmVyc2lvbiI6IDMsCiJtY" +
"XBwaW5ncyI6ICJBQUFBLElBQUs7RUFDSCxnQkFBZ0IsRUFBRSxLQUFLO0VBQ3ZCLFNBQU87SUFD" +
"TCxLQUFLLEVBQUUsS0FBSyIsCiJzb3VyY2VzIjogWyJ0ZXN0LnNjc3MiXSwKInNvdXJjZXNDb25" +
"0ZW50IjogWyJib2R5IHtcbiAgYmFja2dyb3VuZC1jb2xvcjogYmxhY2s7XG4gICYgPiBoMSB7XG" +
"4gICAgY29sb3I6IHdoaXRlO1xuICB9XG59XG4iXSwKIm5hbWVzIjogW10sCiJmaWxlIjogInRlc" +
"3QuY3NzIgp9Cg== */";

add_task(function* () {
  let {ui} = yield openStyleEditorForURL(TESTCASE_URI);

  is(ui.editors.length, 1,
    "correct number of editors with source maps enabled");

  yield testEditor(ui.editors[0], "test.scss", sassContent);

  // Test disabling original sources
  yield togglePref(ui);

  is(ui.editors.length, 1, "correct number of editors after pref toggled");

  // Test CSS editors
  yield testEditor(ui.editors[0], "<inline style sheet #1>", cssContent);

  Services.prefs.clearUserPref(PREF);
});

function* testEditor(editor, expectedName, expectedText) {
  let name = getStylesheetNameFor(editor);
  is(expectedName, name, name + " editor name is correct");

  yield openEditor(editor);
  let text = editor.sourceEditor.getText();
  is(text, expectedText, name + " editor contains expected text");
}

/* Helpers */

function togglePref(UI) {
  let editorsPromise = UI.once("stylesheets-reset");
  let selectedPromise = UI.once("editor-selected");

  Services.prefs.setBoolPref(PREF, false);

  return promise.all([editorsPromise, selectedPromise]);
}

function openEditor(editor) {
  getLinkFor(editor).click();

  return editor.getSourceEditor();
}

function getLinkFor(editor) {
  return editor.summary.querySelector(".stylesheet-name");
}

function getStylesheetNameFor(editor) {
  return editor.summary.querySelector(".stylesheet-name > label")
    .getAttribute("value");
}