|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 Cu.import("resource://services-common/utils.js"); |
|
5 Cu.import("resource://gre/modules/osfile.jsm"); |
|
6 |
|
7 function run_test() { |
|
8 initTestLogging(); |
|
9 run_next_test(); |
|
10 } |
|
11 |
|
12 add_test(function test_writeJSON_readJSON() { |
|
13 _("Round-trip some JSON through the promise-based JSON writer."); |
|
14 |
|
15 let contents = { |
|
16 "a": 12345.67, |
|
17 "b": { |
|
18 "c": "héllö", |
|
19 }, |
|
20 "d": undefined, |
|
21 "e": null, |
|
22 }; |
|
23 |
|
24 function checkJSON(json) { |
|
25 do_check_eq(contents.a, json.a); |
|
26 do_check_eq(contents.b.c, json.b.c); |
|
27 do_check_eq(contents.d, json.d); |
|
28 do_check_eq(contents.e, json.e); |
|
29 run_next_test(); |
|
30 }; |
|
31 |
|
32 function doRead() { |
|
33 CommonUtils.readJSON(path) |
|
34 .then(checkJSON, do_throw); |
|
35 } |
|
36 |
|
37 let path = OS.Path.join(OS.Constants.Path.profileDir, "bar.json"); |
|
38 CommonUtils.writeJSON(contents, path) |
|
39 .then(doRead, do_throw); |
|
40 }); |