1 description('<select> selection test for scrolling.');
3 var parent = document.createElement('div');
4 parent.innerHTML = '<select id="sl1" multiple size=5>'
5 + '<option>one</option>'
6 + '<option>two</option>'
7 + '<option>three</option>'
8 + '<option>four</option>'
9 + '<option>five</option>'
10 + '<option>six</option>'
11 + '<option>seven</option>'
12 + '<option>eight</option>'
13 + '<option>nine</option>'
14 + '<option>ten</option>'
15 + '<option>eleven</option>'
16 + '<option>twelve</option>'
17 + '<option>thirteen</option>'
18 + '<option>fourteen</option>'
19 + '<option>fifteen</option>'
20 + '<option>sixteen</option>'
21 + '<option>seventeen</option>'
23 + '<select id="sl2" multiple style="height: 135px; border: 10px solid; padding: 5px;">'
24 + '<option>one</option>'
25 + '<option>two</option>'
26 + '<option>three</option>'
28 document.body.appendChild(parent);
30 // Determine the item height.
31 var sl1 = document.getElementById('sl1');
32 var sl2 = document.getElementById('sl2');
33 var itemHeight = Math.floor(sl1.offsetHeight / sl1.size);
34 sl1.removeAttribute('size');
35 var height = itemHeight * 9 + 9;
36 sl1.setAttribute('style', 'height: ' + height + 'px; border: 10px solid; padding: 5px;');
38 function mouseDownOnSelect(selId, index)
40 var sl = document.getElementById(selId);
41 var borderPaddingTop = 15;
42 var borderPaddingLeft = 15;
43 var y = index * itemHeight + itemHeight / 3 - window.pageYOffset + borderPaddingTop;
44 var event = document.createEvent("MouseEvent");
45 event.initMouseEvent("mousedown", true, true, document.defaultView, 1, sl.offsetLeft + borderPaddingLeft, sl.offsetTop + y, sl.offsetLeft + borderPaddingLeft, sl.offsetTop + y, false, false, false, false, 0, document);
46 sl.dispatchEvent(event);
49 function selectionPattern(selectId)
51 var select = document.getElementById(selectId);
53 for (var i = 0; i < select.options.length; i++)
54 result += select.options[i].selected ? '1' : '0';
58 mouseDownOnSelect("sl1", 0);
59 shouldBe('selectionPattern("sl1")', '"10000000000000000"');
61 mouseDownOnSelect("sl1", 1);
62 shouldBe('selectionPattern("sl1")', '"01000000000000000"');
64 mouseDownOnSelect("sl1", 6);
65 shouldBe('selectionPattern("sl1")', '"00000010000000000"');
67 mouseDownOnSelect("sl1", 7);
68 shouldBe('selectionPattern("sl1")', '"00000001000000000"');
70 mouseDownOnSelect("sl1", 8);
71 shouldBe('selectionPattern("sl1")', '"00000001000000000"');
73 mouseDownOnSelect("sl1", 0);
74 shouldBe('selectionPattern("sl1")', '"01000000000000000"');
76 for (i = 0; i < 9; i++)
77 mouseDownOnSelect("sl1", 7);
78 shouldBe('selectionPattern("sl1")', '"00000000000000001"');
80 mouseDownOnSelect("sl2", 1);
81 shouldBe('selectionPattern("sl2")', '"010"');
83 mouseDownOnSelect("sl2", 3);
84 shouldBe('selectionPattern("sl2")', '"010"');
86 mouseDownOnSelect("sl2", 2);
87 shouldBe('selectionPattern("sl2")', '"001"');