test_protocol_abort.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Outstanding requests should be rejected when the connection aborts
  5. * unexpectedly.
  6. */
  7. var protocol = require("devtools/shared/protocol");
  8. var {Arg, Option, RetVal} = protocol;
  9. var events = require("sdk/event/core");
  10. function simpleHello() {
  11. return {
  12. from: "root",
  13. applicationType: "xpcshell-tests",
  14. traits: [],
  15. };
  16. }
  17. const rootSpec = protocol.generateActorSpec({
  18. typeName: "root",
  19. methods: {
  20. simpleReturn: {
  21. response: { value: RetVal() }
  22. }
  23. }
  24. });
  25. var RootActor = protocol.ActorClassWithSpec(rootSpec, {
  26. typeName: "root",
  27. initialize: function (conn) {
  28. protocol.Actor.prototype.initialize.call(this, conn);
  29. // Root actor owns itself.
  30. this.manage(this);
  31. this.actorID = "root";
  32. this.sequence = 0;
  33. },
  34. sayHello: simpleHello,
  35. simpleReturn: function () {
  36. return this.sequence++;
  37. }
  38. });
  39. var RootFront = protocol.FrontClassWithSpec(rootSpec, {
  40. initialize: function (client) {
  41. this.actorID = "root";
  42. protocol.Front.prototype.initialize.call(this, client);
  43. // Root owns itself.
  44. this.manage(this);
  45. }
  46. });
  47. function run_test() {
  48. DebuggerServer.createRootActor = RootActor;
  49. DebuggerServer.init();
  50. let trace = connectPipeTracing();
  51. let client = new DebuggerClient(trace);
  52. let rootClient;
  53. client.connect().then(([applicationType, traits]) => {
  54. rootClient = RootFront(client);
  55. rootClient.simpleReturn().then(() => {
  56. ok(false, "Connection was aborted, request shouldn't resolve");
  57. do_test_finished();
  58. }, e => {
  59. let error = e.toString();
  60. ok(true, "Connection was aborted, request rejected correctly");
  61. ok(error.includes("Request stack:"), "Error includes request stack");
  62. ok(error.includes("test_protocol_abort.js"), "Stack includes this test");
  63. do_test_finished();
  64. });
  65. trace.close();
  66. });
  67. do_test_pending();
  68. }