test_sourcemaps-01.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "newSource" 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. gThreadClient.addListener("newSource", function _onNewSource(aEvent, aPacket) {
  31. do_check_eq(aEvent, "newSource");
  32. do_check_eq(aPacket.type, "newSource");
  33. do_check_true(!!aPacket.source);
  34. do_check_true(expectedSources.has(aPacket.source.url),
  35. "The source url should be one of our original sources.");
  36. expectedSources.delete(aPacket.source.url);
  37. if (expectedSources.size === 0) {
  38. gClient.removeListener("newSource", _onNewSource);
  39. finishClient(gClient);
  40. }
  41. });
  42. let { code, map } = (new SourceNode(null, null, null, [
  43. new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
  44. new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
  45. new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
  46. ])).toStringWithSourceMap({
  47. file: "abc.js",
  48. sourceRoot: "http://example.com/www/js/"
  49. });
  50. code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
  51. Components.utils.evalInSandbox(code, gDebuggee, "1.8",
  52. "http://example.com/www/js/abc.js", 1);
  53. }