browser_scratchpad_ui.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. function test()
  4. {
  5. waitForExplicitFinish();
  6. gBrowser.selectedTab = gBrowser.addTab();
  7. gBrowser.selectedBrowser.addEventListener("load", function onLoad() {
  8. gBrowser.selectedBrowser.removeEventListener("load", onLoad, true);
  9. openScratchpad(runTests);
  10. }, true);
  11. content.location = "data:text/html,<title>foobarBug636725</title>" +
  12. "<p>test inspect() in Scratchpad";
  13. }
  14. function runTests()
  15. {
  16. let sp = gScratchpadWindow.Scratchpad;
  17. let doc = gScratchpadWindow.document;
  18. let methodsAndItems = {
  19. "sp-menu-newscratchpad": "openScratchpad",
  20. "sp-menu-open": "openFile",
  21. "sp-menu-save": "saveFile",
  22. "sp-menu-saveas": "saveFileAs",
  23. "sp-text-run": "run",
  24. "sp-text-inspect": "inspect",
  25. "sp-text-display": "display",
  26. "sp-text-reloadAndRun": "reloadAndRun",
  27. "sp-menu-content": "setContentContext",
  28. "sp-menu-browser": "setBrowserContext",
  29. "sp-menu-pprint": "prettyPrint",
  30. "sp-menu-line-numbers": "toggleEditorOption",
  31. "sp-menu-word-wrap": "toggleEditorOption",
  32. "sp-menu-highlight-trailing-space": "toggleEditorOption",
  33. "sp-menu-larger-font": "increaseFontSize",
  34. "sp-menu-smaller-font": "decreaseFontSize",
  35. "sp-menu-normal-size-font": "normalFontSize",
  36. };
  37. let lastMethodCalled = null;
  38. for (let id in methodsAndItems) {
  39. lastMethodCalled = null;
  40. let methodName = methodsAndItems[id];
  41. let oldMethod = sp[methodName];
  42. ok(oldMethod, "found method " + methodName + " in Scratchpad object");
  43. sp[methodName] = () => {
  44. lastMethodCalled = methodName;
  45. };
  46. let menu = doc.getElementById(id);
  47. ok(menu, "found menuitem #" + id);
  48. try {
  49. menu.doCommand();
  50. }
  51. catch (ex) {
  52. ok(false, "exception thrown while executing the command of menuitem #" + id);
  53. }
  54. ok(lastMethodCalled == methodName,
  55. "method " + methodName + " invoked by the associated menuitem");
  56. sp[methodName] = oldMethod;
  57. }
  58. finish();
  59. }