michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // http rather than chrome to improve coverage michael@0: const TESTCASE_URI = TEST_BASE_HTTP + "simple.html"; michael@0: michael@0: let tempScope = {}; michael@0: Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope); michael@0: let FileUtils = tempScope.FileUtils; michael@0: michael@0: const FILENAME = "styleeditor-import-test.css"; michael@0: const SOURCE = "body{background:red;}"; michael@0: michael@0: michael@0: let gUI; michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: addTabAndCheckOnStyleEditorAdded(panel => gUI = panel.UI, testEditorAdded); michael@0: michael@0: content.location = TESTCASE_URI; michael@0: } michael@0: michael@0: function testImport() michael@0: { michael@0: // create file to import first michael@0: let file = FileUtils.getFile("ProfD", [FILENAME]); michael@0: let ostream = FileUtils.openSafeFileOutputStream(file); michael@0: let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"] michael@0: .createInstance(Ci.nsIScriptableUnicodeConverter); michael@0: converter.charset = "UTF-8"; michael@0: let istream = converter.convertToInputStream(SOURCE); michael@0: NetUtil.asyncCopy(istream, ostream, function (status) { michael@0: FileUtils.closeSafeFileOutputStream(ostream); michael@0: michael@0: // click the import button now that the file to import is ready michael@0: gUI._mockImportFile = file; michael@0: michael@0: waitForFocus(function () { michael@0: let document = gPanelWindow.document michael@0: let importButton = document.querySelector(".style-editor-importButton"); michael@0: ok(importButton, "import button exists"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(importButton, {}, gPanelWindow); michael@0: }, gPanelWindow); michael@0: }); michael@0: } michael@0: michael@0: let gAddedCount = 0; michael@0: function testEditorAdded(aEditor) michael@0: { michael@0: if (++gAddedCount == 2) { michael@0: // test import after the 2 initial stylesheets have been loaded michael@0: gUI.editors[0].getSourceEditor().then(function() { michael@0: testImport(); michael@0: }); michael@0: } michael@0: michael@0: if (!aEditor.savedFile) { michael@0: return; michael@0: } michael@0: michael@0: is(aEditor.savedFile.leafName, FILENAME, michael@0: "imported stylesheet will be saved directly into the same file"); michael@0: is(aEditor.friendlyName, FILENAME, michael@0: "imported stylesheet has the same name as the filename"); michael@0: michael@0: gUI = null; michael@0: finish(); michael@0: }