PageRenderTime 22ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/services/sync/tests/unit/test_utils_deferGetSet.js

http://github.com/zpao/v8monkey
JavaScript | 45 lines | 38 code | 7 blank | 0 comment | 0 complexity | e51c4d4e4dd0b5994527fa4ff3212366 MD5 | raw file
 1_("Make sure various combinations of deferGetSet arguments correctly defer getting/setting properties to another object");
 2Cu.import("resource://services-sync/util.js");
 3
 4function run_test() {
 5  let base = function() {};
 6  base.prototype = {
 7    dst: {},
 8
 9    get a() "a",
10    set b(val) this.dst.b = val + "!!!"
11  };
12  let src = new base();
13
14  _("get/set a single property");
15  Utils.deferGetSet(base, "dst", "foo");
16  src.foo = "bar";
17  do_check_eq(src.dst.foo, "bar");
18  do_check_eq(src.foo, "bar");
19
20  _("editing the target also updates the source");
21  src.dst.foo = "baz";
22  do_check_eq(src.dst.foo, "baz");
23  do_check_eq(src.foo, "baz");
24
25  _("handle multiple properties");
26  Utils.deferGetSet(base, "dst", ["p1", "p2"]);
27  src.p1 = "v1";
28  src.p2 = "v2";
29  do_check_eq(src.p1, "v1");
30  do_check_eq(src.dst.p1, "v1");
31  do_check_eq(src.p2, "v2");
32  do_check_eq(src.dst.p2, "v2");
33
34  _("make sure existing getter keeps its functionality");
35  Utils.deferGetSet(base, "dst", "a");
36  src.a = "not a";
37  do_check_eq(src.dst.a, "not a");
38  do_check_eq(src.a, "a");
39
40  _("make sure existing setter keeps its functionality");
41  Utils.deferGetSet(base, "dst", "b");
42  src.b = "b";
43  do_check_eq(src.dst.b, "b!!!");
44  do_check_eq(src.b, "b!!!");
45}