tor-browser

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

test_RemoteSettingsCrashPull.js (2418B)


      1 /* Any copyright is dedicated to the Public Domain.
      2 http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 const lazy = {};
      7 ChromeUtils.defineESModuleGetters(lazy, {
      8  RemoteSettings: "resource://services-settings/remote-settings.sys.mjs",
      9  RemoteSettingsCrashPull:
     10    "resource://gre/modules/RemoteSettingsCrashPull.sys.mjs",
     11  EventDispatcher: "resource://gre/modules/Messaging.sys.mjs",
     12  makeFakeAppDir: "resource://testing-common/AppData.sys.mjs",
     13 });
     14 
     15 const kRemoteSettingsCollectionName = "crash-reports-ondemand";
     16 
     17 add_setup(async function () {
     18  await lazy.makeFakeAppDir();
     19 });
     20 
     21 add_task(
     22  async function test_remoteSettingsGeneratesCorrectEvent_whenAttached() {
     23    let listener;
     24    const crashPullPromise = new Promise(resolve => {
     25      listener = {
     26        onEvent(aEvent, aData) {
     27          resolve([aEvent, aData]);
     28        },
     29      };
     30    });
     31    lazy.EventDispatcher.instance.registerListener(listener, [
     32      "GeckoView:RemoteSettingsCrashPull",
     33    ]);
     34 
     35    const oldCheckForInterestingUnsubmittedCrash =
     36      lazy.RemoteSettingsCrashPull.checkForInterestingUnsubmittedCrash;
     37    lazy.RemoteSettingsCrashPull.checkForInterestingUnsubmittedCrash =
     38      async _ => {
     39        return ["989df240-a40c-405a-9a22-f2fc4a31db6c"];
     40      };
     41 
     42    lazy.EventDispatcher.instance.dispatch(
     43      "GeckoView:CrashPullController.Delegate:Attached",
     44      undefined,
     45      undefined,
     46      undefined
     47    );
     48 
     49    const payload = {
     50      current: [],
     51      created: [
     52        {
     53          hashes: [
     54            // value here is not important
     55            "2435191bfd64cf0c8cbf0397f1cb5654f778388a3be72cb01502196896f5a0e9",
     56          ],
     57        },
     58      ],
     59      updated: [],
     60      deleted: [],
     61    };
     62 
     63    await lazy.RemoteSettings(kRemoteSettingsCollectionName).emit("sync", {
     64      data: payload,
     65    });
     66 
     67    const [aEvent, aData] = await crashPullPromise;
     68    Assert.equal(
     69      "GeckoView:RemoteSettingsCrashPull",
     70      aEvent,
     71      "expected a remote settings crash pull"
     72    );
     73    Assert.equal(
     74      1,
     75      aData.crashIDs.length,
     76      `expected one crash ID, but got ${aData.crashIDs.length}`
     77    );
     78    Assert.ok(
     79      aData.crashIDs[0].includes(
     80        "pending/989df240-a40c-405a-9a22-f2fc4a31db6c.dmp"
     81      ),
     82      "build path for crash dump"
     83    );
     84 
     85    lazy.RemoteSettingsCrashPull.checkForInterestingUnsubmittedCrash =
     86      oldCheckForInterestingUnsubmittedCrash;
     87  }
     88 );