2009-01-12 Eric Roman <eroman@chromium.org>
[WebKit-https.git] / LayoutTests / editing / selection / doubleclick-whitespace.html
1 <html>
2 <head>
3 <script>
4 if (window.layoutTestController) {
5      layoutTestController.dumpAsText();
6      layoutTestController.setSmartInsertDeleteEnabled(false);
7      layoutTestController.setSelectTrailingWhitespaceEnabled(true);
8 }
9
10 function getPositionOfNode(id)
11 {
12     var n = document.getElementById(id);
13     var pos = {x: 0, y: 0};
14
15     while (n) {
16         pos.x += n.offsetLeft + n.clientLeft;
17         pos.y += n.offsetTop + n.clientTop;
18         n = n.offsetParent;
19     }
20     return pos;
21 }
22
23 function doubleClickNode(id)
24 {
25     var pos = getPositionOfNode(id);
26     eventSender.mouseMoveTo(pos.x + 2, pos.y + 2);
27     eventSender.mouseDown();
28     eventSender.leapForward(1);
29     eventSender.mouseUp();
30     eventSender.leapForward(100);
31     eventSender.mouseDown();
32     eventSender.leapForward(1);
33     eventSender.mouseUp();
34 }
35
36 function doTest(testId, expectedText)
37 {
38     // Simulate a double click.
39     doubleClickNode(testId);
40
41     // Get the text of the current selection.
42     var sel = window.getSelection();
43     var actualText = sel.getRangeAt(0).toString();
44
45     if (expectedText == actualText) {
46         log("Passed " + testId);
47     } else {
48         log("Failed " + testId);
49         log("  Expected: " + expectedText);
50         log("  Actual: " + actualText);
51     }
52
53 }
54
55 function runTests()
56 {
57     if (window.layoutTestController) {
58         doTest("test1", "Doubleclickme \u00a0\u00a0\u00a0 ");
59         doTest("test2", "Doubleclickme");
60         doTest("test3", "Doubleclickme \u00a0\u00a0 ");
61         doTest("test4", "Doubleclickme");
62         doTest("test5", "Doubleclickme  \u00a0\u00a0");
63         doTest("test6", "Doubleclickme  \u00a0\t\t\t\u00a0");
64     }
65 }
66
67 function log(msg)
68 {
69     var l = document.getElementById('log');
70     l.appendChild(document.createTextNode(msg));
71     l.appendChild(document.createElement('br'));
72 }
73
74 </script>
75 </head>
76 <body onload="runTests()">
77 <p>
78 This tests that double-clicking a word on the Windows platform selects the whitespace after the word.
79 </p>
80
81 <div>
82 <span id=test1>Doubleclickme &nbsp;&nbsp;&nbsp; |END|</span>
83 </div>
84
85 <div>
86 <span id=test2>Doubleclickme|END|</span>
87 </div>
88
89 <div>
90 <span id=test3>Doubleclickme</span> &nbsp;&nbsp; 
91 |END|</span>
92 </div>
93
94 <div>
95 <div>
96 <span id="test4">Doubleclickme</span>
97 </div>
98 &nbsp;&nbsp;&nbsp;|(Should not have been extended into this line)|
99 </div>
100
101 <div>
102 <span id="test5">Doubleclickme </span> &nbsp;&nbsp;<img src="does-not-exist.png" />&nbsp; &nbsp;
103 </div>
104
105 <pre>
106 <span id="test6">Doubleclickme </span> &nbsp;                   &nbsp;|END|
107 </pre>
108
109 <br/>
110 <pre id=log>
111 </pre>
112
113 </body>
114 </html>