tor-browser

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

test_WorkerDebuggerGlobalScope.reportError.xhtml (3928B)


      1 <?xml version="1.0"?>
      2 <!--
      3  Any copyright is dedicated to the Public Domain.
      4  http://creativecommons.org/publicdomain/zero/1.0/
      5 -->
      6 <window title="Test for WorkerDebuggerGlobalScope.reportError"
      7        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
      8        onload="test();">
      9 
     10  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     11  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
     12  <script type="application/javascript" src="dom_worker_helper.js"/>
     13 
     14  <script type="application/javascript">
     15  <![CDATA[
     16 
     17    const WORKER_URL = "WorkerDebuggerGlobalScope.reportError_worker.js";
     18    const CHILD_WORKER_URL = "WorkerDebuggerGlobalScope.reportError_childWorker.js";
     19    const DEBUGGER_URL = BASE_URL + "WorkerDebuggerGlobalScope.reportError_debugger.js";
     20 
     21    function test() {
     22      (async function() {
     23        SimpleTest.waitForExplicitFinish();
     24 
     25        info("Create a worker that creates a child worker, wait for their " +
     26             "debuggers to be registered, and initialize them.");
     27        let promise = waitForMultiple([
     28          waitForRegister(WORKER_URL, DEBUGGER_URL),
     29          waitForRegister(CHILD_WORKER_URL, DEBUGGER_URL)
     30        ]);
     31        let worker = new Worker(WORKER_URL);
     32        let [dbg, childDbg] = await promise;
     33 
     34        worker.onmessage = function () {
     35          ok(false, "Debugger error events should not be fired at workers.");
     36        };
     37 
     38        info("Send a request to the worker debugger. This should cause the " +
     39             "worker debugger to report an error.");
     40        promise = waitForDebuggerError(dbg);
     41        dbg.postMessage("report");
     42        let error = await promise;
     43        is(error.fileName, DEBUGGER_URL,
     44           "fileName should be name of file from which error is reported.");
     45        is(error.lineNumber, 6,
     46           "lineNumber should be line number from which error is reported.");
     47        is(error.message, "reported", "message should be reported.");
     48 
     49        info("Send a request to the worker debugger. This should cause the " +
     50             "worker debugger to throw an error.");
     51        promise = waitForDebuggerError(dbg);
     52        dbg.postMessage("throw");
     53        error = await promise;
     54        is(error.fileName, DEBUGGER_URL,
     55           "fileName should be name of file from which error is thrown");
     56        is(error.lineNumber, 9,
     57           "lineNumber should be line number from which error is thrown");
     58        is(error.message, "Error: thrown", "message should be Error: thrown");
     59 
     60        info("Send a reqeust to the child worker debugger. This should cause " +
     61             "the child worker debugger to report an error.");
     62        promise = waitForDebuggerError(childDbg);
     63        childDbg.postMessage("report");
     64        error = await promise;
     65        is(error.fileName, DEBUGGER_URL,
     66           "fileName should be name of file from which error is reported.");
     67        is(error.lineNumber, 6,
     68           "lineNumber should be line number from which error is reported.");
     69        is(error.message, "reported", "message should be reported.");
     70 
     71        info("Send a message to the child worker debugger. This should cause " +
     72             "the child worker debugger to throw an error.");
     73        promise = waitForDebuggerError(childDbg);
     74        childDbg.postMessage("throw");
     75        error = await promise;
     76        is(error.fileName, DEBUGGER_URL,
     77           "fileName should be name of file from which error is thrown");
     78        is(error.lineNumber, 9,
     79           "lineNumber should be line number from which error is thrown");
     80        is(error.message, "Error: thrown", "message should be Error: thrown");
     81 
     82        SimpleTest.finish();
     83      })();
     84    }
     85 
     86  ]]>
     87  </script>
     88 
     89  <body xmlns="http://www.w3.org/1999/xhtml">
     90    <p id="display"></p>
     91    <div id="content" style="display:none;"></div>
     92    <pre id="test"></pre>
     93  </body>
     94  <label id="test-result"/>
     95 </window>