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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/server/tests/unit/test_source-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,78 @@
     1.4 +/* -*- Mode: javascript; js-indent-level: 2; -*- */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +var gDebuggee;
     1.9 +var gClient;
    1.10 +var gThreadClient;
    1.11 +
    1.12 +// This test ensures that we can create SourceActors and SourceClients properly,
    1.13 +// and that they can communicate over the protocol to fetch the source text for
    1.14 +// a given script.
    1.15 +
    1.16 +function run_test()
    1.17 +{
    1.18 +  initTestDebuggerServer();
    1.19 +  gDebuggee = addTestGlobal("test-grips");
    1.20 +  Cu.evalInSandbox(
    1.21 +    "" + function stopMe(arg1) {
    1.22 +      debugger;
    1.23 +    },
    1.24 +    gDebuggee,
    1.25 +    "1.8",
    1.26 +    getFileUrl("test_source-01.js")
    1.27 +  );
    1.28 +
    1.29 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.30 +  gClient.connect(function() {
    1.31 +    attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) {
    1.32 +      gThreadClient = aThreadClient;
    1.33 +      test_source();
    1.34 +    });
    1.35 +  });
    1.36 +  do_test_pending();
    1.37 +}
    1.38 +
    1.39 +const SOURCE_URL = "http://example.com/foobar.js";
    1.40 +const SOURCE_CONTENT = "stopMe()";
    1.41 +
    1.42 +function test_source()
    1.43 +{
    1.44 +  DebuggerServer.LONG_STRING_LENGTH = 200;
    1.45 +
    1.46 +  gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) {
    1.47 +    gThreadClient.getSources(function (aResponse) {
    1.48 +      do_check_true(!!aResponse);
    1.49 +      do_check_true(!!aResponse.sources);
    1.50 +
    1.51 +      let source = aResponse.sources.filter(function (s) {
    1.52 +        return s.url === SOURCE_URL;
    1.53 +      })[0];
    1.54 +
    1.55 +      do_check_true(!!source);
    1.56 +
    1.57 +      let sourceClient = gThreadClient.source(source);
    1.58 +      sourceClient.source(function (aResponse) {
    1.59 +        do_check_true(!!aResponse);
    1.60 +        do_check_true(!aResponse.error);
    1.61 +        do_check_true(!!aResponse.contentType);
    1.62 +        do_check_true(aResponse.contentType.contains("javascript"));
    1.63 +
    1.64 +        do_check_true(!!aResponse.source);
    1.65 +        do_check_eq(SOURCE_CONTENT,
    1.66 +                    aResponse.source);
    1.67 +
    1.68 +        gThreadClient.resume(function () {
    1.69 +          finishClient(gClient);
    1.70 +        });
    1.71 +      });
    1.72 +    });
    1.73 +  });
    1.74 +
    1.75 +  Cu.evalInSandbox(
    1.76 +    SOURCE_CONTENT,
    1.77 +    gDebuggee,
    1.78 +    "1.8",
    1.79 +    SOURCE_URL
    1.80 +  );
    1.81 +}

mercurial