test_sourcemaps-02.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Check basic source map integration with the "sources" packet in the RDP.
  5. */
  6. var gDebuggee;
  7. var gClient;
  8. var gThreadClient;
  9. const {SourceNode} = require("source-map");
  10. function run_test()
  11. {
  12. initTestDebuggerServer();
  13. gDebuggee = addTestGlobal("test-source-map");
  14. gClient = new DebuggerClient(DebuggerServer.connectPipe());
  15. gClient.connect().then(function () {
  16. attachTestTabAndResume(gClient, "test-source-map", function (aResponse, aTabClient, aThreadClient) {
  17. gThreadClient = aThreadClient;
  18. test_simple_source_map();
  19. });
  20. });
  21. do_test_pending();
  22. }
  23. function test_simple_source_map()
  24. {
  25. // Because we are source mapping, we should be notified of a.js, b.js, and
  26. // c.js as sources, and shouldn"t receive abc.js or test_sourcemaps-01.js.
  27. let expectedSources = new Set(["http://example.com/www/js/a.js",
  28. "http://example.com/www/js/b.js",
  29. "http://example.com/www/js/c.js"]);
  30. gClient.addOneTimeListener("paused", function (aEvent, aPacket) {
  31. gThreadClient.getSources(function (aResponse) {
  32. do_check_true(!aResponse.error, "Should not get an error");
  33. for (let s of aResponse.sources) {
  34. do_check_neq(s.url, "http://example.com/www/js/abc.js",
  35. "Shouldn't get the generated source's url.");
  36. expectedSources.delete(s.url);
  37. }
  38. do_check_eq(expectedSources.size, 0,
  39. "Should have found all the expected sources sources by now.");
  40. finishClient(gClient);
  41. });
  42. });
  43. let { code, map } = (new SourceNode(null, null, null, [
  44. new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
  45. new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
  46. new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
  47. new SourceNode(1, 0, "d.js", "debugger;\n")
  48. ])).toStringWithSourceMap({
  49. file: "abc.js",
  50. sourceRoot: "http://example.com/www/js/"
  51. });
  52. code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
  53. Components.utils.evalInSandbox(code, gDebuggee, "1.8",
  54. "http://example.com/www/js/abc.js", 1);
  55. }