|
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/. */ |
|
6 |
|
7 const Cr = Components.results; |
|
8 const Ci = Components.interfaces; |
|
9 |
|
10 const CC = Components.Constructor; |
|
11 var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath"); |
|
12 |
|
13 function run_test() |
|
14 { |
|
15 test_normalized_vs_non_normalized(); |
|
16 } |
|
17 |
|
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; |
|
27 |
|
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)); |
|
31 |
|
32 // this is a non-normalized version of tmp1, it should not equal tmp1 |
|
33 tmp2.appendRelativePath("."); |
|
34 do_check_false(tmp1.equals(tmp2)); |
|
35 |
|
36 // normalize and make sure they are equivalent again |
|
37 tmp2.normalize(); |
|
38 do_check_true(tmp1.equals(tmp2)); |
|
39 } |