browser_dbg_source-maps-03.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. /**
  5. * Test that we can debug minified javascript with source maps.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_minified.html";
  8. const JS_URL = EXAMPLE_URL + "code_math.js";
  9. var gTab, gPanel, gDebugger;
  10. var gEditor, gSources, gFrames;
  11. function test() {
  12. let options = {
  13. source: JS_URL,
  14. line: 1
  15. };
  16. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  17. gTab = aTab;
  18. gPanel = aPanel;
  19. gDebugger = gPanel.panelWin;
  20. gEditor = gDebugger.DebuggerView.editor;
  21. gSources = gDebugger.DebuggerView.Sources;
  22. gFrames = gDebugger.DebuggerView.StackFrames;
  23. checkInitialSource()
  24. testSetBreakpoint()
  25. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  26. .then(null, aError => {
  27. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  28. });
  29. });
  30. }
  31. function checkInitialSource() {
  32. isnot(gSources.selectedItem.attachment.source.url.indexOf(".js"), -1,
  33. "The debugger should not show the minified js file.");
  34. is(gSources.selectedItem.attachment.source.url.indexOf(".min.js"), -1,
  35. "The debugger should show the original js file.");
  36. is(gEditor.getText().split("\n").length, 46,
  37. "The debugger's editor should have the original source displayed, " +
  38. "not the whitespace stripped minified version.");
  39. }
  40. function testSetBreakpoint() {
  41. let deferred = promise.defer();
  42. let sourceForm = getSourceForm(gSources, JS_URL);
  43. let source = gDebugger.gThreadClient.source(sourceForm);
  44. source.setBreakpoint({ line: 30 }, aResponse => {
  45. ok(!aResponse.error,
  46. "Should be able to set a breakpoint in a js file.");
  47. ok(!aResponse.actualLocation,
  48. "Should be able to set a breakpoint on line 30.");
  49. gDebugger.gClient.addOneTimeListener("resumed", () => {
  50. waitForCaretAndScopes(gPanel, 30).then(() => {
  51. // Make sure that we have the right stack frames.
  52. is(gFrames.itemCount, 9,
  53. "Should have nine frames.");
  54. is(gFrames.getItemAtIndex(0).attachment.url.indexOf(".min.js"), -1,
  55. "First frame should not be a minified JS frame.");
  56. isnot(gFrames.getItemAtIndex(0).attachment.url.indexOf(".js"), -1,
  57. "First frame should be a JS frame.");
  58. deferred.resolve();
  59. });
  60. // This will cause the breakpoint to be hit, and put us back in the
  61. // paused state.
  62. callInTab(gTab, "arithmetic");
  63. });
  64. });
  65. return deferred.promise;
  66. }
  67. registerCleanupFunction(function () {
  68. gTab = null;
  69. gPanel = null;
  70. gDebugger = null;
  71. gEditor = null;
  72. gSources = null;
  73. gFrames = null;
  74. });