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 | // http rather than chrome to improve coverage |
michael@0 | 6 | const TESTCASE_URI = TEST_BASE_HTTP + "simple.html"; |
michael@0 | 7 | |
michael@0 | 8 | let tempScope = {}; |
michael@0 | 9 | Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope); |
michael@0 | 10 | let FileUtils = tempScope.FileUtils; |
michael@0 | 11 | |
michael@0 | 12 | const FILENAME = "styleeditor-import-test.css"; |
michael@0 | 13 | const SOURCE = "body{background:red;}"; |
michael@0 | 14 | |
michael@0 | 15 | |
michael@0 | 16 | let gUI; |
michael@0 | 17 | |
michael@0 | 18 | function test() |
michael@0 | 19 | { |
michael@0 | 20 | waitForExplicitFinish(); |
michael@0 | 21 | |
michael@0 | 22 | addTabAndCheckOnStyleEditorAdded(panel => gUI = panel.UI, testEditorAdded); |
michael@0 | 23 | |
michael@0 | 24 | content.location = TESTCASE_URI; |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function testImport() |
michael@0 | 28 | { |
michael@0 | 29 | // create file to import first |
michael@0 | 30 | let file = FileUtils.getFile("ProfD", [FILENAME]); |
michael@0 | 31 | let ostream = FileUtils.openSafeFileOutputStream(file); |
michael@0 | 32 | let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] |
michael@0 | 33 | .createInstance(Ci.nsIScriptableUnicodeConverter); |
michael@0 | 34 | converter.charset = "UTF-8"; |
michael@0 | 35 | let istream = converter.convertToInputStream(SOURCE); |
michael@0 | 36 | NetUtil.asyncCopy(istream, ostream, function (status) { |
michael@0 | 37 | FileUtils.closeSafeFileOutputStream(ostream); |
michael@0 | 38 | |
michael@0 | 39 | // click the import button now that the file to import is ready |
michael@0 | 40 | gUI._mockImportFile = file; |
michael@0 | 41 | |
michael@0 | 42 | waitForFocus(function () { |
michael@0 | 43 | let document = gPanelWindow.document |
michael@0 | 44 | let importButton = document.querySelector(".style-editor-importButton"); |
michael@0 | 45 | ok(importButton, "import button exists"); |
michael@0 | 46 | |
michael@0 | 47 | EventUtils.synthesizeMouseAtCenter(importButton, {}, gPanelWindow); |
michael@0 | 48 | }, gPanelWindow); |
michael@0 | 49 | }); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | let gAddedCount = 0; |
michael@0 | 53 | function testEditorAdded(aEditor) |
michael@0 | 54 | { |
michael@0 | 55 | if (++gAddedCount == 2) { |
michael@0 | 56 | // test import after the 2 initial stylesheets have been loaded |
michael@0 | 57 | gUI.editors[0].getSourceEditor().then(function() { |
michael@0 | 58 | testImport(); |
michael@0 | 59 | }); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | if (!aEditor.savedFile) { |
michael@0 | 63 | return; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | is(aEditor.savedFile.leafName, FILENAME, |
michael@0 | 67 | "imported stylesheet will be saved directly into the same file"); |
michael@0 | 68 | is(aEditor.friendlyName, FILENAME, |
michael@0 | 69 | "imported stylesheet has the same name as the filename"); |
michael@0 | 70 | |
michael@0 | 71 | gUI = null; |
michael@0 | 72 | finish(); |
michael@0 | 73 | } |