content/base/test/chrome/test_fileconstructor.xul

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     3 <?xml-stylesheet
     4   href="chrome://mochikit/content/tests/SimpleTest/test.css"
     5   type="text/css"?>
     6 <!--
     7 https://bugzilla.mozilla.org/show_bug.cgi?id=607114.xul
     8 -->
     9 <window title="Mozilla Bug 607114"
    10   xmlns:html="http://www.w3.org/1999/xhtml"
    11   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    13   <script type="application/javascript"
    14     src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    16 <body  xmlns="http://www.w3.org/1999/xhtml">
    17 <a target="_blank"
    18    href="https://bugzilla.mozilla.org/show_bug.cgi?id=607114">
    19    Mozilla Bug 607114</a>
    20 <p id="display"></p>
    21 <div id="content" style="display: none">
    23 </div>
    24 <pre id="test">
    25 </pre>
    26 </body>
    28 <script class="testbody" type="application/javascript">
    29 <![CDATA[
    31 /** Test for Bug 607114 **/
    33 var file = Components.classes["@mozilla.org/file/directory_service;1"]
    34            .getService(Components.interfaces.nsIProperties)
    35            .get("CurWorkD", Components.interfaces.nsIFile);
    37 // man I wish this were simpler ...
    38 file.append("chrome");
    39 file.append("content");
    40 file.append("base");
    41 file.append("test");
    42 file.append("chrome");
    43 file.append("fileconstructor_file.png");
    45 doTest(new File(file.path));
    46 doTest(new File(file));
    47 function doTest(domfile) {
    48   ok(domfile instanceof File, "File() should return a File");
    49   is(domfile.type, "image/png", "File should be a PNG");
    50   is(domfile.size, 95, "File has size 95 (and more importantly we can read it)");
    51 }
    53 try {
    54   var boomfile = new File();
    55   ok(false, "This should never be reached!");
    56 } catch (e) {
    57   ok(true, "Botched file constructor attempts throw and do not crash.");
    58 }
    60 try {
    61   var nonexistentfile = new File("i/sure/hope/this/does/not/exist/anywhere.txt");
    62   ok(false, "This should never be reached!");
    63 } catch (e) {
    64   ok(true, "Attempt to construct a non-existent file should fail.");
    65 }
    67 try {
    68   var dir = Components.classes["@mozilla.org/file/directory_service;1"]
    69                       .getService(Components.interfaces.nsIProperties)
    70                       .get("CurWorkD", Components.interfaces.nsIFile);
    71   var dirfile = new File(dir);
    72   ok(false, "This should never be reached!");
    73 } catch (e) {
    74   ok(true, "Attempt to construct a file from a directory should fail.");
    75 }
    76 ]]>
    77 </script>
    79 </window>

mercurial