browser_dbg_stack-contextmenu-02.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. * Test that the copy contextmenu copys the stack frames to the clipboard.
  6. */
  7. const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html";
  8. const STACK_STRING = "simpleCall@" + EXAMPLE_URL + "doc_recursion-stack.html:14:8";
  9. function test() {
  10. let gTab, gPanel, gDebugger, gFrames;
  11. let options = {
  12. source: TAB_URL,
  13. line: 1
  14. };
  15. initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
  16. gTab = aTab;
  17. gPanel = aPanel;
  18. gDebugger = gPanel.panelWin;
  19. gFrames = gDebugger.DebuggerView.StackFrames;
  20. waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_REFILLED)
  21. .then(openContextMenu)
  22. .then(testCopyStackMenuItem)
  23. .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
  24. .then(null, aError => {
  25. ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
  26. });
  27. callInTab(gTab, "simpleCall");
  28. });
  29. function clickCopyStack() {
  30. return new Promise((resolve, reject) => {
  31. let copyStackMenuItem = gDebugger.document.getElementById("copyStackMenuItem");
  32. if (!copyStackMenuItem) {
  33. reject(new Error("The Copy stack context menu item is not available."));
  34. }
  35. ok(copyStackMenuItem, "The Copy stack context menu item is available.");
  36. EventUtils.synthesizeMouseAtCenter(copyStackMenuItem, {}, gDebugger);
  37. resolve();
  38. });
  39. }
  40. function testCopyStackMenuItem() {
  41. return waitForClipboardPromise(clickCopyStack, STACK_STRING);
  42. }
  43. function openContextMenu() {
  44. let contextMenu = gDebugger.document.getElementById("stackFramesContextMenu");
  45. let contextMenuShown = once(contextMenu, "popupshown");
  46. EventUtils.synthesizeMouseAtCenter(gFrames.getItemAtIndex(0).prebuiltNode, {type: "contextmenu", button: 2}, gDebugger);
  47. return contextMenuShown;
  48. }
  49. }