tor-browser

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

test_file2.js (1917B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 Cu.importGlobalProperties(['File']);
      6 
      7 add_task(async function() {
      8  // throw if anything goes wrong
      9 
     10  // find the current directory path
     11  var file = Cc["@mozilla.org/file/directory_service;1"]
     12             .getService(Ci.nsIProperties)
     13             .get("CurWorkD", Ci.nsIFile);
     14  file.append("xpcshell.toml");
     15 
     16  // should be able to construct a file
     17  var f1 = await File.createFromFileName(file.path);
     18  // and with nsIFiles
     19  var f2 = await File.createFromNsIFile(file);
     20 
     21  // do some tests
     22  Assert.ok(f1 instanceof File, "Should be a DOM File");
     23  Assert.ok(f2 instanceof File, "Should be a DOM File");
     24 
     25  Assert.equal(f1.name, "xpcshell.toml", "Should be the right file");
     26  Assert.equal(f2.name, "xpcshell.toml", "Should be the right file");
     27 
     28  // The OS could guess the mime-type or not...
     29  Assert.ok(f1.type === "" || f1.type === "application/toml", "Should be the right type");
     30  Assert.ok(f2.type === "" || f2.type === "application/toml", "Should be the right type");
     31 
     32  var threw = false;
     33  try {
     34    // Needs a ctor argument
     35    var f7 = File();
     36  } catch (e) {
     37    threw = true;
     38  }
     39  Assert.ok(threw, "No ctor arguments should throw");
     40 
     41  var threw = false;
     42  try {
     43    // Needs a valid ctor argument
     44    var f7 = File(Date(132131532));
     45  } catch (e) {
     46    threw = true;
     47  }
     48  Assert.ok(threw, "Passing a random object should fail");
     49 
     50  var threw = false
     51  try {
     52    // Directories fail
     53    var dir = Cc["@mozilla.org/file/directory_service;1"]
     54                .getService(Ci.nsIProperties)
     55                .get("CurWorkD", Ci.nsIFile);
     56    var f7 = await File.createFromNsIFile(dir)
     57  } catch (e) {
     58    threw = true;
     59  }
     60  Assert.ok(threw, "Can't create a File object for a directory");
     61 });