[Release] Webkit-EFL Ver. 2.0_beta_118996_0.6.22
[framework/web/webkit-efl.git] / LayoutTests / fast / events / selectionchange-user-initiated.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script>
5
6 function expected(text) {
7     return text.substr(text.indexOf(':') + 2);
8 }
9
10 var i = 0;
11
12 function logger(event) {
13     var console = document.getElementById('console');
14     var listItem = null;
15     if (i < console.childNodes.length) {
16         var text = null;
17         do {
18             listItem = console.childNodes[i++];
19             text = listItem.innerText;
20         } while (text.indexOf('OPTIONAL:') >= 0 && expected(text) != event.type && i < console.childNodes.length);
21     }
22
23     if (!listItem) {
24         var listItem = document.createElement('li');
25         listItem.appendChild(document.createTextNode('FAIL: ' + event.type + ' but didn\'t expect to fire'));
26         console.appendChild(listItem);
27         i = console.childNodes.length;
28         return;
29     }
30
31     if (expected(listItem.innerText) == event.type)
32         listItem.innerHTML = 'PASS: ' + event.type;
33     else
34         listItem.innerHTML = 'FAIL: ' + event.type + ' but expected ' + expected(listItem.innerText);
35 }
36
37 </script>
38 </head>
39 <body onselectionchange="logger(event)">
40 <p>To test this manually, click on "hello", and extend selection to right by pressing right arrow keys with shift twice.
41 Then click again on "world" and extend selection twice the same way.</p>
42 <div id="hello" contenteditable>hello</div>
43 <div id="world" contenteditable>world</div>
44 <ul id="console"
45 ><li>EXPECT: mousedown</li
46 ><li>EXPECT: selectionchange</li
47 ><li>EXPECT: mouseup</li
48 ><li>EXPECT: click</li
49 ><li>EXPECT: keydown</li
50 ><li>EXPECT: keyup</li
51 ><li>EXPECT: selectionchange</li
52 ><li>EXPECT: keydown</li
53 ><li>EXPECT: keyup</li
54 ><li>EXPECT: selectionchange</li
55 ><li>EXPECT: mousedown</li
56 ><li>EXPECT: selectionchange</li
57 ><li>OPTIONAL: selectionchange</li
58 ><li>EXPECT: mouseup</li
59 ><li>EXPECT: click</li
60 ><li>EXPECT: keydown</li
61 ><li>EXPECT: keyup</li
62 ><li>EXPECT: selectionchange</li
63 ><li>EXPECT: keydown</li
64 ><li>EXPECT: keyup</li
65 ><li>EXPECT: selectionchange</li
66 ></ul>
67 <script>
68
69 function attachLogger(element, name) {
70     element.addEventListener('mousedown', logger, false);
71     element.addEventListener('mouseup', logger, false);
72     element.addEventListener('click', logger, false);
73     element.addEventListener('keydown', logger, false);
74     element.addEventListener('keyup', logger, false);
75 }
76
77 var helloDiv = document.getElementById('hello');
78 var worldDiv = document.getElementById('world');
79
80 attachLogger(helloDiv);
81 attachLogger(worldDiv);
82
83 if (window.layoutTestController && window.eventSender) {
84     layoutTestController.dumpAsText();
85     layoutTestController.waitUntilDone();
86
87     var events = [
88         function () { eventSender.mouseMoveTo(helloDiv.offsetLeft + 10, helloDiv.offsetTop + 2); },
89         function () { eventSender.mouseDown(); },
90         function () { eventSender.mouseUp(); },
91         function () { eventSender.keyDown("leftArrow", ['shiftKey']); },
92         function () { eventSender.keyDown("rightArrow", ['shiftKey']); },
93         function () { eventSender.mouseMoveTo(worldDiv.offsetLeft + 10, worldDiv.offsetTop + 2); },
94         function () { eventSender.mouseDown(); },
95         function () { eventSender.mouseUp(); },
96         function () { eventSender.keyDown("leftArrow", ['shiftKey']); },
97         function () { eventSender.keyDown("rightArrow", ['shiftKey']); },
98     ];
99     var j = 0;
100
101     function timer() {
102         // Need to wait one more iteration for events to be processed
103         if (j >= events.length) {
104             layoutTestController.notifyDone();
105             return;
106         }
107         events[j]();
108         j++;
109         setTimeout(timer, 0);
110     }
111
112     timer();
113 }
114
115 </script>
116 </body>
117 </html>