michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://services-common/utils.js"); michael@0: Cu.import("resource://gre/modules/osfile.jsm"); michael@0: michael@0: function run_test() { michael@0: initTestLogging(); michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function test_writeJSON_readJSON() { michael@0: _("Round-trip some JSON through the promise-based JSON writer."); michael@0: michael@0: let contents = { michael@0: "a": 12345.67, michael@0: "b": { michael@0: "c": "héllö", michael@0: }, michael@0: "d": undefined, michael@0: "e": null, michael@0: }; michael@0: michael@0: function checkJSON(json) { michael@0: do_check_eq(contents.a, json.a); michael@0: do_check_eq(contents.b.c, json.b.c); michael@0: do_check_eq(contents.d, json.d); michael@0: do_check_eq(contents.e, json.e); michael@0: run_next_test(); michael@0: }; michael@0: michael@0: function doRead() { michael@0: CommonUtils.readJSON(path) michael@0: .then(checkJSON, do_throw); michael@0: } michael@0: michael@0: let path = OS.Path.join(OS.Constants.Path.profileDir, "bar.json"); michael@0: CommonUtils.writeJSON(contents, path) michael@0: .then(doRead, do_throw); michael@0: });