~ubuntu-branches/ubuntu/trusty/enigmail/trusty-updates

« back to all changes in this revision

Viewing changes to services/sync/tests/unit/test_utils_json.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2011-06-07 14:35:53 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: package-import@ubuntu.com-20110607143553-fbgqhhvh8g8h6j1y
Tags: 2:1.2~a2~cvs20110606t2200-0ubuntu1
* Update to latest trunk snapshot for Thunderbird beta compat

* Remove build/pgo/profileserver.py from debian/clean. The new build
  system has a target depending on this
  - update debian/clean
* Drop debian/patches/autoconf.diff, just generate this at build time
* Refresh debian/patches/build_system_dont_link_libxul.diff
* libipc seems to be renamed to libipc-pipe. Fix genxpi and chrome.manifest
  to fix this 
  - add debian/patches/ipc-pipe_rename.diff
  - update debian/patches/series
* The makefiles in extensions/enigmail/ipc have an incorrect DEPTH
  attribute. Fix this so that they can find the rest of the build system
  - add debian/patches/makefile_depth.diff
  - update debian/patches/series
* Drop debian/patches/makefile-in-empty-xpcom-fix.diff - fixed in the
  current version
* Don't register a class ID multiple times, as this breaks enigmail entirely
  - add debian/patches/dont_register_cids_multiple_times.diff
  - update debian/patches/series
* Look for the Thunderbird 5 SDK
  - update debian/rules
  - update debian/control
* Run autoconf2.13 at build time
  - update debian/rules
  - update debian/control
* Add useless mesa-common-dev build-dep, just to satisfy the build system.
  We should just patch this out entirely really, but that's for another upload
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
_("Make sure json saves and loads from disk");
 
2
Cu.import("resource://services-sync/util.js");
 
3
Cu.import("resource://services-sync/constants.js");
 
4
 
 
5
function run_test() {
 
6
  do_test_pending();
 
7
  Utils.asyncChain(function (next) {
 
8
 
 
9
    _("Do a simple write of an array to json and read");
 
10
    Utils.jsonSave("foo", {}, ["v1", "v2"], ensureThrows(function() {
 
11
      Utils.jsonLoad("foo", {}, ensureThrows(function(val) {
 
12
        let foo = val;
 
13
        do_check_eq(typeof foo, "object");
 
14
        do_check_eq(foo.length, 2);
 
15
        do_check_eq(foo[0], "v1");
 
16
        do_check_eq(foo[1], "v2");
 
17
        next();
 
18
      }));
 
19
    }));
 
20
 
 
21
  }, function (next) {
 
22
 
 
23
    _("Try saving simple strings");
 
24
    Utils.jsonSave("str", {}, "hi", ensureThrows(function() {
 
25
      Utils.jsonLoad("str", {}, ensureThrows(function(val) {
 
26
        let str = val;
 
27
        do_check_eq(typeof str, "string");
 
28
        do_check_eq(str.length, 2);
 
29
        do_check_eq(str[0], "h");
 
30
        do_check_eq(str[1], "i");
 
31
        next();
 
32
      }));
 
33
    }));
 
34
 
 
35
  }, function (next) {
 
36
 
 
37
    _("Try saving a number");
 
38
    Utils.jsonSave("num", {}, 42, ensureThrows(function() {
 
39
      Utils.jsonLoad("num", {}, ensureThrows(function(val) {
 
40
        let num = val;
 
41
        do_check_eq(typeof num, "number");
 
42
        do_check_eq(num, 42);
 
43
        next();
 
44
      }));
 
45
    }));
 
46
 
 
47
  }, function (next) {
 
48
 
 
49
    _("Try loading a non-existent file.");
 
50
    Utils.jsonLoad("non-existent", {}, ensureThrows(function(val) {
 
51
      do_check_eq(val, undefined);
 
52
      next();
 
53
    }));
 
54
    
 
55
  }, function (next) {
 
56
 
 
57
    _("Verify that writes are logged.");
 
58
    let trace;
 
59
    Utils.jsonSave("log", {_log: {trace: function(msg) { trace = msg; }}},
 
60
                   "hi", ensureThrows(function () {
 
61
      do_check_true(!!trace);
 
62
      next();
 
63
    }));
 
64
 
 
65
  }, function (next) {
 
66
 
 
67
    _("Verify that reads and read errors are logged.");
 
68
 
 
69
    // Write a file with some invalid JSON
 
70
    let file = Utils.getProfileFile({ autoCreate: true,
 
71
                                      path: "weave/log.json" });
 
72
    let fos = Cc["@mozilla.org/network/file-output-stream;1"]
 
73
                .createInstance(Ci.nsIFileOutputStream);
 
74
    fos.init(file, MODE_WRONLY | MODE_CREATE | MODE_TRUNCATE, PERMS_FILE,
 
75
             fos.DEFER_OPEN);
 
76
    let stream = Cc["@mozilla.org/intl/converter-output-stream;1"]
 
77
                   .createInstance(Ci.nsIConverterOutputStream);
 
78
    stream.init(fos, "UTF-8", 4096, 0x0000);
 
79
    stream.writeString("invalid json!");
 
80
    stream.close();
 
81
 
 
82
    let trace, debug;
 
83
    Utils.jsonLoad("log",
 
84
                   {_log: {trace: function(msg) { trace = msg; },
 
85
                           debug: function(msg) { debug = msg; }}},
 
86
                   ensureThrows(function(val) {
 
87
      do_check_true(!!trace);
 
88
      do_check_true(!!debug);
 
89
      next();
 
90
    }));
 
91
 
 
92
  }, do_test_finished)();
 
93
 
 
94
}