toolkit/devtools/server/tests/unit/test_listsources-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_listsources-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,58 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Check basic getSources functionality.
     1.9 + */
    1.10 +
    1.11 +var gDebuggee;
    1.12 +var gClient;
    1.13 +var gThreadClient;
    1.14 +
    1.15 +var gNumTimesSourcesSent = 0;
    1.16 +
    1.17 +function run_test()
    1.18 +{
    1.19 +  initTestDebuggerServer();
    1.20 +  gDebuggee = addTestGlobal("test-stack");
    1.21 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.22 +  gClient.request = (function (request) {
    1.23 +    return function (aRequest, aOnResponse) {
    1.24 +      if (aRequest.type === "sources") {
    1.25 +        ++gNumTimesSourcesSent;
    1.26 +      }
    1.27 +      return request.call(this, aRequest, aOnResponse);
    1.28 +    };
    1.29 +  }(gClient.request));
    1.30 +  gClient.connect(function () {
    1.31 +    attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) {
    1.32 +      gThreadClient = aThreadClient;
    1.33 +      test_simple_listsources();
    1.34 +    });
    1.35 +  });
    1.36 +  do_test_pending();
    1.37 +}
    1.38 +
    1.39 +function test_simple_listsources()
    1.40 +{
    1.41 +  gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
    1.42 +    gThreadClient.getSources(function (aResponse) {
    1.43 +      do_check_true(aResponse.sources.some(function (s) {
    1.44 +        return s.url.match(/test_listsources-01.js$/);
    1.45 +      }));
    1.46 +
    1.47 +      do_check_true(gNumTimesSourcesSent <= 1,
    1.48 +                    "Should only send one sources request at most, even though we"
    1.49 +                    + " might have had to send one to determine feature support.");
    1.50 +
    1.51 +      gThreadClient.resume(function () {
    1.52 +        finishClient(gClient);
    1.53 +      });
    1.54 +    });
    1.55 +  });
    1.56 +
    1.57 +  gDebuggee.eval("var line0 = Error().lineNumber;\n" +
    1.58 +       "debugger;\n" +   // line0 + 1
    1.59 +       "var a = 1;\n" +  // line0 + 2
    1.60 +       "var b = 2;\n");  // line0 + 3
    1.61 +}

mercurial