browser_console_copy_command.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // Tests that the `copy` console helper works as intended.
  5. "use strict";
  6. var gWebConsole, gJSTerm;
  7. var TEXT = "Lorem ipsum dolor sit amet, consectetur adipisicing " +
  8. "elit, sed do eiusmod tempor incididunt ut labore et dolore magna " +
  9. "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco " +
  10. "laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure " +
  11. "dolor in reprehenderit in voluptate velit esse cillum dolore eu " +
  12. "fugiat nulla pariatur. Excepteur sint occaecat cupidatat non " +
  13. "proident, sunt in culpa qui officia deserunt mollit anim id est laborum." +
  14. new Date();
  15. var ID = "select-me";
  16. add_task(function* init() {
  17. yield loadTab("data:text/html;charset=utf-8," +
  18. "<body>" +
  19. " <div>" +
  20. " <h1>Testing copy command</h1>" +
  21. " <p>This is some example text</p>" +
  22. " <p id='select-me'>" + TEXT + "</p>" +
  23. " </div>" +
  24. " <div><p></p></div>" +
  25. "</body>");
  26. gWebConsole = yield openConsole();
  27. gJSTerm = gWebConsole.jsterm;
  28. });
  29. add_task(function* testCopy() {
  30. let RANDOM = Math.random();
  31. let string = "Text: " + RANDOM;
  32. let obj = {a: 1, b: "foo", c: RANDOM};
  33. let samples = [
  34. [RANDOM, RANDOM],
  35. [JSON.stringify(string), string],
  36. [obj.toSource(), JSON.stringify(obj, null, " ")],
  37. [
  38. "$('#" + ID + "')",
  39. content.document.getElementById(ID).outerHTML
  40. ]
  41. ];
  42. for (let [source, reference] of samples) {
  43. let deferredResult = promise.defer();
  44. SimpleTest.waitForClipboard(
  45. "" + reference,
  46. () => {
  47. let command = "copy(" + source + ")";
  48. info("Attempting to copy: " + source);
  49. info("Executing command: " + command);
  50. gJSTerm.execute(command, msg => {
  51. is(msg, undefined, "Command success: " + command);
  52. });
  53. },
  54. deferredResult.resolve,
  55. deferredResult.reject);
  56. yield deferredResult.promise;
  57. }
  58. });
  59. add_task(function* cleanup() {
  60. gWebConsole = gJSTerm = null;
  61. gBrowser.removeTab(gBrowser.selectedTab);
  62. finishTest();
  63. });