browser_scratchpad_execute_print.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. function test() {
  5. waitForExplicitFinish();
  6. gBrowser.selectedTab = gBrowser.addTab();
  7. gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
  8. gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
  9. openScratchpad(runTests);
  10. }, true);
  11. content.location = "data:text/html,<p>test run() and display() in Scratchpad";
  12. }
  13. function runTests() {
  14. let sp = gScratchpadWindow.Scratchpad;
  15. let tests = [{
  16. method: "run",
  17. prepare: function* () {
  18. yield inContent(function* () {
  19. content.wrappedJSObject.foobarBug636725 = 1;
  20. });
  21. sp.editor.setText("++window.foobarBug636725");
  22. },
  23. then: function* ([code, , result]) {
  24. is(code, sp.getText(), "code is correct");
  25. let pageResult = yield inContent(function* () {
  26. return content.wrappedJSObject.foobarBug636725;
  27. });
  28. is(result, pageResult,
  29. "result is correct");
  30. is(sp.getText(), "++window.foobarBug636725",
  31. "run() does not change the editor content");
  32. is(pageResult, 2, "run() updated window.foobarBug636725");
  33. }
  34. }, {
  35. method: "display",
  36. prepare: function* () {},
  37. then: function* () {
  38. let pageResult = yield inContent(function* () {
  39. return content.wrappedJSObject.foobarBug636725;
  40. });
  41. is(pageResult, 3, "display() updated window.foobarBug636725");
  42. is(sp.getText(), "++window.foobarBug636725\n/*\n3\n*/",
  43. "display() shows evaluation result in the textbox");
  44. is(sp.editor.getSelection(), "\n/*\n3\n*/", "getSelection is correct");
  45. }
  46. }, {
  47. method: "run",
  48. prepare: function* () {
  49. sp.editor.setText("window.foobarBug636725 = 'a';\n" +
  50. "window.foobarBug636725 = 'b';");
  51. sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 29 });
  52. },
  53. then: function* ([code, , result]) {
  54. is(code, "window.foobarBug636725 = 'a';", "code is correct");
  55. is(result, "a", "result is correct");
  56. is(sp.getText(), "window.foobarBug636725 = 'a';\n" +
  57. "window.foobarBug636725 = 'b';",
  58. "run() does not change the textbox value");
  59. let pageResult = yield inContent(function* () {
  60. return content.wrappedJSObject.foobarBug636725;
  61. });
  62. is(pageResult, "a", "run() worked for the selected range");
  63. }
  64. }, {
  65. method: "display",
  66. prepare: function* () {
  67. sp.editor.setText("window.foobarBug636725 = 'c';\n" +
  68. "window.foobarBug636725 = 'b';");
  69. sp.editor.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 22 });
  70. },
  71. then: function* () {
  72. let pageResult = yield inContent(function* () {
  73. return content.wrappedJSObject.foobarBug636725;
  74. });
  75. is(pageResult, "a", "display() worked for the selected range");
  76. is(sp.getText(), "window.foobarBug636725" +
  77. "\n/*\na\n*/" +
  78. " = 'c';\n" +
  79. "window.foobarBug636725 = 'b';",
  80. "display() shows evaluation result in the textbox");
  81. is(sp.editor.getSelection(), "\n/*\na\n*/", "getSelection is correct");
  82. }
  83. }];
  84. runAsyncCallbackTests(sp, tests).then(function () {
  85. ok(sp.editor.somethingSelected(), "something is selected");
  86. sp.editor.dropSelection();
  87. ok(!sp.editor.somethingSelected(), "something is no longer selected");
  88. ok(!sp.editor.getSelection(), "getSelection is empty");
  89. // Test undo/redo.
  90. sp.editor.setText("foo1");
  91. sp.editor.setText("foo2");
  92. is(sp.getText(), "foo2", "editor content updated");
  93. sp.undo();
  94. is(sp.getText(), "foo1", "undo() works");
  95. sp.redo();
  96. is(sp.getText(), "foo2", "redo() works");
  97. finish();
  98. });
  99. }