tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / forms / script-tests / listbox-selection.js
1 description('<select> selection test for mouse events and keyevents.');
2
3 function mouseDownOnSelect(selId, index, modifier) {
4     var sl = document.getElementById(selId);
5     var itemHeight = Math.floor(sl.offsetHeight / sl.size);
6     var border = 1;
7     var y = border + index * itemHeight;
8
9     sl.focus();
10     if (window.eventSender) {
11         eventSender.mouseMoveTo(sl.offsetLeft + border, sl.offsetTop + y - window.pageYOffset);
12         eventSender.mouseDown(0, [modifier]);
13         eventSender.mouseUp(0, [modifier]);
14     }
15 }
16
17 function keyDownOnSelect(selId, identifier, modifier) {
18     document.getElementById(selId).focus();
19     if (window.eventSender)
20         eventSender.keyDown(identifier, [modifier]);
21 }
22
23 function createSelect(idName, sz, mlt, selIndex) {
24     var sl = document.createElement("select");
25     var i = 0;
26     sl.size = sz;
27     while (i < sz) {
28         var opt = document.createElement("option");
29         if (i == selIndex)
30             opt.selected = true;
31         opt.textContent = "item " + i;
32         sl.appendChild(opt);
33         i++;
34     }
35     sl.multiple = mlt;
36     sl.id = idName;
37     var parent = document.getElementById("parent");
38     parent.appendChild(sl);
39 }
40
41 function selectionPattern(selId) {
42     var sl = document.getElementById(selId);
43     var result = '';
44     for (var i = 0; i < sl.options.length; i++)
45         result += sl.options[i].selected ? '1' : '0';
46     return result;
47 }
48
49 var parent = document.createElement('div');
50 parent.id = "parent";
51 document.body.appendChild(parent);
52
53 createSelect("sl1", 5, false, -1);
54 createSelect("sl2", 5, false, 1);
55 createSelect("sl3", 5, false, -1);
56 createSelect("sl4", 5, false, 1);
57 createSelect("sl5", 5, false, 2);
58 createSelect("sl6", 5, false, 3);
59 createSelect("sl7", 5, false, 1);
60
61 createSelect("sl8", 5, true, -1);
62 createSelect("sl9", 5, true, 1);
63 createSelect("sl10", 5, true, -1);
64 createSelect("sl11", 5, true, 1);
65 createSelect("sl12", 5, true, 2);
66 createSelect("sl13", 5, true, 0);
67 createSelect("sl14", 5, true, 1);
68
69 debug("1) Select one item with mouse (no previous selection)");
70 mouseDownOnSelect("sl1", 0);
71 shouldBe('selectionPattern("sl1")', '"10000"');
72
73 debug("2) Select one item with mouse (with previous selection)");
74 mouseDownOnSelect("sl2", 0);
75 shouldBe('selectionPattern("sl2")', '"10000"');
76
77 debug("3) Select one item with the keyboard (no previous selection)");
78 keyDownOnSelect("sl3", "upArrow");
79 shouldBe('selectionPattern("sl3")', '"00001"');
80
81 debug("4) Select one item with the keyboard (with previous selection)");
82 keyDownOnSelect("sl4", "downArrow");
83 shouldBe('selectionPattern("sl4")', '"00100"');
84
85 debug("5) Attempt to select an item cmd-clicking");
86 mouseDownOnSelect("sl5", 1, "addSelectionKey");
87 shouldBe('selectionPattern("sl5")', '"01000"');
88
89 debug("6) Attempt to select a range shift-clicking");
90 mouseDownOnSelect("sl6", 1, "rangeSelectionKey");
91 shouldBe('selectionPattern("sl6")', '"01000"');
92
93 debug("7) Attempt to select a range with the keyboard");
94 keyDownOnSelect("sl7", "downArrow", "rangeSelectionKey");
95 shouldBe('selectionPattern("sl7")', '"00100"');
96
97 // Multiple selection tests
98
99 debug("8) Select one item with mouse (no previous selection)");
100 mouseDownOnSelect("sl8", 0);
101 shouldBe('selectionPattern("sl8")', '"10000"');
102
103 debug("9) Select one item with mouse (with previous selection)");
104 mouseDownOnSelect("sl9", 0);
105 shouldBe('selectionPattern("sl9")', '"10000"');
106
107 debug("10) Select one item with the keyboard (no previous selection)");
108 keyDownOnSelect("sl10", "upArrow");
109 shouldBe('selectionPattern("sl10")', '"00001"');
110
111 debug("11) Select one item with the keyboard (with previous selection)");
112 keyDownOnSelect("sl11", "downArrow");
113 shouldBe('selectionPattern("sl11")', '"00100"');
114
115 debug("12) Select an item cmd-clicking");
116 mouseDownOnSelect("sl12", 1, "addSelectionKey");
117 shouldBe('selectionPattern("sl12")', '"01100"');
118
119 debug("13) Select a range shift-clicking");
120 mouseDownOnSelect("sl13", 3, "rangeSelectionKey");
121 shouldBe('selectionPattern("sl13")', '"11110"');
122
123 debug("14) Select a range with the keyboard");
124 keyDownOnSelect("sl14", "downArrow", "rangeSelectionKey");
125 shouldBe('selectionPattern("sl14")', '"01100"');