OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title></title> | 4 <title></title> |
5 <style> | 5 <style> |
6 | |
7 </style> | 6 </style> |
8 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j s"></script> | 7 <script src="webui_resource_test.js"></script> |
9 <script src="../../cr.js"></script> | |
10 <script src="../event_target.js"></script> | |
11 <script src="list_selection_model.js"></script> | |
12 <script src="list_selection_model_test_util.js"></script> | |
13 <script> | |
14 | |
15 goog.require('goog.testing.jsunit'); | |
16 | |
17 </script> | |
18 | |
19 </head> | 8 </head> |
20 <body> | 9 <body> |
21 | 10 |
22 <script> | 11 <script> |
23 | |
24 function createSelectionModel(len, opt_dependentLeadItem) { | 12 function createSelectionModel(len, opt_dependentLeadItem) { |
25 var sm = new cr.ui.ListSelectionModel(len); | 13 var sm = new cr.ui.ListSelectionModel(len); |
26 sm.independentLeadItem_ = !opt_dependentLeadItem; | 14 sm.independentLeadItem_ = !opt_dependentLeadItem; |
27 return sm; | 15 return sm; |
28 } | 16 } |
29 | 17 |
Dan Beam
2013/06/20 18:23:39
doc, assert(start % end == 0);
kevers
2013/06/20 20:03:34
Added jsdoc.
| |
18 function range(start, end) { | |
19 var a = []; | |
20 for (var i = start; i <= end; i++) { | |
21 a.push(i); | |
22 } | |
23 return a; | |
24 } | |
25 | |
Dan Beam
2013/06/20 18:23:39
i'm 12 and what is this? (needs doc)
kevers
2013/06/20 20:03:34
Done.
| |
26 function adjust(sm, index, removed, added) { | |
27 var permutation = []; | |
28 for (var i = 0; i < index; i++) { | |
29 permutation.push(i); | |
30 } | |
31 for (var i = 0; i < removed; i++) { | |
32 permutation.push(-1); | |
33 } | |
34 for (var i = index + removed; i < sm.length; i++) { | |
35 permutation.push(i - removed + added); | |
36 } | |
37 sm.adjustLength(sm.length - removed + added); | |
38 sm.adjustToReordering(permutation); | |
39 } | |
40 | |
30 function testAdjust1() { | 41 function testAdjust1() { |
31 var sm = createSelectionModel(200); | 42 var sm = createSelectionModel(200); |
32 | 43 |
33 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 100; | 44 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 100; |
34 adjust(sm, 0, 10, 0); | 45 adjust(sm, 0, 10, 0); |
35 | 46 |
36 assertEquals(90, sm.leadIndex); | 47 assertEquals(90, sm.leadIndex); |
37 assertEquals(90, sm.anchorIndex); | 48 assertEquals(90, sm.anchorIndex); |
38 assertEquals(90, sm.selectedIndex); | 49 assertEquals(90, sm.selectedIndex); |
39 } | 50 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 assertArrayEquals(range(95, 105), sm.selectedIndexes); | 84 assertArrayEquals(range(95, 105), sm.selectedIndexes); |
74 } | 85 } |
75 | 86 |
76 function testAdjust5() { | 87 function testAdjust5() { |
77 var sm = createSelectionModel(100); | 88 var sm = createSelectionModel(100); |
78 | 89 |
79 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 99; | 90 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 99; |
80 | 91 |
81 adjust(sm, 99, 1, 0); | 92 adjust(sm, 99, 1, 0); |
82 | 93 |
83 assertEquals('lead', -1, sm.leadIndex); | 94 // Selection set to next item when selected items are removed (see |
84 assertEquals('anchor', -1, sm.anchorIndex); | 95 // crbug/81802). |
arv (Not doing code reviews)
2013/06/20 15:25:01
I'm not sure this comment makes sense now. The bug
kevers
2013/06/20 20:03:34
removed comment.
| |
85 assertArrayEquals([], sm.selectedIndexes); | 96 assertEquals(98, sm.leadIndex, 'lead'); |
97 assertEquals(98, sm.anchorIndex, 'anchor'); | |
98 assertArrayEquals([98], sm.selectedIndexes); | |
86 } | 99 } |
87 | 100 |
88 function testAdjust6() { | 101 function testAdjust6() { |
89 var sm = createSelectionModel(200); | 102 var sm = createSelectionModel(200); |
90 | 103 |
91 sm.leadIndex = sm.anchorIndex = 105; | 104 sm.leadIndex = sm.anchorIndex = 105; |
92 sm.selectRange(100, 110); | 105 sm.selectRange(100, 110); |
93 | 106 |
94 // Remove 100 - 105 | 107 // Remove 100 - 105 |
95 adjust(sm, 100, 5, 0); | 108 adjust(sm, 100, 5, 0); |
96 | 109 |
97 assertEquals('lead', 100, sm.leadIndex); | 110 assertEquals(100, sm.leadIndex, 'lead'); |
98 assertEquals('anchor', 100, sm.anchorIndex); | 111 assertEquals(100, sm.anchorIndex, 'anchor'); |
99 assertArrayEquals(range(100, 105), sm.selectedIndexes); | 112 assertArrayEquals(range(100, 105), sm.selectedIndexes); |
100 } | 113 } |
101 | 114 |
102 function testAdjust7() { | 115 function testAdjust7() { |
103 var sm = createSelectionModel(1); | 116 var sm = createSelectionModel(1); |
104 | 117 |
105 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 0; | 118 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 0; |
106 | 119 |
107 adjust(sm, 0, 0, 10); | 120 adjust(sm, 0, 0, 10); |
108 | 121 |
109 assertEquals('lead', 10, sm.leadIndex); | 122 assertEquals(10, sm.leadIndex, 'lead'); |
110 assertEquals('anchor', 10, sm.anchorIndex); | 123 assertEquals(10, sm.anchorIndex, 'anchor'); |
111 assertArrayEquals([10], sm.selectedIndexes); | 124 assertArrayEquals([10], sm.selectedIndexes); |
112 } | 125 } |
113 | 126 |
114 function testAdjust8() { | 127 function testAdjust8() { |
115 var sm = createSelectionModel(100); | 128 var sm = createSelectionModel(100); |
116 | 129 |
117 sm.leadIndex = sm.anchorIndex = 50; | 130 sm.leadIndex = sm.anchorIndex = 50; |
118 sm.selectAll(); | 131 sm.selectAll(); |
119 | 132 |
120 adjust(sm, 10, 80, 0); | 133 adjust(sm, 10, 80, 0); |
121 | 134 |
122 assertEquals('lead', -1, sm.leadIndex); | 135 assertEquals(-1, sm.leadIndex, 'lead'); |
123 assertEquals('anchor', -1, sm.anchorIndex); | 136 assertEquals(-1, sm.anchorIndex, 'anchor'); |
124 assertArrayEquals(range(0, 19), sm.selectedIndexes); | 137 assertArrayEquals(range(0, 19), sm.selectedIndexes); |
125 } | 138 } |
126 | 139 |
127 function testAdjust9() { | 140 function testAdjust9() { |
128 var sm = createSelectionModel(10); | 141 var sm = createSelectionModel(10); |
129 | 142 |
130 sm.leadIndex = sm.anchorIndex = 5; | 143 sm.leadIndex = sm.anchorIndex = 5; |
131 sm.selectAll(); | 144 sm.selectAll(); |
132 | 145 |
133 // Remove all | 146 // Remove all |
134 adjust(sm, 0, 10, 0); | 147 adjust(sm, 0, 10, 0); |
135 | 148 |
136 assertEquals('lead', -1, sm.leadIndex); | 149 assertEquals(-1, sm.leadIndex, 'lead'); |
137 assertEquals('anchor', -1, sm.anchorIndex); | 150 assertEquals(-1, sm.anchorIndex, 'anchor'); |
138 assertArrayEquals([], sm.selectedIndexes); | 151 assertArrayEquals([], sm.selectedIndexes); |
139 } | 152 } |
140 | 153 |
141 function testAdjust10() { | 154 function testAdjust10() { |
142 var sm = createSelectionModel(10); | 155 var sm = createSelectionModel(10); |
143 | 156 |
144 sm.leadIndex = sm.anchorIndex = 5; | 157 sm.leadIndex = sm.anchorIndex = 5; |
145 sm.selectAll(); | 158 sm.selectAll(); |
146 | 159 |
160 // Selection set to next item when selected items are removed (see | |
161 // crbug/81802). | |
Dan Beam
2013/06/20 18:23:39
if these bug references stay, make real links (so
kevers
2013/06/20 20:03:34
Removed comment.
| |
147 adjust(sm, 0, 10, 20); | 162 adjust(sm, 0, 10, 20); |
148 | 163 |
149 assertEquals('lead', -1, sm.leadIndex); | 164 assertEquals(5, sm.leadIndex, 'lead'); |
150 assertEquals('anchor', -1, sm.anchorIndex); | 165 assertEquals(5, sm.anchorIndex, 'anchor'); |
151 assertArrayEquals([], sm.selectedIndexes); | 166 assertArrayEquals([5], sm.selectedIndexes); |
152 } | 167 } |
153 | 168 |
154 function testAdjust11() { | 169 function testAdjust11() { |
155 var sm = createSelectionModel(20); | 170 var sm = createSelectionModel(20); |
156 | 171 |
157 sm.leadIndex = sm.anchorIndex = 10; | 172 sm.leadIndex = sm.anchorIndex = 10; |
158 sm.selectAll(); | 173 sm.selectAll(); |
159 | 174 |
160 adjust(sm, 5, 20, 10); | 175 adjust(sm, 5, 20, 10); |
161 | 176 |
162 assertEquals('lead', -1, sm.leadIndex); | 177 assertEquals(-1, sm.leadIndex, 'lead'); |
163 assertEquals('anchor', -1, sm.anchorIndex); | 178 assertEquals(-1, sm.anchorIndex, 'anchor'); |
164 assertArrayEquals(range(0, 4), sm.selectedIndexes); | 179 assertArrayEquals(range(0, 4), sm.selectedIndexes); |
165 } | 180 } |
166 | 181 |
167 function testAdjust12() { | 182 function testAdjust12() { |
168 var sm = createSelectionModel(20, true); | 183 var sm = createSelectionModel(20, true); |
169 | 184 |
170 sm.selectAll(); | 185 sm.selectAll(); |
171 sm.leadIndex = sm.anchorIndex = 10; | 186 sm.leadIndex = sm.anchorIndex = 10; |
172 | 187 |
173 adjust(sm, 5, 20, 10); | 188 adjust(sm, 5, 20, 10); |
174 | 189 |
175 assertEquals('lead', 4, sm.leadIndex); | 190 assertEquals(4, sm.leadIndex, 'lead'); |
176 assertEquals('anchor', 4, sm.anchorIndex); | 191 assertEquals(4, sm.anchorIndex, 'anchor'); |
177 assertArrayEquals(range(0, 4), sm.selectedIndexes); | 192 assertArrayEquals(range(0, 4), sm.selectedIndexes); |
178 } | 193 } |
179 | 194 |
180 function testAdjust13() { | 195 function testAdjust13() { |
181 var sm = createSelectionModel(20, true); | 196 var sm = createSelectionModel(20, true); |
182 | 197 |
183 sm.selectAll(); | 198 sm.selectAll(); |
184 sm.leadIndex = sm.anchorIndex = 15; | 199 sm.leadIndex = sm.anchorIndex = 15; |
185 | 200 |
186 adjust(sm, 5, 5, 0); | 201 adjust(sm, 5, 5, 0); |
187 | 202 |
188 assertEquals('lead', 10, sm.leadIndex); | 203 assertEquals(10, sm.leadIndex, 'lead'); |
189 assertEquals('anchor', 10, sm.anchorIndex); | 204 assertEquals(10, sm.anchorIndex, 'anchor'); |
190 assertArrayEquals(range(0, 14), sm.selectedIndexes); | 205 assertArrayEquals(range(0, 14), sm.selectedIndexes); |
191 } | 206 } |
192 | 207 |
193 function testLeadAndAnchor1() { | 208 function testLeadAndAnchor1() { |
194 var sm = createSelectionModel(20, true); | 209 var sm = createSelectionModel(20, true); |
195 | 210 |
196 sm.selectAll(); | 211 sm.selectAll(); |
197 sm.leadIndex = sm.anchorIndex = 10; | 212 sm.leadIndex = sm.anchorIndex = 10; |
198 | 213 |
199 assertEquals('lead', 10, sm.leadIndex); | 214 assertEquals(10, sm.leadIndex, 'lead'); |
200 assertEquals('anchor', 10, sm.anchorIndex); | 215 assertEquals(10, sm.anchorIndex, 'anchor'); |
201 } | 216 } |
202 | 217 |
203 function testLeadAndAnchor2() { | 218 function testLeadAndAnchor2() { |
204 var sm = createSelectionModel(20, true); | 219 var sm = createSelectionModel(20, true); |
205 | 220 |
206 sm.leadIndex = sm.anchorIndex = 10; | 221 sm.leadIndex = sm.anchorIndex = 10; |
207 sm.selectAll(); | 222 sm.selectAll(); |
208 | 223 |
209 assertEquals('lead', 19, sm.leadIndex); | 224 assertEquals(19, sm.leadIndex, 'lead'); |
210 assertEquals('anchor', 19, sm.anchorIndex); | 225 assertEquals(19, sm.anchorIndex, 'anchor'); |
211 } | 226 } |
212 | 227 |
213 </script> | 228 </script> |
214 | 229 |
215 </body> | 230 </body> |
216 </html> | 231 </html> |
OLD | NEW |