test_protocol_stack.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Client request stacks should span the entire process from before making the
  6. * request to handling the reply from the server. The server frames are not
  7. * included, nor can they be in most cases, since the server can be a remote
  8. * device.
  9. */
  10. var protocol = require("devtools/shared/protocol");
  11. var {Arg, Option, RetVal} = protocol;
  12. var events = require("sdk/event/core");
  13. function simpleHello() {
  14. return {
  15. from: "root",
  16. applicationType: "xpcshell-tests",
  17. traits: [],
  18. };
  19. }
  20. const rootSpec = protocol.generateActorSpec({
  21. typeName: "root",
  22. methods: {
  23. simpleReturn: {
  24. response: { value: RetVal() },
  25. }
  26. }
  27. });
  28. var RootActor = protocol.ActorClassWithSpec(rootSpec, {
  29. initialize: function (conn) {
  30. protocol.Actor.prototype.initialize.call(this, conn);
  31. // Root actor owns itself.
  32. this.manage(this);
  33. this.actorID = "root";
  34. this.sequence = 0;
  35. },
  36. sayHello: simpleHello,
  37. simpleReturn: function () {
  38. return this.sequence++;
  39. }
  40. });
  41. var RootFront = protocol.FrontClassWithSpec(rootSpec, {
  42. initialize: function (client) {
  43. this.actorID = "root";
  44. protocol.Front.prototype.initialize.call(this, client);
  45. // Root owns itself.
  46. this.manage(this);
  47. }
  48. });
  49. function run_test() {
  50. if (!Services.prefs.getBoolPref("javascript.options.asyncstack")) {
  51. do_print("Async stacks are disabled.");
  52. return;
  53. }
  54. DebuggerServer.createRootActor = RootActor;
  55. DebuggerServer.init();
  56. let trace = connectPipeTracing();
  57. let client = new DebuggerClient(trace);
  58. let rootClient;
  59. client.connect().then(function onConnect() {
  60. rootClient = RootFront(client);
  61. rootClient.simpleReturn().then(() => {
  62. let stack = Components.stack;
  63. while (stack) {
  64. do_print(stack.name);
  65. if (stack.name == "onConnect") {
  66. // Reached back to outer function before request
  67. ok(true, "Complete stack");
  68. return;
  69. }
  70. stack = stack.asyncCaller || stack.caller;
  71. }
  72. ok(false, "Incomplete stack");
  73. }, () => {
  74. ok(false, "Request failed unexpectedly");
  75. }).then(() => {
  76. client.close().then(() => {
  77. do_test_finished();
  78. });
  79. });
  80. });
  81. do_test_pending();
  82. }