tor-browser

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

head.js (1850B)


      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) {
     13  for (const name of Object.keys(expected)) {
     14    const expectedValue = expected[name];
     15    const value = object[name];
     16    checkValue(name, value, expectedValue);
     17  }
     18 }
     19 
     20 function checkValue(name, value, expected) {
     21  if (expected === null) {
     22    is(value, null, "'" + name + "' is null");
     23  } else if (value === null) {
     24    ok(false, "'" + name + "' is null");
     25  } else if (value === undefined) {
     26    ok(false, "'" + name + "' is undefined");
     27  } else if (
     28    typeof expected == "string" ||
     29    typeof expected == "number" ||
     30    typeof expected == "boolean"
     31  ) {
     32    is(value, expected, "property '" + name + "'");
     33  } else if (expected instanceof RegExp) {
     34    ok(expected.test(value), name + ": " + expected + " matched " + value);
     35  } else if (Array.isArray(expected)) {
     36    info("checking array for property '" + name + "'");
     37    checkObject(value, expected);
     38  } else if (typeof expected == "object") {
     39    info("checking object for property '" + name + "'");
     40    checkObject(value, expected);
     41  }
     42 }
     43 
     44 function checkHeadersOrCookies(array, expected) {
     45  const foundHeaders = {};
     46 
     47  for (const elem of array) {
     48    if (!(elem.name in expected)) {
     49      continue;
     50    }
     51    foundHeaders[elem.name] = true;
     52    info("checking value of header " + elem.name);
     53    checkValue(elem.name, elem.value, expected[elem.name]);
     54  }
     55 
     56  for (const header in expected) {
     57    if (!(header in foundHeaders)) {
     58      ok(false, header + " was not found");
     59    }
     60  }
     61 }