summaryrefslogtreecommitdiffstats
path: root/devtools/client/styleeditor/test/browser_styleeditor_sourcemaps_inline.js
blob: 933a128a745f13910b919a9eb5a0e00e524e5c19 (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
86
87
88
89
/* 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.source-map.client-service.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(async function () {
  const { ui } = await openStyleEditorForURL(TESTCASE_URI);

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

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

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

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

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

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

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

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

/* Helpers */

function togglePref(UI) {
  const editorsPromise = UI.once("stylesheets-refreshed");
  const 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");
}