tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_fileconstructor.xhtml (2623B)


      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">
     12 
     13  <script type="application/javascript"
     14    src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
     15 
     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">
     22 
     23 </div>
     24 <pre id="test">
     25 </pre>
     26 </body>
     27 
     28 <script class="testbody" type="application/javascript">
     29 <![CDATA[
     30 
     31 /** Test for Bug 607114 */
     32 
     33 // eslint-disable-next-line mozilla/no-addtask-setup
     34 add_task(async function setup() {
     35  await SpecialPowers.pushPrefEnv({ set: [[ "dom.file.createInChild", true ]]});
     36 });
     37 
     38 add_task(async function test() {
     39  var file = SpecialPowers.Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     40  // man I wish this were simpler ...
     41  file.append("chrome");
     42  file.append("dom");
     43  file.append("base");
     44  file.append("test");
     45  file.append("chrome");
     46  file.append("fileconstructor_file.png");
     47 
     48  let domFile = await File.createFromFileName(file.path);
     49 
     50  ok(File.isInstance(domFile), "File() should return a File");
     51  is(domFile.type, "image/png", "File should be a PNG");
     52  is(domFile.size, 95, "File has size 95 (and more importantly we can read it)");
     53 
     54  domFile = await File.createFromNsIFile(file);
     55  ok(File.isInstance(domFile), "File() should return a File for an nsIFile");
     56  is(domFile.type, "image/png", "File should be a PNG");
     57  is(domFile.size, 95, "File has size 95 (and more importantly we can read it)");
     58 
     59  try {
     60    await File.createFromFileName(
     61      "i/sure/hope/this/does/not/exist/anywhere.txt"
     62    );
     63    ok(false, "Attempt to construct a non-existent file should fail.");
     64  } catch (ex) {
     65    is(
     66      ex.result,
     67      Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH,
     68      "Constructing a non-existing file should fail with the correct error code"
     69    );
     70  }
     71  let dir = SpecialPowers.Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     72  try {
     73    await File.createFromNsIFile(dir);
     74    ok(false, "Attempt to construct a file from a directory should fail.");
     75  } catch (ex) {
     76    is(
     77      ex.result,
     78      Cr.NS_ERROR_FILE_IS_DIRECTORY,
     79      "Constructing a file from a directory should fail with the correct error code"
     80    );
     81  }
     82 })
     83 ]]>
     84 </script>
     85 
     86 </window>