test_file_equality.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 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. var Cr = Components.results;
  7. var Ci = Components.interfaces;
  8. var CC = Components.Constructor;
  9. var LocalFile = CC("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
  10. function run_test()
  11. {
  12. test_normalized_vs_non_normalized();
  13. }
  14. function test_normalized_vs_non_normalized()
  15. {
  16. // get a directory that exists on all platforms
  17. var dirProvider = Components.classes["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
  18. var tmp1 = dirProvider.get("TmpD", Ci.nsILocalFile);
  19. var exists = tmp1.exists();
  20. do_check_true(exists);
  21. if (!exists)
  22. return;
  23. // the test logic below assumes we're starting with a normalized path, but the
  24. // default location on macos is a symbolic link, so resolve it before starting
  25. tmp1.normalize();
  26. // this has the same exact path as tmp1, it should equal tmp1
  27. var tmp2 = new LocalFile(tmp1.path);
  28. do_check_true(tmp1.equals(tmp2));
  29. // this is a non-normalized version of tmp1, it should not equal tmp1
  30. tmp2.appendRelativePath(".");
  31. do_check_false(tmp1.equals(tmp2));
  32. // normalize and make sure they are equivalent again
  33. tmp2.normalize();
  34. do_check_true(tmp1.equals(tmp2));
  35. }