tor-browser

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

test_protocol_stack.js (2228B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Client request stacks should span the entire process from before making the
      8 * request to handling the reply from the server.  The server frames are not
      9 * included, nor can they be in most cases, since the server can be a remote
     10 * device.
     11 */
     12 
     13 var protocol = require("resource://devtools/shared/protocol.js");
     14 var { RetVal } = protocol;
     15 
     16 const rootSpec = protocol.generateActorSpec({
     17  typeName: "root",
     18 
     19  methods: {
     20    simpleReturn: {
     21      response: { value: RetVal() },
     22    },
     23  },
     24 });
     25 
     26 class RootActor extends protocol.Actor {
     27  constructor(conn) {
     28    super(conn, rootSpec);
     29 
     30    // Root actor owns itself.
     31    this.manage(this);
     32    this.actorID = "root";
     33    this.sequence = 0;
     34  }
     35 
     36  sayHello() {
     37    return {
     38      from: "root",
     39      applicationType: "xpcshell-tests",
     40      traits: [],
     41    };
     42  }
     43 
     44  simpleReturn() {
     45    return this.sequence++;
     46  }
     47 }
     48 
     49 class RootFront extends protocol.FrontClassWithSpec(rootSpec) {
     50  constructor(client) {
     51    super(client);
     52    this.actorID = "root";
     53    // Root owns itself.
     54    this.manage(this);
     55  }
     56 
     57  connect() {}
     58 }
     59 protocol.registerFront(RootFront);
     60 
     61 function run_test() {
     62  DevToolsServer.createRootActor = conn => new RootActor(conn);
     63  DevToolsServer.init();
     64 
     65  const trace = connectPipeTracing();
     66  const client = new DevToolsClient(trace);
     67  let rootFront;
     68 
     69  client.connect().then(function onConnect() {
     70    rootFront = client.mainRoot;
     71 
     72    rootFront
     73      .simpleReturn()
     74      .then(
     75        () => {
     76          let stack = Components.stack;
     77          while (stack) {
     78            info(stack.name);
     79            if (stack.name.includes("onConnect")) {
     80              // Reached back to outer function before request
     81              ok(true, "Complete stack");
     82              return;
     83            }
     84            stack = stack.asyncCaller || stack.caller;
     85          }
     86          ok(false, "Incomplete stack");
     87        },
     88        () => {
     89          ok(false, "Request failed unexpectedly");
     90        }
     91      )
     92      .then(() => {
     93        client.close().then(() => {
     94          do_test_finished();
     95        });
     96      });
     97  });
     98 
     99  do_test_pending();
    100 }