1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/services/common/tests/unit/test_utils_json.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,40 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +Cu.import("resource://services-common/utils.js"); 1.8 +Cu.import("resource://gre/modules/osfile.jsm"); 1.9 + 1.10 +function run_test() { 1.11 + initTestLogging(); 1.12 + run_next_test(); 1.13 +} 1.14 + 1.15 +add_test(function test_writeJSON_readJSON() { 1.16 + _("Round-trip some JSON through the promise-based JSON writer."); 1.17 + 1.18 + let contents = { 1.19 + "a": 12345.67, 1.20 + "b": { 1.21 + "c": "héllö", 1.22 + }, 1.23 + "d": undefined, 1.24 + "e": null, 1.25 + }; 1.26 + 1.27 + function checkJSON(json) { 1.28 + do_check_eq(contents.a, json.a); 1.29 + do_check_eq(contents.b.c, json.b.c); 1.30 + do_check_eq(contents.d, json.d); 1.31 + do_check_eq(contents.e, json.e); 1.32 + run_next_test(); 1.33 + }; 1.34 + 1.35 + function doRead() { 1.36 + CommonUtils.readJSON(path) 1.37 + .then(checkJSON, do_throw); 1.38 + } 1.39 + 1.40 + let path = OS.Path.join(OS.Constants.Path.profileDir, "bar.json"); 1.41 + CommonUtils.writeJSON(contents, path) 1.42 + .then(doRead, do_throw); 1.43 +});