tor-browser

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

test_breakpoint-25.js (2411B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 /**
      7 * Ensure that the debugger resume page execution when the connection drops
      8 * and when the target is detached.
      9 */
     10 
     11 add_task(
     12  threadFrontTest(({ threadFront, debuggee, targetFront }) => {
     13    return new Promise(resolve => {
     14      (async () => {
     15        await executeOnNextTickAndWaitForPause(evalCode, threadFront);
     16 
     17        ok(true, "The page is paused");
     18        ok(!debuggee.foo, "foo is still false after we hit the breakpoint");
     19 
     20        await targetFront.detach();
     21 
     22        // Closing the connection will force the thread actor to resume page
     23        // execution
     24        ok(debuggee.foo, "foo is true after target's detach request");
     25 
     26        resolve();
     27      })();
     28 
     29      function evalCode() {
     30        /* eslint-disable */
     31        Cu.evalInSandbox("var foo = false;\n", debuggee);
     32        /* eslint-enable */
     33        ok(!debuggee.foo, "foo is false at startup");
     34 
     35        /* eslint-disable */
     36        Cu.evalInSandbox("debugger;\n" + "foo = true;\n", debuggee);
     37        /* eslint-enable */
     38      }
     39    });
     40  })
     41 );
     42 
     43 add_task(
     44  threadFrontTest(({ threadFront, client, debuggee }) => {
     45    return new Promise(resolve => {
     46      (async () => {
     47        await executeOnNextTickAndWaitForPause(evalCode, threadFront);
     48 
     49        ok(true, "The page is paused");
     50        ok(!debuggee.foo, "foo is still false after we hit the breakpoint");
     51 
     52        await client.close();
     53 
     54        // `close` will force the destruction of the thread actor, which,
     55        // will resume the page execution. But all of that seems to be
     56        // synchronous and we have to spin the event loop in order to ensure
     57        // having the content javascript to execute the resumed code.
     58        await new Promise(executeSoon);
     59 
     60        // Closing the connection will force the thread actor to resume page
     61        // execution
     62        ok(debuggee.foo, "foo is true after client close");
     63        executeSoon(resolve);
     64        dump("resolved\n");
     65      })();
     66 
     67      function evalCode() {
     68        /* eslint-disable */
     69        Cu.evalInSandbox("var foo = false;\n", debuggee);
     70        /* eslint-enable */
     71        ok(!debuggee.foo, "foo is false at startup");
     72 
     73        /* eslint-disable */
     74        Cu.evalInSandbox("debugger;\n" + "foo = true;\n", debuggee);
     75        /* eslint-enable */
     76      }
     77    });
     78  })
     79 );