browser_dbg_addon-modules.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // Make sure the add-on actor can see loaded JS Modules from an add-on
  5. const ADDON_ID = "browser_dbg_addon4@tests.mozilla.org";
  6. const ADDON_PATH = "addon4.xpi";
  7. const ADDON_URL = getTemporaryAddonURLFromPath(ADDON_PATH);
  8. function test() {
  9. Task.spawn(function* () {
  10. let addon = yield addTemporaryAddon(ADDON_PATH);
  11. let tab1 = yield addTab("chrome://browser_dbg_addon4/content/test.xul");
  12. let addonDebugger = yield initAddonDebugger(ADDON_ID);
  13. is(addonDebugger.title, `Developer Tools - Test add-on with JS Modules - ${ADDON_URL}`,
  14. "Saw the right toolbox title.");
  15. // Check the inital list of sources is correct
  16. let groups = yield addonDebugger.getSourceGroups();
  17. is(groups[0].name, "browser_dbg_addon4@tests.mozilla.org", "Add-on code should be the first group");
  18. is(groups[1].name, "chrome://global", "XUL code should be the second group");
  19. is(groups.length, 2, "Should be only two groups.");
  20. let sources = groups[0].sources;
  21. is(sources.length, 3, "Should be three sources");
  22. ok(sources[0].url.endsWith("/addon4.xpi!/bootstrap.js"), "correct url for bootstrap code");
  23. is(sources[0].label, "bootstrap.js", "correct label for bootstrap code");
  24. is(sources[1].url, "resource://browser_dbg_addon4/test.jsm", "correct url for addon code");
  25. is(sources[1].label, "test.jsm", "correct label for addon code");
  26. is(sources[2].url, "chrome://browser_dbg_addon4/content/testxul.js", "correct url for addon tab code");
  27. is(sources[2].label, "testxul.js", "correct label for addon tab code");
  28. // Load a new module and tab and check they appear in the list of sources
  29. Cu.import("resource://browser_dbg_addon4/test2.jsm", {});
  30. let tab2 = yield addTab("chrome://browser_dbg_addon4/content/test2.xul");
  31. groups = yield addonDebugger.getSourceGroups();
  32. is(groups[0].name, "browser_dbg_addon4@tests.mozilla.org", "Add-on code should be the first group");
  33. is(groups[1].name, "chrome://global", "XUL code should be the second group");
  34. is(groups.length, 2, "Should be only two groups.");
  35. sources = groups[0].sources;
  36. is(sources.length, 5, "Should be five sources");
  37. ok(sources[0].url.endsWith("/addon4.xpi!/bootstrap.js"), "correct url for bootstrap code");
  38. is(sources[0].label, "bootstrap.js", "correct label for bootstrap code");
  39. is(sources[1].url, "resource://browser_dbg_addon4/test.jsm", "correct url for addon code");
  40. is(sources[1].label, "test.jsm", "correct label for addon code");
  41. is(sources[2].url, "chrome://browser_dbg_addon4/content/testxul.js", "correct url for addon tab code");
  42. is(sources[2].label, "testxul.js", "correct label for addon tab code");
  43. is(sources[3].url, "resource://browser_dbg_addon4/test2.jsm", "correct url for addon code");
  44. is(sources[3].label, "test2.jsm", "correct label for addon code");
  45. is(sources[4].url, "chrome://browser_dbg_addon4/content/testxul2.js", "correct url for addon tab code");
  46. is(sources[4].label, "testxul2.js", "correct label for addon tab code");
  47. Cu.unload("resource://browser_dbg_addon4/test2.jsm");
  48. yield addonDebugger.destroy();
  49. yield removeTab(tab1);
  50. yield removeTab(tab2);
  51. yield removeAddon(addon);
  52. finish();
  53. });
  54. }