browser_dbg_sources-webext-contentscript.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * Make sure eval scripts appear in the source list
  6. */
  7. const ADDON_PATH = "addon-webext-contentscript.xpi";
  8. const TAB_URL = EXAMPLE_URL + "doc_script_webext_contentscript.html";
  9. let {getExtensionUUID} = Cu.import("resource://gre/modules/Extension.jsm", {});
  10. function test() {
  11. let gPanel, gDebugger;
  12. let gSources, gAddon;
  13. let cleanup = function* (e) {
  14. if (gAddon) {
  15. // Remove the addon, if any.
  16. yield removeAddon(gAddon);
  17. }
  18. if (gPanel) {
  19. // Close the debugger panel, if any.
  20. yield closeDebuggerAndFinish(gPanel);
  21. } else {
  22. // If no debugger panel was opened, call finish directly.
  23. finish();
  24. }
  25. };
  26. return Task.spawn(function* () {
  27. gAddon = yield addTemporaryAddon(ADDON_PATH);
  28. let uuid = getExtensionUUID(gAddon.id);
  29. let options = {
  30. source: `moz-extension://${uuid}/webext-content-script.js`,
  31. line: 1
  32. };
  33. [,, gPanel] = yield initDebugger(TAB_URL, options);
  34. gDebugger = gPanel.panelWin;
  35. gSources = gDebugger.DebuggerView.Sources;
  36. is(gSources.values.length, 2, "Should have 2 sources");
  37. let item = gSources.getItemForAttachment(attachment => {
  38. return attachment.source.url.includes("moz-extension");
  39. });
  40. ok(item, "Got the expected WebExtensions ContentScript source");
  41. ok(item && item.attachment.source.url.includes(item.attachment.group),
  42. "The source is in the expected source group");
  43. is(item && item.attachment.label, "webext-content-script.js",
  44. "Got the expected filename in the label");
  45. yield cleanup();
  46. }).catch((e) => {
  47. ok(false, `Got an unexpected exception: ${e}`);
  48. // Cleanup in case of failures in the above task.
  49. return Task.spawn(cleanup);
  50. });
  51. }