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