test_blackboxing-01.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Test basic black boxing.
  5. */
  6. var gDebuggee;
  7. var gClient;
  8. var gThreadClient;
  9. function run_test()
  10. {
  11. initTestDebuggerServer();
  12. gDebuggee = addTestGlobal("test-black-box");
  13. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  14. gClient.connect().then(function () {
  15. attachTestTabAndResume(gClient, "test-black-box", function (aResponse, aTabClient, aThreadClient) {
  16. gThreadClient = aThreadClient;
  17. testBlackBox();
  18. });
  19. });
  20. do_test_pending();
  21. }
  22. const BLACK_BOXED_URL = "http://example.com/blackboxme.js";
  23. const SOURCE_URL = "http://example.com/source.js";
  24. const testBlackBox = Task.async(function* () {
  25. let packet = yield executeOnNextTickAndWaitForPause(evalCode, gClient);
  26. let source = gThreadClient.source(packet.frame.where.source);
  27. yield setBreakpoint(source, {
  28. line: 2
  29. });
  30. yield resume(gThreadClient);
  31. const { sources } = yield getSources(gThreadClient);
  32. let sourceClient = gThreadClient.source(
  33. sources.filter(s => s.url == BLACK_BOXED_URL)[0]);
  34. do_check_true(!sourceClient.isBlackBoxed,
  35. "By default the source is not black boxed.");
  36. // Test that we can step into `doStuff` when we are not black boxed.
  37. yield runTest(
  38. function onSteppedLocation(aLocation) {
  39. do_check_eq(aLocation.source.url, BLACK_BOXED_URL);
  40. do_check_eq(aLocation.line, 2);
  41. },
  42. function onDebuggerStatementFrames(aFrames) {
  43. do_check_true(!aFrames.some(f => f.where.source.isBlackBoxed));
  44. }
  45. );
  46. let blackBoxResponse = yield blackBox(sourceClient);
  47. do_check_true(sourceClient.isBlackBoxed);
  48. // Test that we step through `doStuff` when we are black boxed and its frame
  49. // doesn't show up.
  50. yield runTest(
  51. function onSteppedLocation(aLocation) {
  52. do_check_eq(aLocation.source.url, SOURCE_URL);
  53. do_check_eq(aLocation.line, 4);
  54. },
  55. function onDebuggerStatementFrames(aFrames) {
  56. for (let f of aFrames) {
  57. if (f.where.source.url == BLACK_BOXED_URL) {
  58. do_check_true(f.where.source.isBlackBoxed);
  59. } else {
  60. do_check_true(!f.where.source.isBlackBoxed);
  61. }
  62. }
  63. }
  64. );
  65. let unBlackBoxResponse = yield unBlackBox(sourceClient);
  66. do_check_true(!sourceClient.isBlackBoxed);
  67. // Test that we can step into `doStuff` again.
  68. yield runTest(
  69. function onSteppedLocation(aLocation) {
  70. do_check_eq(aLocation.source.url, BLACK_BOXED_URL);
  71. do_check_eq(aLocation.line, 2);
  72. },
  73. function onDebuggerStatementFrames(aFrames) {
  74. do_check_true(!aFrames.some(f => f.where.source.isBlackBoxed));
  75. }
  76. );
  77. finishClient(gClient);
  78. });
  79. function evalCode() {
  80. Components.utils.evalInSandbox(
  81. "" + function doStuff(k) { // line 1
  82. let arg = 15; // line 2 - Step in here
  83. k(arg); // line 3
  84. }, // line 4
  85. gDebuggee,
  86. "1.8",
  87. BLACK_BOXED_URL,
  88. 1
  89. );
  90. Components.utils.evalInSandbox(
  91. "" + function runTest() { // line 1
  92. doStuff( // line 2 - Break here
  93. function (n) { // line 3 - Step through `doStuff` to here
  94. debugger; // line 4
  95. } // line 5
  96. ); // line 6
  97. } + "\n" // line 7
  98. + "debugger;", // line 8
  99. gDebuggee,
  100. "1.8",
  101. SOURCE_URL,
  102. 1
  103. );
  104. }
  105. const runTest = Task.async(function* (onSteppedLocation, onDebuggerStatementFrames) {
  106. let packet = yield executeOnNextTickAndWaitForPause(gDebuggee.runTest,
  107. gClient);
  108. do_check_eq(packet.why.type, "breakpoint");
  109. yield stepIn(gClient, gThreadClient);
  110. yield stepIn(gClient, gThreadClient);
  111. yield stepIn(gClient, gThreadClient);
  112. const location = yield getCurrentLocation();
  113. onSteppedLocation(location);
  114. packet = yield resumeAndWaitForPause(gClient, gThreadClient);
  115. do_check_eq(packet.why.type, "debuggerStatement");
  116. let { frames } = yield getFrames(gThreadClient, 0, 100);
  117. onDebuggerStatementFrames(frames);
  118. return resume(gThreadClient);
  119. });
  120. const getCurrentLocation = Task.async(function* () {
  121. const response = yield getFrames(gThreadClient, 0, 1);
  122. return response.frames[0].where;
  123. });