tor-browser

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

test_protocol_abort.js (1794B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Outstanding requests should be rejected when the connection aborts
      8 * unexpectedly.
      9 */
     10 
     11 var protocol = require("resource://devtools/shared/protocol.js");
     12 var { RetVal } = protocol;
     13 
     14 const rootSpec = protocol.generateActorSpec({
     15  typeName: "root",
     16 
     17  methods: {
     18    simpleReturn: {
     19      response: { value: RetVal() },
     20    },
     21  },
     22 });
     23 
     24 class RootActor extends protocol.Actor {
     25  constructor(conn) {
     26    super(conn, rootSpec);
     27 
     28    // Root actor owns itself.
     29    this.manage(this);
     30    this.actorID = "root";
     31    this.sequence = 0;
     32  }
     33 
     34  sayHello() {
     35    return {
     36      from: "root",
     37      applicationType: "xpcshell-tests",
     38      traits: [],
     39    };
     40  }
     41 
     42  simpleReturn() {
     43    return this.sequence++;
     44  }
     45 }
     46 
     47 class RootFront extends protocol.FrontClassWithSpec(rootSpec) {
     48  constructor(client) {
     49    super(client);
     50    this.actorID = "root";
     51    // Root owns itself.
     52    this.manage(this);
     53  }
     54 
     55  connect() {}
     56 }
     57 protocol.registerFront(RootFront);
     58 
     59 add_task(async function () {
     60  DevToolsServer.createRootActor = conn => new RootActor(conn);
     61  DevToolsServer.init();
     62 
     63  const trace = connectPipeTracing();
     64  const client = new DevToolsClient(trace);
     65  await client.connect();
     66 
     67  const rootFront = client.mainRoot;
     68 
     69  const onSimpleReturn = rootFront.simpleReturn();
     70  trace.close();
     71 
     72  try {
     73    await onSimpleReturn;
     74    ok(false, "Connection was aborted, request shouldn't resolve");
     75  } catch (e) {
     76    const error = e.toString();
     77    ok(true, "Connection was aborted, request rejected correctly");
     78    ok(error.includes("Request stack:"), "Error includes request stack");
     79    ok(error.includes("test_protocol_abort.js"), "Stack includes this test");
     80  }
     81 });