/browser/devtools/webconsole/test/browser_webconsole_bug_613280_jsterm_copy.js

https://github.com/diogogmt/mozilla-central · JavaScript · 79 lines · 53 code · 18 blank · 8 comment · 7 complexity · 6c568579d7bc004ea72f4a82d083cf64 MD5 · raw file

  1. /*
  2. * Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/
  4. *
  5. * Contributor(s):
  6. * Mihai Șucan <mihai.sucan@gmail.com>
  7. */
  8. const TEST_URI = "data:text/html;charset=utf-8,Web Console test for bug 613280";
  9. registerCleanupFunction(function() {
  10. Services.prefs.clearUserPref("devtools.gcli.enable");
  11. });
  12. function test() {
  13. Services.prefs.setBoolPref("devtools.gcli.enable", false);
  14. addTab(TEST_URI);
  15. browser.addEventListener("load", tabLoaded, true);
  16. }
  17. function tabLoaded() {
  18. browser.removeEventListener("load", tabLoaded, true);
  19. openConsole();
  20. let hudId = HUDService.getHudIdByWindow(content);
  21. let HUD = HUDService.hudReferences[hudId];
  22. let input = HUD.jsterm.inputNode;
  23. let selection = getSelection();
  24. let contentSelection = browser.contentWindow.wrappedJSObject.getSelection();
  25. let clipboard_setup = function() {
  26. goDoCommand("cmd_copy");
  27. };
  28. let clipboard_copy_done = function() {
  29. finishTest();
  30. };
  31. // Check if we first need to clear any existing selections.
  32. if (selection.rangeCount > 0 || contentSelection.rangeCount > 0 ||
  33. input.selectionStart != input.selectionEnd) {
  34. if (input.selectionStart != input.selectionEnd) {
  35. input.selectionStart = input.selectionEnd = 0;
  36. }
  37. if (selection.rangeCount > 0) {
  38. selection.removeAllRanges();
  39. }
  40. if (contentSelection.rangeCount > 0) {
  41. contentSelection.removeAllRanges();
  42. }
  43. goUpdateCommand("cmd_copy");
  44. }
  45. let controller = top.document.commandDispatcher.
  46. getControllerForCommand("cmd_copy");
  47. is(controller.isCommandEnabled("cmd_copy"), false, "cmd_copy is disabled");
  48. HUD.jsterm.execute("'bug613280: hello world!'");
  49. HUD.outputNode.selectedIndex = HUD.outputNode.itemCount - 1;
  50. HUD.outputNode.focus();
  51. goUpdateCommand("cmd_copy");
  52. controller = top.document.commandDispatcher.
  53. getControllerForCommand("cmd_copy");
  54. is(controller.isCommandEnabled("cmd_copy"), true, "cmd_copy is enabled");
  55. waitForClipboard(getExpectedClipboardText(HUD.outputNode.selectedItem),
  56. clipboard_setup, clipboard_copy_done, clipboard_copy_done);
  57. }
  58. function getExpectedClipboardText(aItem) {
  59. return "[" + ConsoleUtils.timestampString(aItem.timestamp) + "] " +
  60. aItem.clipboardText;
  61. }