test_file_createUnique.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. var Cc = Components.classes;
  6. var Ci = Components.interfaces;
  7. var Cr = Components.results;
  8. function run_test()
  9. {
  10. // Generate a leaf name that is 255 characters long.
  11. var longLeafName = new Array(256).join("T");
  12. // Generate the path for a file located in a directory with a long name.
  13. var tempFile = Cc["@mozilla.org/file/directory_service;1"].
  14. getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
  15. tempFile.append(longLeafName);
  16. tempFile.append("test.txt");
  17. try {
  18. tempFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
  19. do_throw("Creating an item in a folder with a very long name should throw");
  20. }
  21. catch (e if (e instanceof Ci.nsIException &&
  22. e.result == Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH)) {
  23. // We expect the function not to crash but to raise this exception.
  24. }
  25. }