Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/test/data/webui/list_selection_model_test.html

Issue 17450012: Fix test failure in list_selection_model_test.html and port to automated browser test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Documentation tweaks. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
18 /**
19 * Creates an array spanning a range of integer values.
20 * @param{number} start The first number in the range.
21 * @param{nubmer} end The last number in the range inclusive.
Dan Beam 2013/06/20 21:38:03 @param\s, s/nubmer/number/
kevers 2013/06/21 13:30:49 Done.
22 * @return {Array.<number>}
Dan Beam 2013/06/20 21:38:03 !Array
kevers 2013/06/21 13:30:49 Done.
23 */
24 function range(start, end) {
25 var a = [];
26 for (var i = start; i <= end; i++) {
27 a.push(i);
28 }
29 return a;
30 }
31
32 /**
33 * Modifies a selection model.
34 * @param {!ListSelectionModel) sm The selection model to adjust.
Dan Beam 2013/06/20 21:38:03 s/)/}/
Dan Beam 2013/06/20 21:38:03 nit: s/sm/model/
kevers 2013/06/21 13:30:49 Done.
kevers 2013/06/21 13:30:49 Done.
35 * @param {number} index Starting index of the edit.
36 * @param {number} removed Number of entries to remove from the list.
37 * @param {number} added Number of entries to add to the list.
38 */
39 function adjust(sm, index, removed, added) {
40 var permutation = [];
41 for (var i = 0; i < index; i++) {
42 permutation.push(i);
43 }
44 for (var i = 0; i < removed; i++) {
45 permutation.push(-1);
46 }
47 for (var i = index + removed; i < sm.length; i++) {
48 permutation.push(i - removed + added);
49 }
50 sm.adjustLength(sm.length - removed + added);
51 sm.adjustToReordering(permutation);
52 }
53
30 function testAdjust1() { 54 function testAdjust1() {
31 var sm = createSelectionModel(200); 55 var sm = createSelectionModel(200);
32 56
33 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 100; 57 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 100;
34 adjust(sm, 0, 10, 0); 58 adjust(sm, 0, 10, 0);
35 59
36 assertEquals(90, sm.leadIndex); 60 assertEquals(90, sm.leadIndex);
37 assertEquals(90, sm.anchorIndex); 61 assertEquals(90, sm.anchorIndex);
38 assertEquals(90, sm.selectedIndex); 62 assertEquals(90, sm.selectedIndex);
39 } 63 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 assertArrayEquals(range(95, 105), sm.selectedIndexes); 97 assertArrayEquals(range(95, 105), sm.selectedIndexes);
74 } 98 }
75 99
76 function testAdjust5() { 100 function testAdjust5() {
77 var sm = createSelectionModel(100); 101 var sm = createSelectionModel(100);
78 102
79 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 99; 103 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 99;
80 104
81 adjust(sm, 99, 1, 0); 105 adjust(sm, 99, 1, 0);
82 106
83 assertEquals('lead', -1, sm.leadIndex); 107 assertEquals(98, sm.leadIndex, 'lead');
84 assertEquals('anchor', -1, sm.anchorIndex); 108 assertEquals(98, sm.anchorIndex, 'anchor');
85 assertArrayEquals([], sm.selectedIndexes); 109 assertArrayEquals([98], sm.selectedIndexes);
86 } 110 }
87 111
88 function testAdjust6() { 112 function testAdjust6() {
89 var sm = createSelectionModel(200); 113 var sm = createSelectionModel(200);
90 114
91 sm.leadIndex = sm.anchorIndex = 105; 115 sm.leadIndex = sm.anchorIndex = 105;
92 sm.selectRange(100, 110); 116 sm.selectRange(100, 110);
93 117
94 // Remove 100 - 105 118 // Remove 100 - 105
95 adjust(sm, 100, 5, 0); 119 adjust(sm, 100, 5, 0);
96 120
97 assertEquals('lead', 100, sm.leadIndex); 121 assertEquals(100, sm.leadIndex, 'lead');
98 assertEquals('anchor', 100, sm.anchorIndex); 122 assertEquals(100, sm.anchorIndex, 'anchor');
99 assertArrayEquals(range(100, 105), sm.selectedIndexes); 123 assertArrayEquals(range(100, 105), sm.selectedIndexes);
100 } 124 }
101 125
102 function testAdjust7() { 126 function testAdjust7() {
103 var sm = createSelectionModel(1); 127 var sm = createSelectionModel(1);
104 128
105 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 0; 129 sm.leadIndex = sm.anchorIndex = sm.selectedIndex = 0;
106 130
107 adjust(sm, 0, 0, 10); 131 adjust(sm, 0, 0, 10);
108 132
109 assertEquals('lead', 10, sm.leadIndex); 133 assertEquals(10, sm.leadIndex, 'lead');
110 assertEquals('anchor', 10, sm.anchorIndex); 134 assertEquals(10, sm.anchorIndex, 'anchor');
111 assertArrayEquals([10], sm.selectedIndexes); 135 assertArrayEquals([10], sm.selectedIndexes);
112 } 136 }
113 137
114 function testAdjust8() { 138 function testAdjust8() {
115 var sm = createSelectionModel(100); 139 var sm = createSelectionModel(100);
116 140
117 sm.leadIndex = sm.anchorIndex = 50; 141 sm.leadIndex = sm.anchorIndex = 50;
118 sm.selectAll(); 142 sm.selectAll();
119 143
120 adjust(sm, 10, 80, 0); 144 adjust(sm, 10, 80, 0);
121 145
122 assertEquals('lead', -1, sm.leadIndex); 146 assertEquals(-1, sm.leadIndex, 'lead');
123 assertEquals('anchor', -1, sm.anchorIndex); 147 assertEquals(-1, sm.anchorIndex, 'anchor');
124 assertArrayEquals(range(0, 19), sm.selectedIndexes); 148 assertArrayEquals(range(0, 19), sm.selectedIndexes);
125 } 149 }
126 150
127 function testAdjust9() { 151 function testAdjust9() {
128 var sm = createSelectionModel(10); 152 var sm = createSelectionModel(10);
129 153
130 sm.leadIndex = sm.anchorIndex = 5; 154 sm.leadIndex = sm.anchorIndex = 5;
131 sm.selectAll(); 155 sm.selectAll();
132 156
133 // Remove all 157 // Remove all
134 adjust(sm, 0, 10, 0); 158 adjust(sm, 0, 10, 0);
135 159
136 assertEquals('lead', -1, sm.leadIndex); 160 assertEquals(-1, sm.leadIndex, 'lead');
137 assertEquals('anchor', -1, sm.anchorIndex); 161 assertEquals(-1, sm.anchorIndex, 'anchor');
138 assertArrayEquals([], sm.selectedIndexes); 162 assertArrayEquals([], sm.selectedIndexes);
139 } 163 }
140 164
141 function testAdjust10() { 165 function testAdjust10() {
142 var sm = createSelectionModel(10); 166 var sm = createSelectionModel(10);
143 167
144 sm.leadIndex = sm.anchorIndex = 5; 168 sm.leadIndex = sm.anchorIndex = 5;
145 sm.selectAll(); 169 sm.selectAll();
146 170
147 adjust(sm, 0, 10, 20); 171 adjust(sm, 0, 10, 20);
148 172
149 assertEquals('lead', -1, sm.leadIndex); 173 assertEquals(5, sm.leadIndex, 'lead');
150 assertEquals('anchor', -1, sm.anchorIndex); 174 assertEquals(5, sm.anchorIndex, 'anchor');
151 assertArrayEquals([], sm.selectedIndexes); 175 assertArrayEquals([5], sm.selectedIndexes);
152 } 176 }
153 177
154 function testAdjust11() { 178 function testAdjust11() {
155 var sm = createSelectionModel(20); 179 var sm = createSelectionModel(20);
156 180
157 sm.leadIndex = sm.anchorIndex = 10; 181 sm.leadIndex = sm.anchorIndex = 10;
158 sm.selectAll(); 182 sm.selectAll();
159 183
160 adjust(sm, 5, 20, 10); 184 adjust(sm, 5, 20, 10);
161 185
162 assertEquals('lead', -1, sm.leadIndex); 186 assertEquals(-1, sm.leadIndex, 'lead');
163 assertEquals('anchor', -1, sm.anchorIndex); 187 assertEquals(-1, sm.anchorIndex, 'anchor');
164 assertArrayEquals(range(0, 4), sm.selectedIndexes); 188 assertArrayEquals(range(0, 4), sm.selectedIndexes);
165 } 189 }
166 190
167 function testAdjust12() { 191 function testAdjust12() {
168 var sm = createSelectionModel(20, true); 192 var sm = createSelectionModel(20, true);
169 193
170 sm.selectAll(); 194 sm.selectAll();
171 sm.leadIndex = sm.anchorIndex = 10; 195 sm.leadIndex = sm.anchorIndex = 10;
172 196
173 adjust(sm, 5, 20, 10); 197 adjust(sm, 5, 20, 10);
174 198
175 assertEquals('lead', 4, sm.leadIndex); 199 assertEquals(4, sm.leadIndex, 'lead');
176 assertEquals('anchor', 4, sm.anchorIndex); 200 assertEquals(4, sm.anchorIndex, 'anchor');
177 assertArrayEquals(range(0, 4), sm.selectedIndexes); 201 assertArrayEquals(range(0, 4), sm.selectedIndexes);
178 } 202 }
179 203
180 function testAdjust13() { 204 function testAdjust13() {
181 var sm = createSelectionModel(20, true); 205 var sm = createSelectionModel(20, true);
182 206
183 sm.selectAll(); 207 sm.selectAll();
184 sm.leadIndex = sm.anchorIndex = 15; 208 sm.leadIndex = sm.anchorIndex = 15;
185 209
186 adjust(sm, 5, 5, 0); 210 adjust(sm, 5, 5, 0);
187 211
188 assertEquals('lead', 10, sm.leadIndex); 212 assertEquals(10, sm.leadIndex, 'lead');
189 assertEquals('anchor', 10, sm.anchorIndex); 213 assertEquals(10, sm.anchorIndex, 'anchor');
190 assertArrayEquals(range(0, 14), sm.selectedIndexes); 214 assertArrayEquals(range(0, 14), sm.selectedIndexes);
191 } 215 }
192 216
193 function testLeadAndAnchor1() { 217 function testLeadAndAnchor1() {
194 var sm = createSelectionModel(20, true); 218 var sm = createSelectionModel(20, true);
195 219
196 sm.selectAll(); 220 sm.selectAll();
197 sm.leadIndex = sm.anchorIndex = 10; 221 sm.leadIndex = sm.anchorIndex = 10;
198 222
199 assertEquals('lead', 10, sm.leadIndex); 223 assertEquals(10, sm.leadIndex, 'lead');
200 assertEquals('anchor', 10, sm.anchorIndex); 224 assertEquals(10, sm.anchorIndex, 'anchor');
201 } 225 }
202 226
203 function testLeadAndAnchor2() { 227 function testLeadAndAnchor2() {
204 var sm = createSelectionModel(20, true); 228 var sm = createSelectionModel(20, true);
205 229
206 sm.leadIndex = sm.anchorIndex = 10; 230 sm.leadIndex = sm.anchorIndex = 10;
207 sm.selectAll(); 231 sm.selectAll();
208 232
209 assertEquals('lead', 19, sm.leadIndex); 233 assertEquals(19, sm.leadIndex, 'lead');
210 assertEquals('anchor', 19, sm.anchorIndex); 234 assertEquals(19, sm.anchorIndex, 'anchor');
211 } 235 }
212 236
213 </script> 237 </script>
214 238
215 </body> 239 </body>
216 </html> 240 </html>
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/webui/webui_resource_browsertest.cc » ('j') | chrome/test/data/webui/webui_resource_test.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698