tor-browser

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

head.js (1584B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 Services.scriptloader.loadSubScript(
      8  "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
      9  this
     10 );
     11 
     12 function checkObject(object, expected, message) {
     13  if (object && object.getGrip) {
     14    object = object.getGrip();
     15  }
     16 
     17  for (const name of Object.keys(expected)) {
     18    const expectedValue = expected[name];
     19    const value = object[name];
     20    checkValue(name, value, expectedValue, message);
     21  }
     22 }
     23 
     24 function checkValue(name, value, expected, message) {
     25  if (message) {
     26    message = ` for '${message}'`;
     27  }
     28 
     29  if (expected === null) {
     30    is(value, null, `'${name}' is null${message}`);
     31  } else if (expected === undefined) {
     32    is(value, expected, `'${name}' is undefined${message}`);
     33  } else if (
     34    typeof expected == "string" ||
     35    typeof expected == "number" ||
     36    typeof expected == "boolean"
     37  ) {
     38    is(value, expected, "property '" + name + "'" + message);
     39  } else if (expected instanceof RegExp) {
     40    ok(
     41      expected.test(value),
     42      name + ": " + expected + " matched " + value + message
     43    );
     44  } else if (Array.isArray(expected)) {
     45    info("checking array for property '" + name + "'" + message);
     46    checkObject(value, expected, message);
     47  } else if (typeof expected == "object") {
     48    info("checking object for property '" + name + "'" + message);
     49    checkObject(value, expected, message);
     50  }
     51 }