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