test_bug121341.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. var Ci = Components.interfaces;
  2. var Cu = Components.utils;
  3. Cu.import("resource://gre/modules/NetUtil.jsm");
  4. function run_test() {
  5. var ios = Components.classes["@mozilla.org/network/io-service;1"].
  6. getService(Components.interfaces.nsIIOService);
  7. var dataFile = do_get_file("data/bug121341.properties");
  8. var channel = NetUtil.newChannel({
  9. uri: ios.newFileURI(dataFile, null, null),
  10. loadUsingSystemPrincipal: true
  11. });
  12. var inp = channel.open2();
  13. var properties = Components.classes["@mozilla.org/persistent-properties;1"].
  14. createInstance(Components.interfaces.nsIPersistentProperties);
  15. properties.load(inp);
  16. var value;
  17. value = properties.getStringProperty("1");
  18. do_check_eq(value, "abc");
  19. value = properties.getStringProperty("2");
  20. do_check_eq(value, "xy");
  21. value = properties.getStringProperty("3");
  22. do_check_eq(value, "\u1234\t\r\n\u00AB\u0001\n");
  23. value = properties.getStringProperty("4");
  24. do_check_eq(value, "this is multiline property");
  25. value = properties.getStringProperty("5");
  26. do_check_eq(value, "this is another multiline property");
  27. value = properties.getStringProperty("6");
  28. do_check_eq(value, "test\u0036");
  29. value = properties.getStringProperty("7");
  30. do_check_eq(value, "yet another multiline propery");
  31. value = properties.getStringProperty("8");
  32. do_check_eq(value, "\ttest5\u0020");
  33. value = properties.getStringProperty("9");
  34. do_check_eq(value, " test6\t");
  35. value = properties.getStringProperty("10a\u1234b");
  36. do_check_eq(value, "c\uCDEFd");
  37. value = properties.getStringProperty("11");
  38. do_check_eq(value, "\uABCD");
  39. dataFile = do_get_file("data/bug121341-2.properties");
  40. var channel = NetUtil.newChannel({
  41. uri: ios.newFileURI(dataFile, null, null),
  42. loadUsingSystemPrincipal: true
  43. });
  44. inp = channel.open2();
  45. var properties2 = Components.classes["@mozilla.org/persistent-properties;1"].
  46. createInstance(Components.interfaces.nsIPersistentProperties);
  47. try {
  48. properties2.load(inp);
  49. do_throw("load() didn't fail");
  50. }
  51. catch (e) {
  52. }
  53. }