browser/devtools/styleeditor/test/browser_styleeditor_sourcemaps.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* vim: set ts=2 et sw=2 tw=80: */
     2 /* Any copyright is dedicated to the Public Domain.
     3    http://creativecommons.org/publicdomain/zero/1.0/ */
     5 // https rather than chrome to improve coverage
     6 const TESTCASE_URI = TEST_BASE_HTTPS + "sourcemaps.html";
     7 const PREF = "devtools.styleeditor.source-maps-enabled";
    10 const contents = {
    11   "sourcemaps.scss": [
    12     "",
    13     "$paulrougetpink: #f06;",
    14     "",
    15     "div {",
    16     "  color: $paulrougetpink;",
    17     "}",
    18     "",
    19     "span {",
    20     "  background-color: #EEE;",
    21     "}"
    22   ].join("\n"),
    23   "contained.scss": [
    24     "$pink: #f06;",
    25     "",
    26     "#header {",
    27     "  color: $pink;",
    28     "}"
    29   ].join("\n"),
    30   "sourcemaps.css": [
    31     "div {",
    32     "  color: #ff0066; }",
    33     "",
    34     "span {",
    35     "  background-color: #EEE; }",
    36     "",
    37     "/*# sourceMappingURL=sourcemaps.css.map */"
    38   ].join("\n"),
    39   "contained.css": [
    40     "#header {",
    41     "  color: #f06; }",
    42     "",
    43     "/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJzYXNzL2NvbnRhaW5lZC5zY3NzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUVBO0VBQ0UsT0FISyIsInNvdXJjZXNDb250ZW50IjpbIiRwaW5rOiAjZjA2O1xuXG4jaGVhZGVyIHtcbiAgY29sb3I6ICRwaW5rO1xufSJdfQ==*/"
    44   ].join("\n")
    45 }
    47 const cssNames = ["sourcemaps.css", "contained.css"];
    48 const scssNames = ["sourcemaps.scss", "contained.scss"];
    50 waitForExplicitFinish();
    52 let test = asyncTest(function*() {
    53   Services.prefs.setBoolPref(PREF, true);
    55   let {UI} = yield addTabAndOpenStyleEditors(5, null, TESTCASE_URI);
    57   is(UI.editors.length, 3,
    58     "correct number of editors with source maps enabled");
    60   // Test first plain css editor
    61   testFirstEditor(UI.editors[0]);
    63   // Test Scss editors
    64   yield testEditor(UI.editors[1], scssNames);
    65   yield testEditor(UI.editors[2], scssNames);
    67   // Test disabling original sources
    68   yield togglePref(UI);
    70   is(UI.editors.length, 3, "correct number of editors after pref toggled");
    72   // Test CSS editors
    73   yield testEditor(UI.editors[1], cssNames);
    74   yield testEditor(UI.editors[2], cssNames);
    76   Services.prefs.clearUserPref(PREF);
    77 });
    79 function testFirstEditor(editor) {
    80   let name = getStylesheetNameFor(editor);
    81   is(name, "simple.css", "First style sheet display name is correct");
    82 }
    84 function testEditor(editor, possibleNames) {
    85   let name = getStylesheetNameFor(editor);
    86   ok(possibleNames.indexOf(name) >= 0, name + " editor name is correct");
    88   return openEditor(editor).then(() => {
    89     let expectedText = contents[name];
    91     let text = editor.sourceEditor.getText();
    92     is(text, expectedText, name + " editor contains expected text");
    93   });
    94 }
    96 /* Helpers */
    98 function togglePref(UI) {
    99   let deferred = promise.defer();
   100   let count = 0;
   102   UI.on("editor-added", (event, editor) => {
   103     if (++count == 3) {
   104       deferred.resolve();
   105     }
   106   })
   108   Services.prefs.setBoolPref(PREF, false);
   109   return deferred.promise;
   110 }
   112 function openEditor(editor) {
   113   getLinkFor(editor).click();
   115   return editor.getSourceEditor();
   116 }
   118 function getLinkFor(editor) {
   119   return editor.summary.querySelector(".stylesheet-name");
   120 }
   122 function getStylesheetNameFor(editor) {
   123   return editor.summary.querySelector(".stylesheet-name > label")
   124          .getAttribute("value")
   125 }

mercurial