tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_utils_deferGetSet.js (1252B)


      1 _(
      2  "Make sure various combinations of deferGetSet arguments correctly defer getting/setting properties to another object"
      3 );
      4 
      5 function run_test() {
      6  let base = function () {};
      7  base.prototype = {
      8    dst: {},
      9 
     10    get a() {
     11      return "a";
     12    },
     13    set b(val) {
     14      this.dst.b = val + "!!!";
     15    },
     16  };
     17  let src = new base();
     18 
     19  _("get/set a single property");
     20  Utils.deferGetSet(base, "dst", "foo");
     21  src.foo = "bar";
     22  Assert.equal(src.dst.foo, "bar");
     23  Assert.equal(src.foo, "bar");
     24 
     25  _("editing the target also updates the source");
     26  src.dst.foo = "baz";
     27  Assert.equal(src.dst.foo, "baz");
     28  Assert.equal(src.foo, "baz");
     29 
     30  _("handle multiple properties");
     31  Utils.deferGetSet(base, "dst", ["p1", "p2"]);
     32  src.p1 = "v1";
     33  src.p2 = "v2";
     34  Assert.equal(src.p1, "v1");
     35  Assert.equal(src.dst.p1, "v1");
     36  Assert.equal(src.p2, "v2");
     37  Assert.equal(src.dst.p2, "v2");
     38 
     39  _("make sure existing getter keeps its functionality");
     40  Utils.deferGetSet(base, "dst", "a");
     41  src.a = "not a";
     42  Assert.equal(src.dst.a, "not a");
     43  Assert.equal(src.a, "a");
     44 
     45  _("make sure existing setter keeps its functionality");
     46  Utils.deferGetSet(base, "dst", "b");
     47  src.b = "b";
     48  Assert.equal(src.dst.b, "b!!!");
     49  Assert.equal(src.b, "b!!!");
     50 }