Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / test / data / webui / list_selection_model_test.html
blob58e7e7011eedb69fa530ba0e94f887d9c34237da
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="list_selection_model_test_util.js"></script>
5 </head>
6 <body>
8 <script>
9 function createSelectionModel(len, opt_dependentLeadItem) {
10 var sm = new cr.ui.ListSelectionModel(len);
11 sm.independentLeadItem_ = !opt_dependentLeadItem;
12 return sm;
15 function testAdjust1() {
16 var sm = createSelectionModel(200);
18 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 100;
19 adjust(sm, 0, 10, 0);
21 assertEquals(90, sm.leadIndex);
22 assertEquals(90, sm.anchorIndex);
23 assertEquals(90, sm.selectedIndex);
26 function testAdjust2() {
27 var sm = createSelectionModel(200);
29 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 50;
30 adjust(sm, 60, 10, 0);
32 assertEquals(50, sm.leadIndex);
33 assertEquals(50, sm.anchorIndex);
34 assertEquals(50, sm.selectedIndex);
37 function testAdjust3() {
38 var sm = createSelectionModel(200);
40 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 100;
41 adjust(sm, 0, 0, 10);
43 assertEquals(110, sm.leadIndex);
44 assertEquals(110, sm.anchorIndex);
45 assertEquals(110, sm.selectedIndex);
48 function testAdjust4() {
49 var sm = createSelectionModel(200);
51 sm.leadIndex = sm.anchorIndex = 100;
52 sm.selectRange(100, 110);
54 adjust(sm, 0, 10, 5);
56 assertEquals(95, sm.leadIndex);
57 assertEquals(95, sm.anchorIndex);
58 assertArrayEquals(range(95, 105), sm.selectedIndexes);
61 function testAdjust5() {
62 var sm = createSelectionModel(100);
64 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 99;
66 adjust(sm, 99, 1, 0);
68 assertEquals(98, sm.leadIndex, 'lead');
69 assertEquals(98, sm.anchorIndex, 'anchor');
70 assertArrayEquals([98], sm.selectedIndexes);
73 function testAdjust6() {
74 var sm = createSelectionModel(200);
76 sm.leadIndex = sm.anchorIndex = 105;
77 sm.selectRange(100, 110);
79 // Remove 100 - 105
80 adjust(sm, 100, 5, 0);
82 assertEquals(100, sm.leadIndex, 'lead');
83 assertEquals(100, sm.anchorIndex, 'anchor');
84 assertArrayEquals(range(100, 105), sm.selectedIndexes);
87 function testAdjust7() {
88 var sm = createSelectionModel(1);
90 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 0;
92 adjust(sm, 0, 0, 10);
94 assertEquals(10, sm.leadIndex, 'lead');
95 assertEquals(10, sm.anchorIndex, 'anchor');
96 assertArrayEquals([10], sm.selectedIndexes);
99 function testAdjust8() {
100 var sm = createSelectionModel(100);
102 sm.leadIndex = sm.anchorIndex = 50;
103 sm.selectAll();
105 adjust(sm, 10, 80, 0);
107 assertEquals(-1, sm.leadIndex, 'lead');
108 assertEquals(-1, sm.anchorIndex, 'anchor');
109 assertArrayEquals(range(0, 19), sm.selectedIndexes);
112 function testAdjust9() {
113 var sm = createSelectionModel(10);
115 sm.leadIndex = sm.anchorIndex = 5;
116 sm.selectAll();
118 // Remove all
119 adjust(sm, 0, 10, 0);
121 assertEquals(-1, sm.leadIndex, 'lead');
122 assertEquals(-1, sm.anchorIndex, 'anchor');
123 assertArrayEquals([], sm.selectedIndexes);
126 function testAdjust10() {
127 var sm = createSelectionModel(10);
129 sm.leadIndex = sm.anchorIndex = 5;
130 sm.selectAll();
132 adjust(sm, 0, 10, 20);
134 assertEquals(5, sm.leadIndex, 'lead');
135 assertEquals(5, sm.anchorIndex, 'anchor');
136 assertArrayEquals([5], sm.selectedIndexes);
139 function testAdjust11() {
140 var sm = createSelectionModel(20);
142 sm.leadIndex = sm.anchorIndex = 10;
143 sm.selectAll();
145 adjust(sm, 5, 20, 10);
147 assertEquals(-1, sm.leadIndex, 'lead');
148 assertEquals(-1, sm.anchorIndex, 'anchor');
149 assertArrayEquals(range(0, 4), sm.selectedIndexes);
152 function testAdjust12() {
153 var sm = createSelectionModel(20, true);
155 sm.selectAll();
156 sm.leadIndex = sm.anchorIndex = 10;
158 adjust(sm, 5, 20, 10);
160 assertEquals(-1, sm.leadIndex, 'lead');
161 assertEquals(-1, sm.anchorIndex, 'anchor');
162 assertArrayEquals(range(0, 4), sm.selectedIndexes);
165 function testAdjust13() {
166 var sm = createSelectionModel(20, true);
168 sm.selectAll();
169 sm.leadIndex = sm.anchorIndex = 15;
171 adjust(sm, 5, 5, 0);
173 assertEquals(10, sm.leadIndex, 'lead');
174 assertEquals(10, sm.anchorIndex, 'anchor');
175 assertArrayEquals(range(0, 14), sm.selectedIndexes);
178 function testLeadAndAnchor1() {
179 var sm = createSelectionModel(20, true);
181 sm.selectAll();
182 sm.leadIndex = sm.anchorIndex = 10;
184 assertEquals(10, sm.leadIndex, 'lead');
185 assertEquals(10, sm.anchorIndex, 'anchor');
188 function testLeadAndAnchor2() {
189 var sm = createSelectionModel(20, true);
191 sm.leadIndex = sm.anchorIndex = 10;
192 sm.selectAll();
194 assertEquals(-1, sm.leadIndex, 'lead');
195 assertEquals(-1, sm.anchorIndex, 'anchor');
198 function testSelectAll() {
199 var sm = createSelectionModel(10);
201 var changes = null;
202 sm.addEventListener('change', function(e) {
203 changes = e.changes;
206 sm.selectAll();
208 assertArrayEquals(range(0, 9), sm.selectedIndexes);
209 assertArrayEquals(range(0, 9),
210 changes.map(function(change) { return change.index; }));
213 function testSelectAllOnEmptyList() {
214 var sm = createSelectionModel(0);
216 var changes = null;
217 sm.addEventListener('change', function(e) {
218 changes = e.changes;
221 sm.selectAll();
223 assertArrayEquals([], sm.selectedIndexes);
224 assertEquals(null, changes);
227 </script>
229 </body>
230 </html>