test_listsources-04.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /**
  4. * Check getSources functionality with sourcemaps.
  5. */
  6. const {SourceNode} = require("source-map");
  7. function run_test() {
  8. run_test_with_server(DebuggerServer, function () {
  9. // Bug 1304144 - This test does not run in a worker because the
  10. // `rpc` method which talks to the main thread does not work.
  11. // run_test_with_server(WorkerDebuggerServer, do_test_finished);
  12. do_test_finished();
  13. });
  14. do_test_pending();
  15. }
  16. function run_test_with_server(server, cb) {
  17. Task.spawn(function*() {
  18. initTestDebuggerServer(server);
  19. const debuggee = addTestGlobal("test-sources", server);
  20. const client = new DebuggerClient(server.connectPipe());
  21. yield client.connect();
  22. const [,,threadClient] = yield attachTestTabAndResume(client, "test-sources");
  23. yield threadClient.reconfigure({ useSourceMaps: true });
  24. addSources(debuggee);
  25. threadClient.getSources(Task.async(function* (res) {
  26. do_check_eq(res.sources.length, 3, "3 sources exist");
  27. yield threadClient.reconfigure({ useSourceMaps: false });
  28. threadClient.getSources(function(res) {
  29. do_check_eq(res.sources.length, 1, "1 source exist");
  30. client.close().then(cb);
  31. });
  32. }));
  33. });
  34. }
  35. function addSources(debuggee) {
  36. let { code, map } = (new SourceNode(null, null, null, [
  37. new SourceNode(1, 0, "a.js", "function a() { return 'a'; }\n"),
  38. new SourceNode(1, 0, "b.js", "function b() { return 'b'; }\n"),
  39. new SourceNode(1, 0, "c.js", "function c() { return 'c'; }\n"),
  40. ])).toStringWithSourceMap({
  41. file: "abc.js",
  42. sourceRoot: "http://example.com/www/js/"
  43. });
  44. code += "//# sourceMappingURL=data:text/json;base64," + btoa(map.toString());
  45. Components.utils.evalInSandbox(code, debuggee, "1.8",
  46. "http://example.com/www/js/abc.js", 1);
  47. }