gecko/services/sync/tests/unit/test_utils_json.js
Edward Lee 4e55362a90 Bug 570636 - Decide how to co-exist as a sync add-on and built-in sync [r=mconnor]
Map the modules directory to services-sync instead of weave and update imports.
2010-06-16 14:30:08 -07:00

47 lines
1.2 KiB
JavaScript

_("Make sure json saves and loads from disk");
Cu.import("resource://services-sync/util.js");
function run_test() {
_("Do a simple write of an array to json and read");
let foo;
Utils.jsonSave("foo", {}, ["v1", "v2"]);
Utils.jsonLoad("foo", {}, function(val) {
foo = val;
});
do_check_eq(typeof foo, "object");
do_check_eq(foo.length, 2);
do_check_eq(foo[0], "v1");
do_check_eq(foo[1], "v2");
_("Use the function callback version of jsonSave");
let bar;
Utils.jsonSave("bar", {}, function() ["v1", "v2"]);
Utils.jsonLoad("bar", {}, function(val) {
bar = val;
});
do_check_eq(typeof bar, "object");
do_check_eq(bar.length, 2);
do_check_eq(bar[0], "v1");
do_check_eq(bar[1], "v2");
_("Try saving simple strings");
let str;
Utils.jsonSave("str", {}, "hi");
Utils.jsonLoad("str", {}, function(val) {
str = val;
});
do_check_eq(typeof str, "string");
do_check_eq(str.length, 2);
do_check_eq(str[0], "h");
do_check_eq(str[1], "i");
_("Try saving a number");
let num;
Utils.jsonSave("num", {}, function() 42);
Utils.jsonLoad("num", {}, function(val) {
num = val;
});
do_check_eq(typeof num, "number");
do_check_eq(num, 42);
}