OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | |
2 <html> | |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 <div id="parent"> | |
8 <select id="sl16" multiple size=5> | |
9 <option>a</option> | |
10 <option>b</option> | |
11 <option>c</option> | |
12 <option>d</option> | |
13 <option>e</option> | |
14 </select> | |
15 </div> | |
16 <p id="description"></p> | |
17 <div id="console"></div> | |
18 <script> | |
19 description('<select> selection test for mouse events and keyevents.'); | |
20 | |
21 function mouseMoveToOption(selId, index) { | |
22 if (!window.eventSender) { | |
23 console.log("Needs eventSender."); | |
24 return; | |
25 } | |
26 var sl = document.getElementById(selId); | |
27 var itemHeight = Math.floor(sl.offsetHeight / sl.size); | |
28 var border = 1; | |
29 var y = border + index * itemHeight; | |
30 eventSender.mouseMoveTo(sl.offsetLeft + border, sl.offsetTop + y - window.pa
geYOffset); | |
31 } | |
32 | |
33 function mouseClickOnSelect(selId, index, modifier) { | |
34 document.getElementById(selId).focus(); | |
35 if (window.eventSender) { | |
36 mouseMoveToOption(selId, index); | |
37 eventSender.mouseDown(0, [modifier]); | |
38 eventSender.mouseUp(0, [modifier]); | |
39 } | |
40 } | |
41 | |
42 function keyDownOnSelect(selId, identifier, modifier) { | |
43 document.getElementById(selId).focus(); | |
44 if (window.eventSender) | |
45 eventSender.keyDown(identifier, [modifier]); | |
46 } | |
47 | |
48 function createSelect(idName, sz, mlt, selIndex) { | |
49 var sl = document.createElement("select"); | |
50 var i = 0; | |
51 sl.size = sz; | |
52 while (i < sz) { | |
53 var opt = document.createElement("option"); | |
54 if (i == selIndex) | |
55 opt.selected = true; | |
56 opt.textContent = "item " + i; | |
57 sl.appendChild(opt); | |
58 i++; | |
59 } | |
60 sl.multiple = mlt; | |
61 sl.id = idName; | |
62 var parent = document.getElementById("parent"); | |
63 parent.appendChild(sl); | |
64 } | |
65 | |
66 function selectionPattern(selId) { | |
67 var sl = document.getElementById(selId); | |
68 var result = ''; | |
69 for (var i = 0; i < sl.options.length; i++) | |
70 result += sl.options[i].selected ? '1' : '0'; | |
71 return result; | |
72 } | |
73 | |
74 createSelect("sl1", 5, false, -1); | |
75 createSelect("sl2", 5, false, 1); | |
76 createSelect("sl3", 5, false, -1); | |
77 createSelect("sl4", 5, false, 1); | |
78 createSelect("sl5", 5, false, 2); | |
79 createSelect("sl6", 5, false, 3); | |
80 createSelect("sl7", 5, false, 1); | |
81 | |
82 createSelect("sl8", 5, true, -1); | |
83 createSelect("sl9", 5, true, 1); | |
84 createSelect("sl10", 5, true, -1); | |
85 createSelect("sl11", 5, true, 1); | |
86 createSelect("sl12", 5, true, 2); | |
87 createSelect("sl13", 5, true, 0); | |
88 createSelect("sl14", 5, true, 1); | |
89 createSelect("sl15", 5, true, 0); | |
90 | |
91 debug("1) Select one item with mouse (no previous selection)"); | |
92 mouseClickOnSelect("sl1", 0); | |
93 shouldBe('selectionPattern("sl1")', '"10000"'); | |
94 | |
95 debug("2) Select one item with mouse (with previous selection)"); | |
96 mouseClickOnSelect("sl2", 0); | |
97 shouldBe('selectionPattern("sl2")', '"10000"'); | |
98 | |
99 debug("3) Select one item with the keyboard (no previous selection)"); | |
100 keyDownOnSelect("sl3", "upArrow"); | |
101 shouldBe('selectionPattern("sl3")', '"00001"'); | |
102 | |
103 debug("4) Select one item with the keyboard (with previous selection)"); | |
104 keyDownOnSelect("sl4", "downArrow"); | |
105 shouldBe('selectionPattern("sl4")', '"00100"'); | |
106 | |
107 debug("5) Attempt to select an item cmd-clicking"); | |
108 mouseClickOnSelect("sl5", 1, "addSelectionKey"); | |
109 shouldBe('selectionPattern("sl5")', '"01000"'); | |
110 | |
111 debug("6) Attempt to select a range shift-clicking"); | |
112 mouseClickOnSelect("sl6", 1, "rangeSelectionKey"); | |
113 shouldBe('selectionPattern("sl6")', '"01000"'); | |
114 | |
115 debug("7) Attempt to select a range with the keyboard"); | |
116 keyDownOnSelect("sl7", "downArrow", "rangeSelectionKey"); | |
117 shouldBe('selectionPattern("sl7")', '"00100"'); | |
118 | |
119 // Multiple selection tests | |
120 | |
121 debug("8) Select one item with mouse (no previous selection)"); | |
122 mouseClickOnSelect("sl8", 0); | |
123 shouldBe('selectionPattern("sl8")', '"10000"'); | |
124 | |
125 debug("9) Select one item with mouse (with previous selection)"); | |
126 mouseClickOnSelect("sl9", 0); | |
127 shouldBe('selectionPattern("sl9")', '"10000"'); | |
128 | |
129 debug("10) Select one item with the keyboard (no previous selection)"); | |
130 keyDownOnSelect("sl10", "upArrow"); | |
131 shouldBe('selectionPattern("sl10")', '"00001"'); | |
132 | |
133 debug("11) Select one item with the keyboard (with previous selection)"); | |
134 keyDownOnSelect("sl11", "downArrow"); | |
135 shouldBe('selectionPattern("sl11")', '"00100"'); | |
136 | |
137 debug("12) Select an item cmd-clicking"); | |
138 mouseClickOnSelect("sl12", 1, "addSelectionKey"); | |
139 shouldBe('selectionPattern("sl12")', '"01100"'); | |
140 | |
141 debug("13) Select a range shift-clicking"); | |
142 mouseClickOnSelect("sl13", 3, "rangeSelectionKey"); | |
143 shouldBe('selectionPattern("sl13")', '"11110"'); | |
144 | |
145 debug("14) Select a range with the keyboard"); | |
146 keyDownOnSelect("sl14", "downArrow", "rangeSelectionKey"); | |
147 shouldBe('selectionPattern("sl14")', '"01100"'); | |
148 | |
149 debug("15) Drag upside-down"); | |
150 mouseMoveToOption("sl15", 1); | |
151 eventSender.dragMode = false; // Avoid event delay in eventSender. | |
152 eventSender.mouseDown(0); | |
153 shouldBeEqualToString('selectionPattern("sl15")', "01000"); | |
154 shouldBeEqualToString('mouseMoveToOption("sl15", 3); selectionPattern("sl15")',
"01110"); | |
155 shouldBeEqualToString('mouseMoveToOption("sl15", 2); selectionPattern("sl15")',
"01100"); | |
156 eventSender.mouseUp(0); | |
157 | |
158 debug("16) Active-selection after type-ahead"); | |
159 shouldBeEqualToString("mouseClickOnSelect('sl16', 1); selectionPattern('sl16')",
"01000"); | |
160 shouldBeEqualToString("keyDownOnSelect('sl16', 'e'); selectionPattern('sl16')",
"00001"); | |
161 shouldBeEqualToString("keyDownOnSelect('sl16', 'upArrow', 'rangeSelectionKey');
selectionPattern('sl16')", "00011"); | |
162 | |
163 document.getElementById("parent").remove(); | |
164 </script> | |
165 </body> | |
166 </html> | |
OLD | NEW |