diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /services/sync/tests/unit/test_utils_deferGetSet.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'services/sync/tests/unit/test_utils_deferGetSet.js')
-rw-r--r-- | services/sync/tests/unit/test_utils_deferGetSet.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/services/sync/tests/unit/test_utils_deferGetSet.js b/services/sync/tests/unit/test_utils_deferGetSet.js new file mode 100644 index 0000000000..6db812b844 --- /dev/null +++ b/services/sync/tests/unit/test_utils_deferGetSet.js @@ -0,0 +1,50 @@ +_( + "Make sure various combinations of deferGetSet arguments correctly defer getting/setting properties to another object" +); + +function run_test() { + let base = function () {}; + base.prototype = { + dst: {}, + + get a() { + return "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"; + Assert.equal(src.dst.foo, "bar"); + Assert.equal(src.foo, "bar"); + + _("editing the target also updates the source"); + src.dst.foo = "baz"; + Assert.equal(src.dst.foo, "baz"); + Assert.equal(src.foo, "baz"); + + _("handle multiple properties"); + Utils.deferGetSet(base, "dst", ["p1", "p2"]); + src.p1 = "v1"; + src.p2 = "v2"; + Assert.equal(src.p1, "v1"); + Assert.equal(src.dst.p1, "v1"); + Assert.equal(src.p2, "v2"); + Assert.equal(src.dst.p2, "v2"); + + _("make sure existing getter keeps its functionality"); + Utils.deferGetSet(base, "dst", "a"); + src.a = "not a"; + Assert.equal(src.dst.a, "not a"); + Assert.equal(src.a, "a"); + + _("make sure existing setter keeps its functionality"); + Utils.deferGetSet(base, "dst", "b"); + src.b = "b"; + Assert.equal(src.dst.b, "b!!!"); + Assert.equal(src.b, "b!!!"); +} |