toolkit/devtools/server/tests/unit/test_objectgrips-13.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_objectgrips-13.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +// Test that ObjectClient.prototype.getDefinitionSite and the "definitionSite"
     1.8 +// request work properly.
     1.9 +
    1.10 +var gDebuggee;
    1.11 +var gClient;
    1.12 +var gThreadClient;
    1.13 +
    1.14 +function run_test()
    1.15 +{
    1.16 +  initTestDebuggerServer();
    1.17 +  gDebuggee = addTestGlobal("test-grips");
    1.18 +  gDebuggee.eval(function stopMe() {
    1.19 +    debugger;
    1.20 +  }.toString());
    1.21 +
    1.22 +  gClient = new DebuggerClient(DebuggerServer.connectPipe());
    1.23 +  gClient.connect(function() {
    1.24 +    attachTestTabAndResume(gClient, "test-grips", function(aResponse, aTabClient, aThreadClient) {
    1.25 +      gThreadClient = aThreadClient;
    1.26 +      add_pause_listener();
    1.27 +    });
    1.28 +  });
    1.29 +  do_test_pending();
    1.30 +}
    1.31 +
    1.32 +function add_pause_listener()
    1.33 +{
    1.34 +  gThreadClient.addOneTimeListener("paused", function(aEvent, aPacket) {
    1.35 +    const [funcGrip, objGrip] = aPacket.frame.arguments;
    1.36 +    const func = gThreadClient.pauseGrip(funcGrip);
    1.37 +    const obj = gThreadClient.pauseGrip(objGrip);
    1.38 +    test_definition_site(func, obj);
    1.39 +  });
    1.40 +
    1.41 +  eval_code();
    1.42 +}
    1.43 +
    1.44 +function eval_code() {
    1.45 +  gDebuggee.eval([
    1.46 +    "this.line0 = Error().lineNumber;",
    1.47 +    "function f() {}",
    1.48 +    "stopMe(f, {});"
    1.49 +  ].join("\n"));
    1.50 +}
    1.51 +
    1.52 +function test_definition_site(func, obj) {
    1.53 +  func.getDefinitionSite(({ error, url, line, column }) => {
    1.54 +    do_check_true(!error);
    1.55 +    do_check_eq(url, getFilePath("test_objectgrips-13.js"));
    1.56 +    do_check_eq(line, gDebuggee.line0 + 1);
    1.57 +    do_check_eq(column, 0);
    1.58 +
    1.59 +    test_bad_definition_site(obj);
    1.60 +  });
    1.61 +}
    1.62 +
    1.63 +function test_bad_definition_site(obj) {
    1.64 +  try {
    1.65 +    obj._client.request("definitionSite", () => do_check_true(false));
    1.66 +  } catch (e) {
    1.67 +    gThreadClient.resume(() => finishClient(gClient));
    1.68 +  }
    1.69 +}

mercurial