services/common/tests/unit/test_utils_json.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial