OLD | NEW |
1 <!DOCTYPE HTML> | 1 <!DOCTYPE HTML> |
2 <html> | 2 <html> |
3 <!-- | 3 <!-- |
4 Copyright (c) 2012 The Chromium Authors. All rights reserved. | 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. |
5 Use of this source code is governed by a BSD-style license that can be | 5 Use of this source code is governed by a BSD-style license that can be |
6 found in the LICENSE file. | 6 found in the LICENSE file. |
7 --> | 7 --> |
8 <head i18n-values="dir:textdirection;"> | 8 <head i18n-values="dir:textdirection;"> |
9 <title>TimelineTrack tests</title> | 9 <title>TimelineTrack tests</title> |
10 <script | 10 <script |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 <script> | 42 <script> |
43 'use strict'; | 43 'use strict'; |
44 | 44 |
45 var TimelineAsyncSlice = tracing.TimelineAsyncSlice; | 45 var TimelineAsyncSlice = tracing.TimelineAsyncSlice; |
46 var TimelineAsyncSliceGroup = tracing.TimelineAsyncSliceGroup; | 46 var TimelineAsyncSliceGroup = tracing.TimelineAsyncSliceGroup; |
47 var TimelineCounter = tracing.TimelineCounter; | 47 var TimelineCounter = tracing.TimelineCounter; |
48 var TimelineCounterTrack = tracing.TimelineCounterTrack; | 48 var TimelineCounterTrack = tracing.TimelineCounterTrack; |
49 var TimelineCpu = tracing.TimelineCpu; | 49 var TimelineCpu = tracing.TimelineCpu; |
50 var TimelineCpuTrack = tracing.TimelineCpuTrack; | 50 var TimelineCpuTrack = tracing.TimelineCpuTrack; |
51 var TimelineProcess = tracing.TimelineProcess; | 51 var TimelineProcess = tracing.TimelineProcess; |
| 52 var TimelineSelection = tracing.TimelineSelection; |
52 var TimelineSliceTrack = tracing.TimelineSliceTrack; | 53 var TimelineSliceTrack = tracing.TimelineSliceTrack; |
53 var TimelineSlice = tracing.TimelineSlice; | 54 var TimelineSlice = tracing.TimelineSlice; |
54 var TimelineThread = tracing.TimelineThread; | 55 var TimelineThread = tracing.TimelineThread; |
55 var TimelineThreadSlice = tracing.TimelineThreadSlice; | 56 var TimelineThreadSlice = tracing.TimelineThreadSlice; |
56 var TimelineThreadTrack = tracing.TimelineThreadTrack; | 57 var TimelineThreadTrack = tracing.TimelineThreadTrack; |
57 var TimelineViewport = tracing.TimelineViewport; | 58 var TimelineViewport = tracing.TimelineViewport; |
58 var testDivs = {}; | 59 var testDivs = {}; |
59 | 60 |
60 // Helper function to create a slice. | 61 // Helper function to create a slice. |
61 function newAsyncSlice(start, duration, startThread, endThread) { | 62 function newAsyncSlice(start, duration, startThread, endThread) { |
(...skipping 18 matching lines...) Expand all Loading... |
80 var track = TimelineSliceTrack(); | 81 var track = TimelineSliceTrack(); |
81 testEl.appendChild(track); | 82 testEl.appendChild(track); |
82 track.heading = 'testBasicSlices'; | 83 track.heading = 'testBasicSlices'; |
83 track.slices = [ | 84 track.slices = [ |
84 new TimelineSlice('a', 0, 1, {}, 1), | 85 new TimelineSlice('a', 0, 1, {}, 1), |
85 new TimelineSlice('b', 1, 2.1, {}, 4.8), | 86 new TimelineSlice('b', 1, 2.1, {}, 4.8), |
86 new TimelineSlice('b', 1, 7, {}, 0.5), | 87 new TimelineSlice('b', 1, 7, {}, 0.5), |
87 new TimelineSlice('c', 2, 7.6, {}, 0.4) | 88 new TimelineSlice('c', 2, 7.6, {}, 0.4) |
88 ]; | 89 ]; |
89 track.viewport = new TimelineViewport(testEl); | 90 track.viewport = new TimelineViewport(testEl); |
90 track.viewport.setPanAndScale(0, | 91 track.viewport.xSetWorldRange(0, 8.8, track.clientWidth); |
91 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); | |
92 } | 92 } |
93 | 93 |
94 function testFindAllObjectsMatchingInSliceTrack() { | 94 function testFindAllObjectsMatchingInSliceTrack() { |
95 var track = TimelineSliceTrack(); | 95 var track = TimelineSliceTrack(); |
96 track.slices = [ | 96 track.slices = [ |
97 new TimelineSlice('a', 0, 1, {}, 1), | 97 new TimelineSlice('a', 0, 1, {}, 1), |
98 new TimelineSlice('b', 1, 2.1, {}, 4.8), | 98 new TimelineSlice('b', 1, 2.1, {}, 4.8), |
99 new TimelineSlice('b', 1, 7, {}, 0.5), | 99 new TimelineSlice('b', 1, 7, {}, 0.5), |
100 new TimelineSlice('c', 2, 7.6, {}, 0.4) | 100 new TimelineSlice('c', 2, 7.6, {}, 0.4) |
101 ]; | 101 ]; |
102 var hits = track.findAllObjectsMatchingFilter( | 102 var selection = new TimelineSelection(); |
103 new tracing.TimelineFilter("b")); | 103 track.addAllObjectsMatchingFilterToSelection( |
104 assertEquals(2, hits.length); | 104 new tracing.TimelineFilter("b"), selection); |
105 assertEquals(track.slices[1], hits[0].slice); | 105 |
106 assertEquals(track.slices[2], hits[1].slice); | 106 assertEquals(2, selection.length); |
| 107 assertEquals(track.slices[1], selection[0].slice); |
| 108 assertEquals(track.slices[2], selection[1].slice); |
107 } | 109 } |
108 | 110 |
109 function testShrinkingSliceSizes() { | 111 function testShrinkingSliceSizes() { |
110 var testEl = getTestDiv('testShrinkingSliceSizes'); | 112 var testEl = getTestDiv('testShrinkingSliceSizes'); |
111 var track = TimelineSliceTrack(); | 113 var track = TimelineSliceTrack(); |
112 testEl.appendChild(track); | 114 testEl.appendChild(track); |
113 track.heading = 'testShrinkingSliceSizes'; | 115 track.heading = 'testShrinkingSliceSizes'; |
114 var x = 0; | 116 var x = 0; |
115 var widths = [10, 5, 4, 3, 2, 1, 0.5, 0.4, 0.3, 0.2, 0.1, 0.05]; | 117 var widths = [10, 5, 4, 3, 2, 1, 0.5, 0.4, 0.3, 0.2, 0.1, 0.05]; |
116 var slices = []; | 118 var slices = []; |
117 for (var i = 0; i < widths.length; i++) { | 119 for (var i = 0; i < widths.length; i++) { |
118 var s = new TimelineSlice('a', 1, x, {}, widths[i]); | 120 var s = new TimelineSlice('a', 1, x, {}, widths[i]); |
119 x += s.duration + 0.5; | 121 x += s.duration + 0.5; |
120 slices.push(s); | 122 slices.push(s); |
121 } | 123 } |
122 track.slices = slices; | 124 track.slices = slices; |
123 track.viewport = new TimelineViewport(testEl); | 125 track.viewport = new TimelineViewport(testEl); |
124 track.viewport.setPanAndScale(0, | 126 track.viewport.xSetWorldRange(0, 1.1 * x, track.clientWidth); |
125 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); | |
126 } | 127 } |
127 | 128 |
128 function testPick() { | 129 function testSelectionHitTesting() { |
129 var testEl = getTestDiv('testPick'); | 130 var testEl = getTestDiv('testSelectionHitTesting'); |
130 var track = TimelineSliceTrack(); | 131 var track = new TimelineSliceTrack(); |
131 testEl.appendChild(track); | 132 testEl.appendChild(track); |
132 track.heading = 'testPick'; | 133 track.heading = 'testSelectionHitTesting'; |
133 track.headingWidth = '100px'; | 134 track.headingWidth = '100px'; |
134 track.slices = [ | 135 track.slices = [ |
135 new TimelineSlice('a', 0, 1, {}, 1), | 136 new TimelineSlice('a', 0, 1, {}, 1), |
136 new TimelineSlice('b', 1, 2.1, {}, 4.8) | 137 new TimelineSlice('b', 1, 2.1, {}, 4.8) |
137 ]; | 138 ]; |
138 track.style.width = '500px'; | 139 track.style.width = '500px'; |
139 track.viewport = new TimelineViewport(testEl); | 140 track.viewport = new TimelineViewport(testEl); |
140 track.viewport.setPanAndScale(0, | 141 track.viewport.xSetWorldRange(0, 7.6, track.clientWidth); |
141 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); | |
142 var clientRect = track.getBoundingClientRect(); | 142 var clientRect = track.getBoundingClientRect(); |
143 | 143 |
144 var hits = []; | 144 var selection = new TimelineSelection(); |
145 track.pick(1.5, clientRect.top + 5, function(x, y, z) { hits.push(z); }); | 145 track.addIntersectingItemsToSelection(1.5, clientRect.top + 5, selection); |
146 assertEquals(track.slices[0], hits[0]); | 146 assertEquals(track.slices[0], selection[0].slice); |
147 | 147 |
148 hits = []; | 148 var selection = new TimelineSelection(); |
149 track.pick(2, clientRect.top + 5, function(x, y, z) { hits.push(z); }); | 149 track.addIntersectingItemsToSelection(2, clientRect.top + 5, selection); |
150 assertEquals(0, hits.length); | 150 assertEquals(0, selection.length); |
151 | 151 |
152 hits = []; | 152 var selection = new TimelineSelection(); |
153 track.pick(6.8, clientRect.top + 5, function(x, y, z) { hits.push(z); }); | 153 track.addIntersectingItemsToSelection(6.8, clientRect.top + 5, selection); |
154 assertEquals(track.slices[1], hits[0]); | 154 assertEquals(track.slices[1], selection[0].slice); |
155 | 155 |
156 hits = []; | 156 var selection = new TimelineSelection(); |
157 track.pick(6.9, clientRect.top + 5, function(x, y, z) { hits.push(z); }); | 157 track.addIntersectingItemsToSelection(6.9, clientRect.top + 5, selection); |
158 assertEquals(0, hits.length); | 158 assertEquals(0, selection.length); |
| 159 } |
| 160 |
| 161 function testSelectionHitTestingWithTimelineThreadTrack() { |
| 162 var model = new tracing.TimelineModel(); |
| 163 var p1 = model.getOrCreateProcess(1); |
| 164 var t1 = p1.getOrCreateThread(1); |
| 165 t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 5)); |
| 166 t1.subRows[0].push(new tracing.TimelineThreadSlice('b', 0, 5.1, {}, 4)); |
| 167 |
| 168 var testEl = getTestDiv('testSelectionHitTestingWithTimelineThreadTrack'); |
| 169 var track = new tracing.TimelineThreadTrack(); |
| 170 testEl.appendChild(track); |
| 171 track.heading = 'testSelectionHitTestingWithTimelineThreadTrack'; |
| 172 track.headingWidth = '100px'; |
| 173 track.thread = t1; |
| 174 |
| 175 track.style.width = '500px'; |
| 176 track.viewport = new TimelineViewport(testEl); |
| 177 track.viewport.xSetWorldRange(0, 10, track.clientWidth); |
| 178 var clientRect = track.getBoundingClientRect(); |
| 179 |
| 180 var selection = new TimelineSelection(); |
| 181 track.addIntersectingItemsToSelection(1.5, clientRect.top + 5, selection); |
| 182 assertEquals(t1.subRows[0][0], selection[0].slice); |
| 183 |
| 184 var selection = new TimelineSelection(); |
| 185 track.addIntersectingItemsInRangeToSelection(1.5, 1.8, clientRect.top + 5, c
lientRect.top + 7, selection); |
| 186 assertEquals(t1.subRows[0][0], selection[0].slice); |
159 } | 187 } |
160 | 188 |
161 function testBasicCpu() { | 189 function testBasicCpu() { |
162 var testEl = getTestDiv('testBasicCpu'); | 190 var testEl = getTestDiv('testBasicCpu'); |
163 | 191 |
164 var cpu = new TimelineCpu(7); | 192 var cpu = new TimelineCpu(7); |
165 cpu.slices = [ | 193 cpu.slices = [ |
166 new TimelineSlice('a', 0, 1, {}, 1), | 194 new TimelineSlice('a', 0, 1, {}, 1), |
167 new TimelineSlice('b', 1, 2.1, {}, 4.8) | 195 new TimelineSlice('b', 1, 2.1, {}, 4.8) |
168 ]; | 196 ]; |
169 cpu.updateBounds(); | 197 cpu.updateBounds(); |
170 | 198 |
171 var track = TimelineCpuTrack(); | 199 var track = TimelineCpuTrack(); |
172 testEl.appendChild(track); | 200 testEl.appendChild(track); |
173 track.heading = 'CPU ' + cpu.cpuNumber; | 201 track.heading = 'CPU ' + cpu.cpuNumber; |
174 track.cpu = cpu; | 202 track.cpu = cpu; |
175 track.viewport = new TimelineViewport(testEl); | 203 track.viewport = new TimelineViewport(testEl); |
176 track.viewport.setPanAndScale(0, | 204 track.viewport.xSetWorldRange(0, 11.1, track.clientWidth); |
177 track.clientWidth / (1.1 * cpu.maxTimestamp)); | |
178 } | 205 } |
179 | 206 |
180 function testViewport() { | 207 function testViewport() { |
181 var testEl = getTestDiv('testViewport'); | 208 var testEl = getTestDiv('testViewport'); |
182 | 209 |
183 var track = tracing.TimelineViewportTrack(); | 210 var track = tracing.TimelineViewportTrack(); |
184 testEl.appendChild(track); | 211 testEl.appendChild(track); |
185 track.viewport = new TimelineViewport(testEl); | 212 track.viewport = new TimelineViewport(testEl); |
186 track.viewport.setPanAndScale(0, | 213 track.viewport.setPanAndScale(0, |
187 track.clientWidth / 1000); | 214 track.clientWidth / 1000); |
(...skipping 16 matching lines...) Expand all Loading... |
204 1, 7, | 231 1, 7, |
205 3, 0, | 232 3, 0, |
206 3.1, 0.5]; | 233 3.1, 0.5]; |
207 ctr.updateBounds(); | 234 ctr.updateBounds(); |
208 | 235 |
209 var track = new TimelineCounterTrack(); | 236 var track = new TimelineCounterTrack(); |
210 testEl.appendChild(track); | 237 testEl.appendChild(track); |
211 track.heading = ctr.name; | 238 track.heading = ctr.name; |
212 track.counter = ctr; | 239 track.counter = ctr; |
213 track.viewport = new TimelineViewport(testEl); | 240 track.viewport = new TimelineViewport(testEl); |
214 track.viewport.setPanAndScale(0, | 241 track.viewport.xSetWorldRange(0, 7.7, track.clientWidth); |
215 track.clientWidth / (1.1 * ctr.maxTimestamp)); | 242 } |
| 243 |
| 244 function runOffscreenCounterTest(timestamps, samples, testFn) { |
| 245 var testEl = document.createElement('div'); |
| 246 var ctr = new TimelineCounter(undefined, |
| 247 'foo', 'foo'); |
| 248 var n = samples.length / timestamps.length; |
| 249 ctr.timestamps = timestamps; |
| 250 ctr.samples = samples; |
| 251 ctr.seriesNames = [] |
| 252 ctr.seriesColors = [] |
| 253 for (var i = 0; i < n; ++i) { |
| 254 ctr.seriesNames.push('value' + i); |
| 255 ctr.seriesColors.push(tracing.getStringColorId(ctr.seriesNames[i])); |
| 256 } |
| 257 ctr.updateBounds(); |
| 258 |
| 259 var track = new TimelineCounterTrack(); |
| 260 testEl.appendChild(track); |
| 261 document.body.appendChild(testEl); |
| 262 |
| 263 track.heading = ctr.name; |
| 264 track.counter = ctr; |
| 265 track.viewport = new TimelineViewport(testEl); |
| 266 track.viewport.xSetWorldRange(0, 10, track.clientWidth); |
| 267 |
| 268 try { |
| 269 testFn(ctr, track); |
| 270 } finally { |
| 271 document.body.removeChild(testEl); |
| 272 } |
| 273 } |
| 274 |
| 275 function testBasicCounterXPointPicking() { |
| 276 var timestamps = [0, 1, 2, 3, 4, 5, 6, 7]; |
| 277 var samples = [0, 5, |
| 278 3, 3, |
| 279 1, 1, |
| 280 2, 1.1, |
| 281 3, 0, |
| 282 1, 7, |
| 283 3, 0, |
| 284 3.1, 0.5]; |
| 285 runOffscreenCounterTest(timestamps, samples, function(ctr, track) { |
| 286 var clientRect = track.getBoundingClientRect(); |
| 287 var y75 = clientRect.top + 0.75 * clientRect.height; |
| 288 var sel; |
| 289 |
| 290 // In bounds. |
| 291 sel = new tracing.TimelineSelection(); |
| 292 track.addIntersectingItemsToSelection(1.5, y75, sel); |
| 293 assertEquals(1, sel.length); |
| 294 assertEquals(track, sel[0].track); |
| 295 assertEquals(ctr, sel[0].counter); |
| 296 assertEquals(1, sel[0].sampleIndex); |
| 297 |
| 298 // Outside bouds. |
| 299 sel = new tracing.TimelineSelection(); |
| 300 track.addIntersectingItemsToSelection(-1, y75, sel); |
| 301 assertEquals(0, sel.length); |
| 302 |
| 303 sel = new tracing.TimelineSelection(); |
| 304 track.addIntersectingItemsToSelection(8, y75, sel); |
| 305 assertEquals(0, sel.length); |
| 306 }); |
216 } | 307 } |
217 | 308 |
218 /* You'll need visual inspection to test eliding with this one. */ | 309 /* You'll need visual inspection to test eliding with this one. */ |
219 function testElideVisualInspection() { | 310 function testElideVisualInspection() { |
220 var optDicts = [{ trackName: 'elideOff', elide: false }, | 311 var optDicts = [{ trackName: 'elideOff', elide: false }, |
221 { trackName: 'elideOn', elide: true }]; | 312 { trackName: 'elideOn', elide: true }]; |
222 for (var dictIndex in optDicts) { | 313 for (var dictIndex in optDicts) { |
223 var dict = optDicts[dictIndex]; | 314 var dict = optDicts[dictIndex]; |
224 var testEl = getTestDiv(dict.trackName); | 315 var testEl = getTestDiv(dict.trackName); |
225 var track = TimelineSliceTrack(); | 316 var track = new TimelineSliceTrack(); |
226 if (dict.elide) { | 317 if (dict.elide) { |
227 track.SHOULD_ELIDE_TEXT = true; | 318 track.SHOULD_ELIDE_TEXT = true; |
228 } else { | 319 } else { |
229 track.SHOULD_ELIDE_TEXT = false; | 320 track.SHOULD_ELIDE_TEXT = false; |
230 } | 321 } |
231 var tooLongTitle = 'Unless eliding this SHOULD NOT BE DISPLAYED. '; | 322 var tooLongTitle = 'Unless eliding this SHOULD NOT BE DISPLAYED. '; |
232 var bigTitle = 'Very big title name that goes on longer ' + | 323 var bigTitle = 'Very big title name that goes on longer ' + |
233 'than you may expect'; | 324 'than you may expect'; |
234 testEl.appendChild(track); | 325 testEl.appendChild(track); |
235 track.heading = 'Visual: ' + dict.trackName; | 326 track.heading = 'Visual: ' + dict.trackName; |
236 track.slices = [ | 327 track.slices = [ |
237 // title, colorId, start, args, opt_duration | 328 // title, colorId, start, args, opt_duration |
238 new TimelineSlice('a ' + tooLongTitle + bigTitle, 0, 1, {}, 1), | 329 new TimelineSlice('a ' + tooLongTitle + bigTitle, 0, 1, {}, 1), |
239 new TimelineSlice(bigTitle, 1, 2.1, {}, 4.8), | 330 new TimelineSlice(bigTitle, 1, 2.1, {}, 4.8), |
240 new TimelineSlice('cccc cccc cccc', 1, 7, {}, 0.5), | 331 new TimelineSlice('cccc cccc cccc', 1, 7, {}, 0.5), |
241 new TimelineSlice('d', 2, 7.6, {}, 1.0) | 332 new TimelineSlice('d', 2, 7.6, {}, 1.0) |
242 ]; | 333 ]; |
243 track.viewport = new TimelineViewport(testEl); | 334 track.viewport = new TimelineViewport(testEl); |
244 track.viewport.setPanAndScale(0, | 335 track.viewport.xSetWorldRange(0, 9.5, track.clientWidth); |
245 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); | |
246 } | 336 } |
247 } | 337 } |
248 | 338 |
249 function testElide() { | 339 function testElide() { |
250 var testEl = getTestDiv('testElide'); | 340 var testEl = getTestDiv('testElide'); |
251 var track = TimelineSliceTrack(); | 341 var track = new TimelineSliceTrack(); |
252 testEl.appendChild(track); | 342 testEl.appendChild(track); |
253 var bigtitle = 'Super duper long long title ' + | 343 var bigtitle = 'Super duper long long title ' + |
254 'holy moly when did you get so verbose?'; | 344 'holy moly when did you get so verbose?'; |
255 var smalltitle = 'small'; | 345 var smalltitle = 'small'; |
256 track.viewport = new TimelineViewport(testEl); | 346 track.viewport = new TimelineViewport(testEl); |
257 track.heading = 'testElide'; | 347 track.heading = 'testElide'; |
258 track.slices = [ | 348 track.slices = [ |
259 // title, colorId, start, args, opt_duration | 349 // title, colorId, start, args, opt_duration |
260 new TimelineSlice(bigtitle, 0, 1, {}, 1), | 350 new TimelineSlice(bigtitle, 0, 1, {}, 1), |
261 new TimelineSlice(smalltitle, 1, 2, {}, 1) | 351 new TimelineSlice(smalltitle, 1, 2, {}, 1) |
262 ]; | 352 ]; |
263 track.viewport = new TimelineViewport(testEl); | 353 track.viewport = new TimelineViewport(testEl); |
264 track.viewport.setPanAndScale(0, | 354 track.viewport.xSetWorldRange(0, 3.3, track.clientWidth); |
265 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); | |
266 var stringWidthPair = undefined; | 355 var stringWidthPair = undefined; |
267 var pixWidth = track.viewport_.xViewVectorToWorld(1); | 356 var pixWidth = track.viewport_.xViewVectorToWorld(1); |
268 | 357 |
269 // Small titles on big slices are not elided. | 358 // Small titles on big slices are not elided. |
270 stringWidthPair = track.elidedTitleCache.get(track, pixWidth, smalltitle, | 359 stringWidthPair = track.elidedTitleCache.get(track, pixWidth, smalltitle, |
271 track.labelWidth(smalltitle), 1); | 360 track.labelWidth(smalltitle), 1); |
272 assertEquals(smalltitle, stringWidthPair.string); | 361 assertEquals(smalltitle, stringWidthPair.string); |
273 // Keep shrinking the slice until eliding starts. | 362 // Keep shrinking the slice until eliding starts. |
274 var elidedWhenSmallEnough = false; | 363 var elidedWhenSmallEnough = false; |
275 for (var sliceLength = 1; sliceLength >= 0.00001; sliceLength /= 2.0) { | 364 for (var sliceLength = 1; sliceLength >= 0.00001; sliceLength /= 2.0) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 new TimelineThreadSlice('d', 3, 1.1, {}, 0.8), | 401 new TimelineThreadSlice('d', 3, 1.1, {}, 0.8), |
313 new TimelineThreadSlice('e', 4, 7.1, {}, 0.3) | 402 new TimelineThreadSlice('e', 4, 7.1, {}, 0.3) |
314 ] | 403 ] |
315 ]; | 404 ]; |
316 thread.updateBounds(); | 405 thread.updateBounds(); |
317 track.heading = 'thread regular'; | 406 track.heading = 'thread regular'; |
318 track.headingWidth = '150px'; | 407 track.headingWidth = '150px'; |
319 track.toolTip = thread.userFriendlyDetails + ':'; | 408 track.toolTip = thread.userFriendlyDetails + ':'; |
320 track.thread = thread; | 409 track.thread = thread; |
321 track.viewport = new TimelineViewport(testEl); | 410 track.viewport = new TimelineViewport(testEl); |
322 track.viewport.setPanAndScale(0, | 411 track.viewport.xSetWorldRange(0, 8.2, track.clientWidth); |
323 track.clientWidth / | |
324 (1.1 * (thread.maxTimestamp - thread.minTimestamp))); | |
325 } | 412 } |
326 | 413 |
327 function testTimelineThreadTrackWithTallSlices() { | 414 function testTimelineThreadTrackWithTallSlices() { |
328 var testEl = getTestDiv('testTimelineThreadTrackWithTallSlices'); | 415 var testEl = getTestDiv('testTimelineThreadTrackWithTallSlices'); |
329 var track = TimelineThreadTrack(); | 416 var track = TimelineThreadTrack(); |
330 testEl.appendChild(track); | 417 testEl.appendChild(track); |
331 track.heading = 'testTimelineThreadTrackWithTallSlices'; | 418 track.heading = 'testTimelineThreadTrackWithTallSlices'; |
332 var thread = new TimelineThread(new TimelineProcess(7), 1); | 419 var thread = new TimelineThread(new TimelineProcess(7), 1); |
333 thread.subRows = [ | 420 thread.subRows = [ |
334 [new TimelineThreadSlice('a', 1, 0, {}, 1)], | 421 [new TimelineThreadSlice('a', 1, 0, {}, 1)], |
335 [new TimelineThreadSlice('b', 2, 0.1, {}, 0.8)], | 422 [new TimelineThreadSlice('b', 2, 0.1, {}, 0.8)], |
336 [new TimelineThreadSlice('c', 3, 0.15, {}, 0.70)], | 423 [new TimelineThreadSlice('c', 3, 0.15, {}, 0.70)], |
337 [new TimelineThreadSlice('d', 4, 0.20, {}, 0.50)], | 424 [new TimelineThreadSlice('d', 4, 0.20, {}, 0.50)], |
338 [new TimelineThreadSlice('e', 5, 0.30, {}, 0.28)], | 425 [new TimelineThreadSlice('e', 5, 0.30, {}, 0.28)], |
339 [new TimelineThreadSlice('e', 6, 0.35, {}, 0.20)], | 426 [new TimelineThreadSlice('e', 6, 0.35, {}, 0.20)], |
340 [new TimelineThreadSlice('f', 7, 0.40, {}, 0.10)] | 427 [new TimelineThreadSlice('f', 7, 0.40, {}, 0.10)] |
341 ]; | 428 ]; |
342 thread.updateBounds(); | 429 thread.updateBounds(); |
343 track.heading = 'thread tall'; | 430 track.heading = 'thread tall'; |
344 track.headingWidth = '150px'; | 431 track.headingWidth = '150px'; |
345 track.toolTip = thread.userFriendlyDetails + ':'; | 432 track.toolTip = thread.userFriendlyDetails + ':'; |
346 track.thread = thread; | 433 track.thread = thread; |
347 track.viewport = new TimelineViewport(testEl); | 434 track.viewport = new TimelineViewport(testEl); |
348 track.viewport.setPanAndScale(0, | 435 track.viewport.xSetWorldRange(0, 1.1, track.clientWidth); |
349 track.clientWidth | |
350 / (1.1 * (thread.maxTimestamp - thread.minTimestamp))); | |
351 } | 436 } |
352 | 437 |
353 function testTimelineThreadTrackWithRegularAndAsyncSlices() { | 438 function testTimelineThreadTrackWithRegularAndAsyncSlices() { |
354 var testEl = getTestDiv('testTimelineThreadTrackWithAsyncSlices'); | 439 var testEl = getTestDiv('testTimelineThreadTrackWithAsyncSlices'); |
355 var track = TimelineThreadTrack(); | 440 var track = TimelineThreadTrack(); |
356 testEl.appendChild(track); | 441 testEl.appendChild(track); |
357 var thread = new TimelineThread(new TimelineProcess(7), 1); | 442 var thread = new TimelineThread(new TimelineProcess(7), 1); |
358 thread.subRows = [ | 443 thread.subRows = [ |
359 [ | 444 [ |
360 new TimelineThreadSlice('a', 0, 1, {}, 1), | 445 new TimelineThreadSlice('a', 0, 1, {}, 1), |
361 new TimelineThreadSlice('b', 1, 2.1, {}, 4.8), | 446 new TimelineThreadSlice('b', 1, 2.1, {}, 4.8), |
362 new TimelineThreadSlice('b', 1, 7, {}, 0.5), | 447 new TimelineThreadSlice('b', 1, 7, {}, 0.5), |
363 new TimelineThreadSlice('c', 2, 7.6, {}, 0.4) | 448 new TimelineThreadSlice('c', 2, 7.6, {}, 0.4) |
364 ], | 449 ], |
365 [ | 450 [ |
366 new TimelineThreadSlice('d', 3, 1.1, {}, 0.8), | 451 new TimelineThreadSlice('d', 3, 1.1, {}, 0.8), |
367 new TimelineThreadSlice('e', 4, 7.1, {}, 0.3) | 452 new TimelineThreadSlice('e', 4, 7.1, {}, 0.3) |
368 ] | 453 ] |
369 ]; | 454 ]; |
370 thread.asyncSlices.push(newAsyncSlice(1.2, 7.2 - 1.2, thread, thread)); | 455 thread.asyncSlices.push(newAsyncSlice(1.2, 7.2 - 1.2, thread, thread)); |
371 thread.asyncSlices.push(newAsyncSlice(1.3, 7.3 - 1.3, thread, thread)); | 456 thread.asyncSlices.push(newAsyncSlice(1.3, 7.3 - 1.3, thread, thread)); |
372 thread.updateBounds(); | 457 thread.updateBounds(); |
373 track.heading = 'thread regular + async'; | 458 track.heading = 'thread regular + async'; |
374 track.headingWidth = '150px'; | 459 track.headingWidth = '150px'; |
375 track.toolTip = thread.userFriendlyDetails + ':'; | 460 track.toolTip = thread.userFriendlyDetails + ':'; |
376 track.thread = thread; | 461 track.thread = thread; |
377 track.viewport = new TimelineViewport(testEl); | 462 track.viewport = new TimelineViewport(testEl); |
378 track.viewport.setPanAndScale(0, | 463 track.viewport.xSetWorldRange(0, 8.15, track.clientWidth); |
379 track.clientWidth / | |
380 (1.1 * (thread.maxTimestamp - thread.minTimestamp))); | |
381 } | 464 } |
382 | 465 |
| 466 function testTimelineSliceTrackAddItemNearToProvidedHit() { |
| 467 var track = new TimelineSliceTrack(); |
| 468 track.slices = [ |
| 469 new TimelineSlice('a', 0, 1, {}, 1), |
| 470 new TimelineSlice('b', 1, 2.1, {}, 4.8), |
| 471 new TimelineSlice('b', 1, 7, {}, 0.5), |
| 472 new TimelineSlice('c', 2, 7.6, {}, 0.4) |
| 473 ]; |
| 474 var sel = new tracing.TimelineSelection(); |
| 475 track.addAllObjectsMatchingFilterToSelection(new tracing.TimelineFilter("b")
, sel); |
| 476 var ret; |
| 477 |
| 478 // Select to the right of B. |
| 479 var selRight = new tracing.TimelineSelection(); |
| 480 ret = track.addItemNearToProvidedHitToSelection(sel[0], 1, selRight); |
| 481 assertTrue(ret); |
| 482 assertEquals(track.slices[2], selRight[0].slice); |
| 483 |
| 484 // Select to the right of the 2nd b. |
| 485 var selRight2 = new tracing.TimelineSelection(); |
| 486 ret = track.addItemNearToProvidedHitToSelection(sel[0], 2, selRight2); |
| 487 assertTrue(ret); |
| 488 assertEquals(track.slices[3], selRight2[0].slice); |
| 489 |
| 490 // Select to 2 to the right of the 2nd b. |
| 491 var selRightOfRight = new tracing.TimelineSelection(); |
| 492 ret = track.addItemNearToProvidedHitToSelection(selRight[0], 1, selRightOfRi
ght); |
| 493 assertTrue(ret); |
| 494 assertEquals(track.slices[3], selRightOfRight[0].slice); |
| 495 |
| 496 // Select to the right of the rightmost slice. |
| 497 var selNone = new tracing.TimelineSelection(); |
| 498 ret = track.addItemNearToProvidedHitToSelection(selRightOfRight[0], 1, selNo
ne); |
| 499 assertFalse(ret); |
| 500 assertEquals(0, selNone.length); |
| 501 |
| 502 // Select A and then select left. |
| 503 var sel = new tracing.TimelineSelection(); |
| 504 track.addAllObjectsMatchingFilterToSelection(new tracing.TimelineFilter("a")
, sel); |
| 505 var ret; |
| 506 |
| 507 selNone = new tracing.TimelineSelection(); |
| 508 ret = track.addItemNearToProvidedHitToSelection(sel[0], -1, selNone); |
| 509 assertFalse(ret); |
| 510 assertEquals(0, selNone.length); |
| 511 |
| 512 } |
383 </script> | 513 </script> |
384 </body> | 514 </body> |
385 </html> | 515 </html> |
OLD | NEW |