browser/devtools/styleeditor/test/browser_styleeditor_sourcemaps.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleeditor/test/browser_styleeditor_sourcemaps.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +// https rather than chrome to improve coverage
     1.9 +const TESTCASE_URI = TEST_BASE_HTTPS + "sourcemaps.html";
    1.10 +const PREF = "devtools.styleeditor.source-maps-enabled";
    1.11 +
    1.12 +
    1.13 +const contents = {
    1.14 +  "sourcemaps.scss": [
    1.15 +    "",
    1.16 +    "$paulrougetpink: #f06;",
    1.17 +    "",
    1.18 +    "div {",
    1.19 +    "  color: $paulrougetpink;",
    1.20 +    "}",
    1.21 +    "",
    1.22 +    "span {",
    1.23 +    "  background-color: #EEE;",
    1.24 +    "}"
    1.25 +  ].join("\n"),
    1.26 +  "contained.scss": [
    1.27 +    "$pink: #f06;",
    1.28 +    "",
    1.29 +    "#header {",
    1.30 +    "  color: $pink;",
    1.31 +    "}"
    1.32 +  ].join("\n"),
    1.33 +  "sourcemaps.css": [
    1.34 +    "div {",
    1.35 +    "  color: #ff0066; }",
    1.36 +    "",
    1.37 +    "span {",
    1.38 +    "  background-color: #EEE; }",
    1.39 +    "",
    1.40 +    "/*# sourceMappingURL=sourcemaps.css.map */"
    1.41 +  ].join("\n"),
    1.42 +  "contained.css": [
    1.43 +    "#header {",
    1.44 +    "  color: #f06; }",
    1.45 +    "",
    1.46 +    "/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJzYXNzL2NvbnRhaW5lZC5zY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBO0VBQ0UsT0FISyIsInNvdXJjZXNDb250ZW50IjpbIiRwaW5rOiAjZjA2O1xuXG4jaGVhZGVyIHtcbiAgY29sb3I6ICRwaW5rO1xufSJdfQ==*/"
    1.47 +  ].join("\n")
    1.48 +}
    1.49 +
    1.50 +const cssNames = ["sourcemaps.css", "contained.css"];
    1.51 +const scssNames = ["sourcemaps.scss", "contained.scss"];
    1.52 +
    1.53 +waitForExplicitFinish();
    1.54 +
    1.55 +let test = asyncTest(function*() {
    1.56 +  Services.prefs.setBoolPref(PREF, true);
    1.57 +
    1.58 +  let {UI} = yield addTabAndOpenStyleEditors(5, null, TESTCASE_URI);
    1.59 +
    1.60 +  is(UI.editors.length, 3,
    1.61 +    "correct number of editors with source maps enabled");
    1.62 +
    1.63 +  // Test first plain css editor
    1.64 +  testFirstEditor(UI.editors[0]);
    1.65 +
    1.66 +  // Test Scss editors
    1.67 +  yield testEditor(UI.editors[1], scssNames);
    1.68 +  yield testEditor(UI.editors[2], scssNames);
    1.69 +
    1.70 +  // Test disabling original sources
    1.71 +  yield togglePref(UI);
    1.72 +
    1.73 +  is(UI.editors.length, 3, "correct number of editors after pref toggled");
    1.74 +
    1.75 +  // Test CSS editors
    1.76 +  yield testEditor(UI.editors[1], cssNames);
    1.77 +  yield testEditor(UI.editors[2], cssNames);
    1.78 +
    1.79 +  Services.prefs.clearUserPref(PREF);
    1.80 +});
    1.81 +
    1.82 +function testFirstEditor(editor) {
    1.83 +  let name = getStylesheetNameFor(editor);
    1.84 +  is(name, "simple.css", "First style sheet display name is correct");
    1.85 +}
    1.86 +
    1.87 +function testEditor(editor, possibleNames) {
    1.88 +  let name = getStylesheetNameFor(editor);
    1.89 +  ok(possibleNames.indexOf(name) >= 0, name + " editor name is correct");
    1.90 +
    1.91 +  return openEditor(editor).then(() => {
    1.92 +    let expectedText = contents[name];
    1.93 +
    1.94 +    let text = editor.sourceEditor.getText();
    1.95 +    is(text, expectedText, name + " editor contains expected text");
    1.96 +  });
    1.97 +}
    1.98 +
    1.99 +/* Helpers */
   1.100 +
   1.101 +function togglePref(UI) {
   1.102 +  let deferred = promise.defer();
   1.103 +  let count = 0;
   1.104 +
   1.105 +  UI.on("editor-added", (event, editor) => {
   1.106 +    if (++count == 3) {
   1.107 +      deferred.resolve();
   1.108 +    }
   1.109 +  })
   1.110 +
   1.111 +  Services.prefs.setBoolPref(PREF, false);
   1.112 +  return deferred.promise;
   1.113 +}
   1.114 +
   1.115 +function openEditor(editor) {
   1.116 +  getLinkFor(editor).click();
   1.117 +
   1.118 +  return editor.getSourceEditor();
   1.119 +}
   1.120 +
   1.121 +function getLinkFor(editor) {
   1.122 +  return editor.summary.querySelector(".stylesheet-name");
   1.123 +}
   1.124 +
   1.125 +function getStylesheetNameFor(editor) {
   1.126 +  return editor.summary.querySelector(".stylesheet-name > label")
   1.127 +         .getAttribute("value")
   1.128 +}

mercurial