File: browser_scratchpad_execute_print.js

package info (click to toggle)
wine-gecko-2.21 2.21%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 646,272 kB
  • ctags: 630,086
  • sloc: cpp: 2,895,786; ansic: 1,502,970; python: 156,675; asm: 115,373; java: 111,421; sh: 63,309; xml: 62,872; makefile: 58,685; perl: 19,182; objc: 3,461; yacc: 2,051; lex: 979; pascal: 929; exp: 449; php: 244; lisp: 228; awk: 211; sed: 26; csh: 21; ada: 16; ruby: 3
file content (126 lines) | stat: -rw-r--r-- 3,514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

function test()
{
  waitForExplicitFinish();

  gBrowser.selectedTab = gBrowser.addTab();
  gBrowser.selectedBrowser.addEventListener("load", function onTabLoad() {
    gBrowser.selectedBrowser.removeEventListener("load", onTabLoad, true);
    openScratchpad(runTests);
  }, true);

  content.location = "data:text/html,<p>test run() and display() in Scratchpad";
}

function runTests()
{
  let sp = gScratchpadWindow.Scratchpad;

  content.wrappedJSObject.foobarBug636725 = 1;

  sp.setText("++window.foobarBug636725");

  let exec = sp.run();
  is(exec[0], sp.getText(), "run()[0] is correct");
  ok(!exec[1], "run()[1] is correct");
  is(exec[2], content.wrappedJSObject.foobarBug636725,
     "run()[2] is correct");

  is(sp.getText(), "++window.foobarBug636725",
     "run() does not change the editor content");

  is(content.wrappedJSObject.foobarBug636725, 2,
     "run() updated window.foobarBug636725");

  sp.display();

  is(content.wrappedJSObject.foobarBug636725, 3,
     "display() updated window.foobarBug636725");

  is(sp.getText(), "++window.foobarBug636725\n/*\n3\n*/",
     "display() shows evaluation result in the textbox");

  is(sp.selectedText, "\n/*\n3\n*/", "selectedText is correct");
  let selection = sp.getSelectionRange();
  is(selection.start, 24, "selection.start is correct");
  is(selection.end, 32, "selection.end is correct");

  // Test selection run() and display().

  sp.setText("window.foobarBug636725 = 'a';\n" +
             "window.foobarBug636725 = 'b';");

  sp.selectRange(1, 2);

  selection = sp.getSelectionRange();

  is(selection.start, 1, "selection.start is 1");
  is(selection.end, 2, "selection.end is 2");

  sp.selectRange(0, 29);

  selection = sp.getSelectionRange();

  is(selection.start, 0, "selection.start is 0");
  is(selection.end, 29, "selection.end is 29");

  exec = sp.run();

  is(exec[0], "window.foobarBug636725 = 'a';",
     "run()[0] is correct");
  ok(!exec[1], 
     "run()[1] is correct");
  is(exec[2], "a",
     "run()[2] is correct");

  is(sp.getText(), "window.foobarBug636725 = 'a';\n" +
                   "window.foobarBug636725 = 'b';",
     "run() does not change the textbox value");

  is(content.wrappedJSObject.foobarBug636725, "a",
     "run() worked for the selected range");

  sp.setText("window.foobarBug636725 = 'c';\n" +
             "window.foobarBug636725 = 'b';");

  sp.selectRange(0, 22);

  sp.display();

  is(content.wrappedJSObject.foobarBug636725, "a",
     "display() worked for the selected range");

  is(sp.getText(), "window.foobarBug636725" +
                   "\n/*\na\n*/" +
                   " = 'c';\n" +
                   "window.foobarBug636725 = 'b';",
     "display() shows evaluation result in the textbox");

  is(sp.selectedText, "\n/*\na\n*/", "selectedText is correct");

  selection = sp.getSelectionRange();
  is(selection.start, 22, "selection.start is correct");
  is(selection.end, 30, "selection.end is correct");

  sp.deselect();

  ok(!sp.selectedText, "selectedText is empty");

  selection = sp.getSelectionRange();
  is(selection.start, selection.end, "deselect() works");

  // Test undo/redo.

  sp.setText("foo1");
  sp.setText("foo2");
  is(sp.getText(), "foo2", "editor content updated");
  sp.undo();
  is(sp.getText(), "foo1", "undo() works");
  sp.redo();
  is(sp.getText(), "foo2", "redo() works");

  finish();
}