browser/devtools/styleeditor/test/browser_styleeditor_import.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleeditor/test/browser_styleeditor_import.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,73 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +// http rather than chrome to improve coverage
     1.9 +const TESTCASE_URI = TEST_BASE_HTTP + "simple.html";
    1.10 +
    1.11 +let tempScope = {};
    1.12 +Components.utils.import("resource://gre/modules/FileUtils.jsm", tempScope);
    1.13 +let FileUtils = tempScope.FileUtils;
    1.14 +
    1.15 +const FILENAME = "styleeditor-import-test.css";
    1.16 +const SOURCE = "body{background:red;}";
    1.17 +
    1.18 +
    1.19 +let gUI;
    1.20 +
    1.21 +function test()
    1.22 +{
    1.23 +  waitForExplicitFinish();
    1.24 +
    1.25 +  addTabAndCheckOnStyleEditorAdded(panel => gUI = panel.UI, testEditorAdded);
    1.26 +
    1.27 +  content.location = TESTCASE_URI;
    1.28 +}
    1.29 +
    1.30 +function testImport()
    1.31 +{
    1.32 +  // create file to import first
    1.33 +  let file = FileUtils.getFile("ProfD", [FILENAME]);
    1.34 +  let ostream = FileUtils.openSafeFileOutputStream(file);
    1.35 +  let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
    1.36 +                    .createInstance(Ci.nsIScriptableUnicodeConverter);
    1.37 +  converter.charset = "UTF-8";
    1.38 +  let istream = converter.convertToInputStream(SOURCE);
    1.39 +  NetUtil.asyncCopy(istream, ostream, function (status) {
    1.40 +    FileUtils.closeSafeFileOutputStream(ostream);
    1.41 +
    1.42 +    // click the import button now that the file to import is ready
    1.43 +    gUI._mockImportFile = file;
    1.44 +
    1.45 +    waitForFocus(function () {
    1.46 +      let document = gPanelWindow.document
    1.47 +      let importButton = document.querySelector(".style-editor-importButton");
    1.48 +      ok(importButton, "import button exists");
    1.49 +
    1.50 +      EventUtils.synthesizeMouseAtCenter(importButton, {}, gPanelWindow);
    1.51 +    }, gPanelWindow);
    1.52 +  });
    1.53 +}
    1.54 +
    1.55 +let gAddedCount = 0;
    1.56 +function testEditorAdded(aEditor)
    1.57 +{
    1.58 +  if (++gAddedCount == 2) {
    1.59 +    // test import after the 2 initial stylesheets have been loaded
    1.60 +    gUI.editors[0].getSourceEditor().then(function() {
    1.61 +      testImport();
    1.62 +    });
    1.63 +  }
    1.64 +
    1.65 +  if (!aEditor.savedFile) {
    1.66 +    return;
    1.67 +  }
    1.68 +
    1.69 +  is(aEditor.savedFile.leafName, FILENAME,
    1.70 +     "imported stylesheet will be saved directly into the same file");
    1.71 +  is(aEditor.friendlyName, FILENAME,
    1.72 +     "imported stylesheet has the same name as the filename");
    1.73 +
    1.74 +  gUI = null;
    1.75 +  finish();
    1.76 +}

mercurial