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 | const TESTCASE_URI_HTML = TEST_BASE + "simple.html"; |
michael@0 | 6 | const TESTCASE_URI_CSS = TEST_BASE + "simple.css"; |
michael@0 | 7 | |
michael@0 | 8 | const Cc = Components.classes; |
michael@0 | 9 | const Ci = Components.interfaces; |
michael@0 | 10 | |
michael@0 | 11 | let tempScope = {}; |
michael@0 | 12 | Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope); |
michael@0 | 13 | Components.utils.import("resource://gre/modules/NetUtil.jsm", tempScope); |
michael@0 | 14 | let FileUtils = tempScope.FileUtils; |
michael@0 | 15 | let NetUtil = tempScope.NetUtil; |
michael@0 | 16 | |
michael@0 | 17 | function test() |
michael@0 | 18 | { |
michael@0 | 19 | waitForExplicitFinish(); |
michael@0 | 20 | |
michael@0 | 21 | copy(TESTCASE_URI_HTML, "simple.html", function(htmlFile) { |
michael@0 | 22 | copy(TESTCASE_URI_CSS, "simple.css", function(cssFile) { |
michael@0 | 23 | addTabAndOpenStyleEditors(1, function(panel) { |
michael@0 | 24 | let UI = panel.UI; |
michael@0 | 25 | let editor = UI.editors[0]; |
michael@0 | 26 | editor.getSourceEditor().then(runTests.bind(this, editor)); |
michael@0 | 27 | }); |
michael@0 | 28 | |
michael@0 | 29 | let uri = Services.io.newFileURI(htmlFile); |
michael@0 | 30 | let filePath = uri.resolve(""); |
michael@0 | 31 | content.location = filePath; |
michael@0 | 32 | }); |
michael@0 | 33 | }); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function runTests(editor) |
michael@0 | 37 | { |
michael@0 | 38 | editor.sourceEditor.once("dirty-change", () => { |
michael@0 | 39 | is(editor.sourceEditor.isClean(), false, "Editor is dirty."); |
michael@0 | 40 | ok(editor.summary.classList.contains("unsaved"), |
michael@0 | 41 | "Star icon is present in the corresponding summary."); |
michael@0 | 42 | }); |
michael@0 | 43 | let beginCursor = {line: 0, ch: 0}; |
michael@0 | 44 | editor.sourceEditor.replaceText("DIRTY TEXT", beginCursor, beginCursor); |
michael@0 | 45 | |
michael@0 | 46 | editor.sourceEditor.once("dirty-change", () => { |
michael@0 | 47 | is(editor.sourceEditor.isClean(), true, "Editor is clean."); |
michael@0 | 48 | ok(!editor.summary.classList.contains("unsaved"), |
michael@0 | 49 | "Star icon is not present in the corresponding summary."); |
michael@0 | 50 | finish(); |
michael@0 | 51 | }); |
michael@0 | 52 | editor.saveToFile(null, function (file) { |
michael@0 | 53 | ok(file, "file should get saved directly when using a file:// URI"); |
michael@0 | 54 | }); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function copy(aSrcChromeURL, aDestFileName, aCallback) |
michael@0 | 58 | { |
michael@0 | 59 | let destFile = FileUtils.getFile("ProfD", [aDestFileName]); |
michael@0 | 60 | write(read(aSrcChromeURL), destFile, aCallback); |
michael@0 | 61 | } |
michael@0 | 62 | |
michael@0 | 63 | function read(aSrcChromeURL) |
michael@0 | 64 | { |
michael@0 | 65 | let scriptableStream = Cc["@mozilla.org/scriptableinputstream;1"] |
michael@0 | 66 | .getService(Ci.nsIScriptableInputStream); |
michael@0 | 67 | |
michael@0 | 68 | let channel = Services.io.newChannel(aSrcChromeURL, null, null); |
michael@0 | 69 | let input = channel.open(); |
michael@0 | 70 | scriptableStream.init(input); |
michael@0 | 71 | |
michael@0 | 72 | let data = ""; |
michael@0 | 73 | while (input.available()) { |
michael@0 | 74 | data = data.concat(scriptableStream.read(input.available())); |
michael@0 | 75 | } |
michael@0 | 76 | scriptableStream.close(); |
michael@0 | 77 | input.close(); |
michael@0 | 78 | |
michael@0 | 79 | return data; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | function write(aData, aFile, aCallback) |
michael@0 | 83 | { |
michael@0 | 84 | let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] |
michael@0 | 85 | .createInstance(Ci.nsIScriptableUnicodeConverter); |
michael@0 | 86 | |
michael@0 | 87 | converter.charset = "UTF-8"; |
michael@0 | 88 | |
michael@0 | 89 | let istream = converter.convertToInputStream(aData); |
michael@0 | 90 | let ostream = FileUtils.openSafeFileOutputStream(aFile); |
michael@0 | 91 | |
michael@0 | 92 | NetUtil.asyncCopy(istream, ostream, function(status) { |
michael@0 | 93 | if (!Components.isSuccessCode(status)) { |
michael@0 | 94 | info("Coudln't write to " + aFile.path); |
michael@0 | 95 | return; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | aCallback(aFile); |
michael@0 | 99 | }); |
michael@0 | 100 | } |