mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 557591 - Add tests for Utils.deferGetSet.
This commit is contained in:
parent
36f17f2c20
commit
cdf7defc20
52
services/sync/tests/unit/test_utils_deferGetSet.js
Normal file
52
services/sync/tests/unit/test_utils_deferGetSet.js
Normal file
@ -0,0 +1,52 @@
|
||||
_("Make sure various combinations of deferGetSet arguments correctly defer getting/setting properties to another object");
|
||||
Cu.import("resource://weave/util.js");
|
||||
|
||||
function run_test() {
|
||||
let base = function() {};
|
||||
base.prototype = {
|
||||
dst: {},
|
||||
|
||||
get a() "a",
|
||||
set b(val) this.dst.b = val + "!!!"
|
||||
};
|
||||
let src = new base();
|
||||
|
||||
_("get/set a single property");
|
||||
Utils.deferGetSet(base, "dst", "foo");
|
||||
src.foo = "bar";
|
||||
do_check_eq(src.dst.foo, "bar");
|
||||
do_check_eq(src.foo, "bar");
|
||||
|
||||
_("editing the target also updates the source");
|
||||
src.dst.foo = "baz";
|
||||
do_check_eq(src.dst.foo, "baz");
|
||||
do_check_eq(src.foo, "baz");
|
||||
|
||||
_("handle multiple properties");
|
||||
Utils.deferGetSet(base, "dst", ["p1", "p2"]);
|
||||
src.p1 = "v1";
|
||||
src.p2 = "v2";
|
||||
do_check_eq(src.p1, "v1");
|
||||
do_check_eq(src.dst.p1, "v1");
|
||||
do_check_eq(src.p2, "v2");
|
||||
do_check_eq(src.dst.p2, "v2");
|
||||
|
||||
_("handle dotted properties");
|
||||
src.dst.nest = {};
|
||||
Utils.deferGetSet(base, "dst.nest", "prop");
|
||||
src.prop = "val";
|
||||
do_check_eq(src.prop, "val");
|
||||
do_check_eq(src.dst.nest.prop, "val");
|
||||
|
||||
_("make sure existing getter keeps its functionality");
|
||||
Utils.deferGetSet(base, "dst", "a");
|
||||
src.a = "not a";
|
||||
do_check_eq(src.dst.a, "not a");
|
||||
do_check_eq(src.a, "a");
|
||||
|
||||
_("make sure existing setter keeps its functionality");
|
||||
Utils.deferGetSet(base, "dst", "b");
|
||||
src.b = "b";
|
||||
do_check_eq(src.dst.b, "b!!!");
|
||||
do_check_eq(src.b, "b!!!");
|
||||
}
|
Loading…
Reference in New Issue
Block a user