xpcom/tests/unit/test_file_equality.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* vim:set ts=2 sw=2 sts=2 et: */
     3 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 const Cr = Components.results;
     8 const Ci = Components.interfaces;
    10 const CC = Components.Constructor;
    11 var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
    13 function run_test()
    14 {
    15   test_normalized_vs_non_normalized();
    16 }
    18 function test_normalized_vs_non_normalized()
    19 {
    20   // get a directory that exists on all platforms
    21   var dirProvider = Components.classes["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
    22   var tmp1 = dirProvider.get("TmpD", Ci.nsILocalFile);
    23   var exists = tmp1.exists();
    24   do_check_true(exists);
    25   if (!exists)
    26     return;
    28   // this has the same exact path as tmp1, it should equal tmp1
    29   var tmp2 = new LocalFile(tmp1.path);
    30   do_check_true(tmp1.equals(tmp2));
    32   // this is a non-normalized version of tmp1, it should not equal tmp1
    33   tmp2.appendRelativePath(".");
    34   do_check_false(tmp1.equals(tmp2));
    36   // normalize and make sure they are equivalent again
    37   tmp2.normalize();
    38   do_check_true(tmp1.equals(tmp2));
    39 }

mercurial