1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/unit/test_file_equality.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,39 @@ 1.4 +/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +const Cr = Components.results; 1.11 +const Ci = Components.interfaces; 1.12 + 1.13 +const CC = Components.Constructor; 1.14 +var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath"); 1.15 + 1.16 +function run_test() 1.17 +{ 1.18 + test_normalized_vs_non_normalized(); 1.19 +} 1.20 + 1.21 +function test_normalized_vs_non_normalized() 1.22 +{ 1.23 + // get a directory that exists on all platforms 1.24 + var dirProvider = Components.classes["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties); 1.25 + var tmp1 = dirProvider.get("TmpD", Ci.nsILocalFile); 1.26 + var exists = tmp1.exists(); 1.27 + do_check_true(exists); 1.28 + if (!exists) 1.29 + return; 1.30 + 1.31 + // this has the same exact path as tmp1, it should equal tmp1 1.32 + var tmp2 = new LocalFile(tmp1.path); 1.33 + do_check_true(tmp1.equals(tmp2)); 1.34 + 1.35 + // this is a non-normalized version of tmp1, it should not equal tmp1 1.36 + tmp2.appendRelativePath("."); 1.37 + do_check_false(tmp1.equals(tmp2)); 1.38 + 1.39 + // normalize and make sure they are equivalent again 1.40 + tmp2.normalize(); 1.41 + do_check_true(tmp1.equals(tmp2)); 1.42 +}