test_source-01.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*- js-indent-level: 2; indent-tabs-mode: nil -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. http://creativecommons.org/publicdomain/zero/1.0/ */
  4. var gDebuggee;
  5. var gClient;
  6. var gThreadClient;
  7. // This test ensures that we can create SourceActors and SourceClients properly,
  8. // and that they can communicate over the protocol to fetch the source text for
  9. // a given script.
  10. function run_test()
  11. {
  12. initTestDebuggerServer();
  13. gDebuggee = addTestGlobal("test-grips");
  14. Cu.evalInSandbox(
  15. "" + function stopMe(arg1) {
  16. debugger;
  17. },
  18. gDebuggee,
  19. "1.8",
  20. getFileUrl("test_source-01.js")
  21. );
  22. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  23. gClient.connect().then(function () {
  24. attachTestTabAndResume(gClient, "test-grips", function (aResponse, aTabClient, aThreadClient) {
  25. gThreadClient = aThreadClient;
  26. test_source();
  27. });
  28. });
  29. do_test_pending();
  30. }
  31. const SOURCE_URL = "http://example.com/foobar.js";
  32. const SOURCE_CONTENT = "stopMe()";
  33. function test_source()
  34. {
  35. DebuggerServer.LONG_STRING_LENGTH = 200;
  36. gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  37. gThreadClient.getSources(function (aResponse) {
  38. do_check_true(!!aResponse);
  39. do_check_true(!!aResponse.sources);
  40. let source = aResponse.sources.filter(function (s) {
  41. return s.url === SOURCE_URL;
  42. })[0];
  43. do_check_true(!!source);
  44. let sourceClient = gThreadClient.source(source);
  45. sourceClient.source(function (aResponse) {
  46. do_check_true(!!aResponse);
  47. do_check_true(!aResponse.error);
  48. do_check_true(!!aResponse.contentType);
  49. do_check_true(aResponse.contentType.includes("javascript"));
  50. do_check_true(!!aResponse.source);
  51. do_check_eq(SOURCE_CONTENT,
  52. aResponse.source);
  53. gThreadClient.resume(function () {
  54. finishClient(gClient);
  55. });
  56. });
  57. });
  58. });
  59. Cu.evalInSandbox(
  60. SOURCE_CONTENT,
  61. gDebuggee,
  62. "1.8",
  63. SOURCE_URL
  64. );
  65. }