tor-browser

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

GleanTest.js (1601B)


      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 // This file is a copy of testing/mochitest/tests/SimpleTest/GleanTest.js,
      8 // as WPT does not serve SimpleTest.
      9 
     10 var GleanTest;
     11 (function () {
     12  async function testResetFOG() {
     13    return SpecialPowers.spawnChrome([], async () => {
     14      await Services.fog.testFlushAllChildren();
     15      Services.fog.testResetFOG();
     16    });
     17  }
     18 
     19  async function flush() {
     20    return SpecialPowers.spawnChrome([], async () => {
     21      await Services.fog.testFlushAllChildren();
     22    });
     23  }
     24 
     25  async function testGetValue(chain) {
     26    return SpecialPowers.spawnChrome([chain], async chain => {
     27      await Services.fog.testFlushAllChildren();
     28      const window = this.browsingContext.topChromeWindow;
     29      let glean = window.Glean;
     30      while (chain.length) {
     31        glean = glean[chain.shift()];
     32      }
     33      return glean.testGetValue();
     34    });
     35  }
     36 
     37  function recurse(chain = []) {
     38    return new Proxy(
     39      {},
     40      {
     41        get(_, prop) {
     42          if (chain.length === 0) {
     43            if (prop === "testResetFOG") {
     44              return testResetFOG;
     45            } else if (prop === "flush") {
     46              return flush;
     47            }
     48          }
     49          if (chain.length >= 2 && prop === "testGetValue") {
     50            return () => testGetValue(chain);
     51          }
     52          return recurse(chain.concat(prop));
     53        },
     54      }
     55    );
     56  }
     57 
     58  window.GleanTest = recurse();
     59 })();