tor-browser

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

ASRouterChild.test.js (1929B)


      1 /*eslint max-nested-callbacks: ["error", 10]*/
      2 import { ASRouterChild } from "actors/ASRouterChild.sys.mjs";
      3 import { MESSAGE_TYPE_HASH as msg } from "modules/ActorConstants.mjs";
      4 
      5 describe("ASRouterChild", () => {
      6  let asRouterChild = null;
      7  let sandbox = null;
      8  beforeEach(() => {
      9    sandbox = sinon.createSandbox();
     10    asRouterChild = new ASRouterChild();
     11    asRouterChild.telemetry = {
     12      sendTelemetry: sandbox.stub(),
     13    };
     14    sandbox.stub(asRouterChild, "sendAsyncMessage");
     15    sandbox.stub(asRouterChild, "sendQuery").returns(Promise.resolve());
     16  });
     17  afterEach(() => {
     18    sandbox.restore();
     19    asRouterChild = null;
     20  });
     21  describe("asRouterMessage", () => {
     22    describe("uses sendAsyncMessage for types that don't need an async response", () => {
     23      [
     24        msg.DISABLE_PROVIDER,
     25        msg.ENABLE_PROVIDER,
     26        msg.EXPIRE_QUERY_CACHE,
     27        msg.IMPRESSION,
     28        msg.RESET_PROVIDER_PREF,
     29        msg.SET_PROVIDER_USER_PREF,
     30        msg.USER_ACTION,
     31      ].forEach(type => {
     32        it(`type ${type}`, () => {
     33          asRouterChild.asRouterMessage({
     34            type,
     35            data: {
     36              something: 1,
     37            },
     38          });
     39          sandbox.assert.calledOnce(asRouterChild.sendAsyncMessage);
     40          sandbox.assert.calledWith(asRouterChild.sendAsyncMessage, type, {
     41            something: 1,
     42          });
     43        });
     44      });
     45    });
     46    // Some legacy privileged extensions still send this legacy NEWTAB_MESSAGE_REQUEST
     47    // action type. We simply
     48    it("can accept the legacy NEWTAB_MESSAGE_REQUEST message without throwing", async () => {
     49      assert.doesNotThrow(async () => {
     50        let result = await asRouterChild.asRouterMessage({
     51          type: "NEWTAB_MESSAGE_REQUEST",
     52          data: {},
     53        });
     54        sandbox.assert.deepEqual(result, {});
     55        sandbox.assert.notCalled(asRouterChild.sendAsyncMessage);
     56      });
     57    });
     58  });
     59 });