tor-browser

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

test_utils_deepEquals.js (1512B)


      1 _("Make sure Utils.deepEquals correctly finds items that are deeply equal");
      2 
      3 Services.prefs.setBoolPref("security.allow_eval_with_system_principal", true);
      4 registerCleanupFunction(() => {
      5  Services.prefs.clearUserPref("security.allow_eval_with_system_principal");
      6 });
      7 
      8 function run_test() {
      9  let data =
     10    '[NaN, undefined, null, true, false, Infinity, 0, 1, "a", "b", {a: 1}, {a: "a"}, [{a: 1}], [{a: true}], {a: 1, b: 2}, [1, 2], [1, 2, 3]]';
     11  _("Generating two copies of data:", data);
     12  /* eslint-disable no-eval */
     13  let d1 = eval(data);
     14  let d2 = eval(data);
     15  /* eslint-enable no-eval */
     16 
     17  d1.forEach(function (a) {
     18    _("Testing", a, typeof a, JSON.stringify([a]));
     19    let numMatch = 0;
     20 
     21    d2.forEach(function (b) {
     22      if (Utils.deepEquals(a, b)) {
     23        numMatch++;
     24        _("Found a match", b, typeof b, JSON.stringify([b]));
     25      }
     26    });
     27 
     28    let expect = 1;
     29    if (isNaN(a) && typeof a == "number") {
     30      expect = 0;
     31      _("Checking NaN should result in no matches");
     32    }
     33 
     34    _("Making sure we found the correct # match:", expect);
     35    _("Actual matches:", numMatch);
     36    Assert.equal(numMatch, expect);
     37  });
     38 
     39  _("Make sure adding undefined properties doesn't affect equalness");
     40  let a = {};
     41  let b = { a: undefined };
     42  Assert.ok(Utils.deepEquals(a, b));
     43  a.b = 5;
     44  Assert.ok(!Utils.deepEquals(a, b));
     45  b.b = 5;
     46  Assert.ok(Utils.deepEquals(a, b));
     47  a.c = undefined;
     48  Assert.ok(Utils.deepEquals(a, b));
     49  b.d = undefined;
     50  Assert.ok(Utils.deepEquals(a, b));
     51 }