OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2016 The Chromium Authors. All rights reserved. | 3 Copyright 2016 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/iteration_helpers.html"> | 8 <link rel="import" href="/tracing/base/iteration_helpers.html"> |
9 <link rel="import" href="/tracing/base/math/range.html"> | 9 <link rel="import" href="/tracing/base/math/range.html"> |
10 <link rel="import" href="/tracing/base/raf.html"> | 10 <link rel="import" href="/tracing/base/raf.html"> |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 Polymer.dom(document.body).appendChild(root); | 173 Polymer.dom(document.body).appendChild(root); |
174 try { | 174 try { |
175 const c = document.createElement('tr-v-ui-scalar-context-controller'); | 175 const c = document.createElement('tr-v-ui-scalar-context-controller'); |
176 Polymer.dom(root).appendChild(c); | 176 Polymer.dom(root).appendChild(c); |
177 | 177 |
178 let updatedGroups = []; // Fail if event fires unexpectedly. | 178 let updatedGroups = []; // Fail if event fires unexpectedly. |
179 c.addEventListener('context-updated', function(e) { | 179 c.addEventListener('context-updated', function(e) { |
180 if (updatedGroups) { | 180 if (updatedGroups) { |
181 assert.fail('Unexpected context-updated event fired.'); | 181 assert.fail('Unexpected context-updated event fired.'); |
182 } | 182 } |
183 updatedGroups = tr.b.asArray(e.groups); | 183 updatedGroups = Array.from(e.groups); |
184 }); | 184 }); |
185 | 185 |
186 c.expectContextUpdatedEventForTesting = | 186 c.expectContextUpdatedEventForTesting = |
187 function(expectedUpdatedGroups) { | 187 function(expectedUpdatedGroups) { |
188 updatedGroups = undefined; | 188 updatedGroups = undefined; |
189 tr.b.forceAllPendingTasksToRunForTest(); | 189 tr.b.forceAllPendingTasksToRunForTest(); |
190 assert.sameMembers(updatedGroups, expectedUpdatedGroups); | 190 assert.sameMembers(updatedGroups, expectedUpdatedGroups); |
191 }; | 191 }; |
192 | 192 |
193 testCallback.call(this, c); | 193 testCallback.call(this, c); |
194 } finally { | 194 } finally { |
195 Polymer.dom(document.body).removeChild(root); | 195 Polymer.dom(document.body).removeChild(root); |
196 } | 196 } |
197 }); | 197 }); |
198 } | 198 } |
199 | 199 |
200 contextTest('singleGroup', function(c) { | 200 contextTest('singleGroup', function(c) { |
201 assert.isUndefined(c.getContext('G')); | 201 assert.isUndefined(c.getContext('G')); |
202 | 202 |
203 const s1 = {value: 10}; | 203 const s1 = {value: 10}; |
204 c.onScalarSpanAdded('G', s1); | 204 c.onScalarSpanAdded('G', s1); |
205 c.expectContextUpdatedEventForTesting(['G']); | 205 c.expectContextUpdatedEventForTesting(['G']); |
206 assert.isTrue(c.getContext('G').range.equals( | 206 assert.isTrue(c.getContext('G').range.equals( |
207 tr.b.math.Range.fromExplicitRange(10, 10))); | 207 tr.b.math.Range.fromExplicitRange(10, 10))); |
208 assert.sameMembers(tr.b.asArray(c.getContext('G').spans), [s1]); | 208 assert.sameMembers(Array.from(c.getContext('G').spans), [s1]); |
209 | 209 |
210 const s2 = {value: 15}; | 210 const s2 = {value: 15}; |
211 c.onScalarSpanAdded('G', s2); | 211 c.onScalarSpanAdded('G', s2); |
212 c.expectContextUpdatedEventForTesting(['G']); | 212 c.expectContextUpdatedEventForTesting(['G']); |
213 assert.isTrue(c.getContext('G').range.equals( | 213 assert.isTrue(c.getContext('G').range.equals( |
214 tr.b.math.Range.fromExplicitRange(10, 15))); | 214 tr.b.math.Range.fromExplicitRange(10, 15))); |
215 assert.sameMembers(tr.b.asArray(c.getContext('G').spans), [s1, s2]); | 215 assert.sameMembers(Array.from(c.getContext('G').spans), [s1, s2]); |
216 | 216 |
217 s1.value = 5; | 217 s1.value = 5; |
218 c.onScalarSpanUpdated('G', s1); | 218 c.onScalarSpanUpdated('G', s1); |
219 c.expectContextUpdatedEventForTesting(['G']); | 219 c.expectContextUpdatedEventForTesting(['G']); |
220 assert.isTrue(c.getContext('G').range.equals( | 220 assert.isTrue(c.getContext('G').range.equals( |
221 tr.b.math.Range.fromExplicitRange(5, 15))); | 221 tr.b.math.Range.fromExplicitRange(5, 15))); |
222 assert.sameMembers(tr.b.asArray(c.getContext('G').spans), [s1, s2]); | 222 assert.sameMembers(Array.from(c.getContext('G').spans), [s1, s2]); |
223 | 223 |
224 c.onScalarSpanRemoved('G', s2); | 224 c.onScalarSpanRemoved('G', s2); |
225 c.expectContextUpdatedEventForTesting(['G']); | 225 c.expectContextUpdatedEventForTesting(['G']); |
226 assert.isTrue(c.getContext('G').range.equals( | 226 assert.isTrue(c.getContext('G').range.equals( |
227 tr.b.math.Range.fromExplicitRange(5, 5))); | 227 tr.b.math.Range.fromExplicitRange(5, 5))); |
228 assert.sameMembers(tr.b.asArray(c.getContext('G').spans), [s1]); | 228 assert.sameMembers(Array.from(c.getContext('G').spans), [s1]); |
229 | 229 |
230 const s3 = {value: 0}; | 230 const s3 = {value: 0}; |
231 c.onScalarSpanAdded('G', s3); | 231 c.onScalarSpanAdded('G', s3); |
232 s2.value = 14; | 232 s2.value = 14; |
233 c.onScalarSpanAdded('G', s2); | 233 c.onScalarSpanAdded('G', s2); |
234 c.expectContextUpdatedEventForTesting(['G']); | 234 c.expectContextUpdatedEventForTesting(['G']); |
235 assert.isTrue(c.getContext('G').range.equals( | 235 assert.isTrue(c.getContext('G').range.equals( |
236 tr.b.math.Range.fromExplicitRange(0, 14))); | 236 tr.b.math.Range.fromExplicitRange(0, 14))); |
237 assert.sameMembers(tr.b.asArray(c.getContext('G').spans), [s1, s2, s3]); | 237 assert.sameMembers(Array.from(c.getContext('G').spans), [s1, s2, s3]); |
238 | 238 |
239 c.onScalarSpanRemoved('G', s1); | 239 c.onScalarSpanRemoved('G', s1); |
240 c.onScalarSpanRemoved('G', s2); | 240 c.onScalarSpanRemoved('G', s2); |
241 c.onScalarSpanRemoved('G', s3); | 241 c.onScalarSpanRemoved('G', s3); |
242 c.expectContextUpdatedEventForTesting(['G']); | 242 c.expectContextUpdatedEventForTesting(['G']); |
243 assert.isUndefined(c.getContext('G')); | 243 assert.isUndefined(c.getContext('G')); |
244 | 244 |
245 c.onScalarSpanAdded('G', s2); | 245 c.onScalarSpanAdded('G', s2); |
246 c.expectContextUpdatedEventForTesting(['G']); | 246 c.expectContextUpdatedEventForTesting(['G']); |
247 assert.isTrue(c.getContext('G').range.equals( | 247 assert.isTrue(c.getContext('G').range.equals( |
248 tr.b.math.Range.fromExplicitRange(14, 14))); | 248 tr.b.math.Range.fromExplicitRange(14, 14))); |
249 assert.sameMembers(tr.b.asArray(c.getContext('G').spans), [s2]); | 249 assert.sameMembers(Array.from(c.getContext('G').spans), [s2]); |
250 }); | 250 }); |
251 | 251 |
252 contextTest('multipleGroups', function(c) { | 252 contextTest('multipleGroups', function(c) { |
253 assert.isUndefined(c.getContext('G1')); | 253 assert.isUndefined(c.getContext('G1')); |
254 assert.isUndefined(c.getContext('G2')); | 254 assert.isUndefined(c.getContext('G2')); |
255 | 255 |
256 const s1 = {value: 0}; | 256 const s1 = {value: 0}; |
257 c.onScalarSpanAdded('G1', s1); | 257 c.onScalarSpanAdded('G1', s1); |
258 c.expectContextUpdatedEventForTesting(['G1']); | 258 c.expectContextUpdatedEventForTesting(['G1']); |
259 assert.isTrue(c.getContext('G1').range.equals( | 259 assert.isTrue(c.getContext('G1').range.equals( |
260 tr.b.math.Range.fromExplicitRange(0, 0))); | 260 tr.b.math.Range.fromExplicitRange(0, 0))); |
261 assert.sameMembers(tr.b.asArray(c.getContext('G1').spans), [s1]); | 261 assert.sameMembers(Array.from(c.getContext('G1').spans), [s1]); |
262 | 262 |
263 const s2 = {value: 1}; | 263 const s2 = {value: 1}; |
264 c.onScalarSpanAdded('G2', s2); | 264 c.onScalarSpanAdded('G2', s2); |
265 c.expectContextUpdatedEventForTesting(['G2']); | 265 c.expectContextUpdatedEventForTesting(['G2']); |
266 assert.isTrue(c.getContext('G2').range.equals( | 266 assert.isTrue(c.getContext('G2').range.equals( |
267 tr.b.math.Range.fromExplicitRange(1, 1))); | 267 tr.b.math.Range.fromExplicitRange(1, 1))); |
268 assert.sameMembers(tr.b.asArray(c.getContext('G2').spans), [s2]); | 268 assert.sameMembers(Array.from(c.getContext('G2').spans), [s2]); |
269 | 269 |
270 const s3 = {value: 2}; | 270 const s3 = {value: 2}; |
271 const s4 = {value: -1}; | 271 const s4 = {value: -1}; |
272 c.onScalarSpanAdded('G2', s3); | 272 c.onScalarSpanAdded('G2', s3); |
273 c.onScalarSpanAdded('G1', s4); | 273 c.onScalarSpanAdded('G1', s4); |
274 c.expectContextUpdatedEventForTesting(['G1', 'G2']); | 274 c.expectContextUpdatedEventForTesting(['G1', 'G2']); |
275 assert.isTrue(c.getContext('G1').range.equals( | 275 assert.isTrue(c.getContext('G1').range.equals( |
276 tr.b.math.Range.fromExplicitRange(-1, 0))); | 276 tr.b.math.Range.fromExplicitRange(-1, 0))); |
277 assert.sameMembers(tr.b.asArray(c.getContext('G1').spans), [s1, s4]); | 277 assert.sameMembers(Array.from(c.getContext('G1').spans), [s1, s4]); |
278 assert.isTrue(c.getContext('G2').range.equals( | 278 assert.isTrue(c.getContext('G2').range.equals( |
279 tr.b.math.Range.fromExplicitRange(1, 2))); | 279 tr.b.math.Range.fromExplicitRange(1, 2))); |
280 assert.sameMembers(tr.b.asArray(c.getContext('G2').spans), [s2, s3]); | 280 assert.sameMembers(Array.from(c.getContext('G2').spans), [s2, s3]); |
281 | 281 |
282 c.onScalarSpanRemoved('G2', s3); | 282 c.onScalarSpanRemoved('G2', s3); |
283 c.onScalarSpanAdded('G1', s3); | 283 c.onScalarSpanAdded('G1', s3); |
284 c.expectContextUpdatedEventForTesting(['G1', 'G2']); | 284 c.expectContextUpdatedEventForTesting(['G1', 'G2']); |
285 assert.isTrue(c.getContext('G1').range.equals( | 285 assert.isTrue(c.getContext('G1').range.equals( |
286 tr.b.math.Range.fromExplicitRange(-1, 2))); | 286 tr.b.math.Range.fromExplicitRange(-1, 2))); |
287 assert.sameMembers(tr.b.asArray(c.getContext('G1').spans), [s1, s3, s4]); | 287 assert.sameMembers(Array.from(c.getContext('G1').spans), [s1, s3, s4]); |
288 assert.isTrue(c.getContext('G2').range.equals( | 288 assert.isTrue(c.getContext('G2').range.equals( |
289 tr.b.math.Range.fromExplicitRange(1, 1))); | 289 tr.b.math.Range.fromExplicitRange(1, 1))); |
290 assert.sameMembers(tr.b.asArray(c.getContext('G2').spans), [s2]); | 290 assert.sameMembers(Array.from(c.getContext('G2').spans), [s2]); |
291 | 291 |
292 s4.value = 3; | 292 s4.value = 3; |
293 c.onScalarSpanUpdated('G1', s4); | 293 c.onScalarSpanUpdated('G1', s4); |
294 s1.value = 1; | 294 s1.value = 1; |
295 c.onScalarSpanUpdated('G1', s1); | 295 c.onScalarSpanUpdated('G1', s1); |
296 c.expectContextUpdatedEventForTesting(['G1']); | 296 c.expectContextUpdatedEventForTesting(['G1']); |
297 assert.isTrue(c.getContext('G1').range.equals( | 297 assert.isTrue(c.getContext('G1').range.equals( |
298 tr.b.math.Range.fromExplicitRange(1, 3))); | 298 tr.b.math.Range.fromExplicitRange(1, 3))); |
299 assert.sameMembers(tr.b.asArray(c.getContext('G1').spans), [s1, s3, s4]); | 299 assert.sameMembers(Array.from(c.getContext('G1').spans), [s1, s3, s4]); |
300 assert.isTrue(c.getContext('G2').range.equals( | 300 assert.isTrue(c.getContext('G2').range.equals( |
301 tr.b.math.Range.fromExplicitRange(1, 1))); | 301 tr.b.math.Range.fromExplicitRange(1, 1))); |
302 assert.sameMembers(tr.b.asArray(c.getContext('G2').spans), [s2]); | 302 assert.sameMembers(Array.from(c.getContext('G2').spans), [s2]); |
303 | 303 |
304 c.onScalarSpanRemoved('G2', s2); | 304 c.onScalarSpanRemoved('G2', s2); |
305 c.expectContextUpdatedEventForTesting(['G2']); | 305 c.expectContextUpdatedEventForTesting(['G2']); |
306 assert.isTrue(c.getContext('G1').range.equals( | 306 assert.isTrue(c.getContext('G1').range.equals( |
307 tr.b.math.Range.fromExplicitRange(1, 3))); | 307 tr.b.math.Range.fromExplicitRange(1, 3))); |
308 assert.sameMembers(tr.b.asArray(c.getContext('G1').spans), [s1, s3, s4]); | 308 assert.sameMembers(Array.from(c.getContext('G1').spans), [s1, s3, s4]); |
309 assert.isUndefined(c.getContext('G2')); | 309 assert.isUndefined(c.getContext('G2')); |
310 }); | 310 }); |
311 }); | 311 }); |
312 </script> | 312 </script> |
OLD | NEW |