michael@0: _("Make sure various combinations of deferGetSet arguments correctly defer getting/setting properties to another object"); michael@0: Cu.import("resource://services-sync/util.js"); michael@0: michael@0: function run_test() { michael@0: let base = function() {}; michael@0: base.prototype = { michael@0: dst: {}, michael@0: michael@0: get a() "a", michael@0: set b(val) this.dst.b = val + "!!!" michael@0: }; michael@0: let src = new base(); michael@0: michael@0: _("get/set a single property"); michael@0: Utils.deferGetSet(base, "dst", "foo"); michael@0: src.foo = "bar"; michael@0: do_check_eq(src.dst.foo, "bar"); michael@0: do_check_eq(src.foo, "bar"); michael@0: michael@0: _("editing the target also updates the source"); michael@0: src.dst.foo = "baz"; michael@0: do_check_eq(src.dst.foo, "baz"); michael@0: do_check_eq(src.foo, "baz"); michael@0: michael@0: _("handle multiple properties"); michael@0: Utils.deferGetSet(base, "dst", ["p1", "p2"]); michael@0: src.p1 = "v1"; michael@0: src.p2 = "v2"; michael@0: do_check_eq(src.p1, "v1"); michael@0: do_check_eq(src.dst.p1, "v1"); michael@0: do_check_eq(src.p2, "v2"); michael@0: do_check_eq(src.dst.p2, "v2"); michael@0: michael@0: _("make sure existing getter keeps its functionality"); michael@0: Utils.deferGetSet(base, "dst", "a"); michael@0: src.a = "not a"; michael@0: do_check_eq(src.dst.a, "not a"); michael@0: do_check_eq(src.a, "a"); michael@0: michael@0: _("make sure existing setter keeps its functionality"); michael@0: Utils.deferGetSet(base, "dst", "b"); michael@0: src.b = "b"; michael@0: do_check_eq(src.dst.b, "b!!!"); michael@0: do_check_eq(src.b, "b!!!"); michael@0: }