toolkit/devtools/server/tests/unit/test_source-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: javascript; js-indent-level: 2; -*- */
     2 /* Any copyright is dedicated to the Public Domain.
     3    http://creativecommons.org/publicdomain/zero/1.0/ */
     5 var gDebuggee;
     6 var gClient;
     7 var gThreadClient;
     9 // This test ensures that we can create SourceActors and SourceClients properly,
    10 // and that they can communicate over the protocol to fetch the source text for
    11 // a given script.
    13 function run_test()
    14 {
    15   initTestDebuggerServer();
    16   gDebuggee = addTestGlobal("test-grips");
    17   Cu.evalInSandbox(
    18     "" + function stopMe(arg1) {
    19       debugger;
    20     },
    21     gDebuggee,
    22     "1.8",
    23     getFileUrl("test_source-01.js")
    24   );
    26   gClient = new DebuggerClient(DebuggerServer.connectPipe());
    27   gClient.connect(function() {
    28     attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) {
    29       gThreadClient = aThreadClient;
    30       test_source();
    31     });
    32   });
    33   do_test_pending();
    34 }
    36 const SOURCE_URL = "http://example.com/foobar.js";
    37 const SOURCE_CONTENT = "stopMe()";
    39 function test_source()
    40 {
    41   DebuggerServer.LONG_STRING_LENGTH = 200;
    43   gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) {
    44     gThreadClient.getSources(function (aResponse) {
    45       do_check_true(!!aResponse);
    46       do_check_true(!!aResponse.sources);
    48       let source = aResponse.sources.filter(function (s) {
    49         return s.url === SOURCE_URL;
    50       })[0];
    52       do_check_true(!!source);
    54       let sourceClient = gThreadClient.source(source);
    55       sourceClient.source(function (aResponse) {
    56         do_check_true(!!aResponse);
    57         do_check_true(!aResponse.error);
    58         do_check_true(!!aResponse.contentType);
    59         do_check_true(aResponse.contentType.contains("javascript"));
    61         do_check_true(!!aResponse.source);
    62         do_check_eq(SOURCE_CONTENT,
    63                     aResponse.source);
    65         gThreadClient.resume(function () {
    66           finishClient(gClient);
    67         });
    68       });
    69     });
    70   });
    72   Cu.evalInSandbox(
    73     SOURCE_CONTENT,
    74     gDebuggee,
    75     "1.8",
    76     SOURCE_URL
    77   );
    78 }

mercurial