browser/devtools/styleeditor/test/browser_styleeditor_import.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:316c7c18f210
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/ */
4
5 // http rather than chrome to improve coverage
6 const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
7
8 let tempScope = {};
9 Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope);
10 let FileUtils = tempScope.FileUtils;
11
12 const FILENAME = "styleeditor-import-test.css";
13 const SOURCE = "body{background:red;}";
14
15
16 let gUI;
17
18 function test()
19 {
20 waitForExplicitFinish();
21
22 addTabAndCheckOnStyleEditorAdded(panel => gUI = panel.UI, testEditorAdded);
23
24 content.location = TESTCASE_URI;
25 }
26
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);
38
39 // click the import button now that the file to import is ready
40 gUI._mockImportFile = file;
41
42 waitForFocus(function () {
43 let document = gPanelWindow.document
44 let importButton = document.querySelector(".style-editor-importButton");
45 ok(importButton, "import button exists");
46
47 EventUtils.synthesizeMouseAtCenter(importButton, {}, gPanelWindow);
48 }, gPanelWindow);
49 });
50 }
51
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 }
61
62 if (!aEditor.savedFile) {
63 return;
64 }
65
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");
70
71 gUI = null;
72 finish();
73 }

mercurial