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>TimelineView tests</title> | 9 <title>TimelineView tests</title> |
10 <link rel="stylesheet" href="overlay.css"> | 10 <link rel="stylesheet" href="overlay.css"> |
11 <link rel="stylesheet" href="timeline.css"> | 11 <link rel="stylesheet" href="timeline.css"> |
| 12 <link rel="stylesheet" href="timeline_analysis.css"> |
12 <link rel="stylesheet" href="timeline_view.css"> | 13 <link rel="stylesheet" href="timeline_view.css"> |
13 <link rel="stylesheet" href="../shared/css/tabs.css"> | 14 <link rel="stylesheet" href="../shared/css/tabs.css"> |
14 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> | 15 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> |
15 <script src="../shared/js/cr.js"></script> | 16 <script src="../shared/js/cr.js"></script> |
16 <script src="../shared/js/cr/event_target.js"></script> | 17 <script src="../shared/js/cr/event_target.js"></script> |
17 <script src="../shared/js/cr/ui.js"></script> | 18 <script src="../shared/js/cr/ui.js"></script> |
18 <script src="../shared/js/cr/ui/tabs.js"></script> | 19 <script src="../shared/js/cr/ui/tabs.js"></script> |
19 <script src="overlay.js"></script> | 20 <script src="overlay.js"></script> |
20 <script src="measuring_stick.js"></script> | 21 <script src="measuring_stick.js"></script> |
21 <script src="profiling_view.js"></script> | 22 <script src="profiling_view.js"></script> |
| 23 <script src="timeline_analysis.js"></script> |
22 <script src="timeline_view.js"></script> | 24 <script src="timeline_view.js"></script> |
23 <script src="timeline_model.js"></script> | 25 <script src="timeline_model.js"></script> |
24 <script src="linux_perf_importer.js"></script> | 26 <script src="linux_perf_importer.js"></script> |
25 <script src="trace_event_importer.js"></script> | 27 <script src="trace_event_importer.js"></script> |
26 <script src="timeline.js"></script> | 28 <script src="timeline.js"></script> |
27 <script src="timeline_track.js"></script> | 29 <script src="timeline_track.js"></script> |
28 <script src="sorted_array_utils.js"></script> | 30 <script src="sorted_array_utils.js"></script> |
29 <script src="fast_rect_renderer.js"></script> | 31 <script src="fast_rect_renderer.js"></script> |
30 <script src="test_utils.js"></script> | 32 <script src="test_utils.js"></script> |
31 <script> | 33 <script> |
32 goog.require('goog.testing.jsunit'); | 34 goog.require('goog.testing.jsunit'); |
33 </script> | 35 </script> |
34 <style> | 36 <style> |
35 .timeline-view { | 37 .timeline-view { |
36 border: 1px solid black; | 38 border: 1px solid black; |
37 margin: 10px; | 39 margin: 10px; |
38 } | 40 } |
39 .timeline-find-dialog { | 41 .timeline-find-dialog { |
40 border: 1px solid black; | 42 border: 1px solid black; |
41 margin: 10px; | 43 margin: 10px; |
42 } | 44 } |
43 </style> | 45 </style> |
44 </head> | 46 </head> |
45 <body> | 47 <body> |
46 <script> | 48 <script> |
47 'use strict'; | 49 'use strict'; |
48 | 50 |
| 51 var assertArrayishEquals = test_utils.assertArrayishEquals; |
| 52 |
49 /* | 53 /* |
50 * Just enough of the Timeline to support the tests below. | 54 * Just enough of the Timeline to support the tests below. |
51 */ | 55 */ |
52 var FakeTimeline = cr.ui.define('div'); | 56 var FakeTimeline = cr.ui.define('div'); |
53 | 57 |
54 FakeTimeline.prototype = { | 58 FakeTimeline.prototype = { |
55 __proto__: HTMLDivElement.prototype, | 59 __proto__: HTMLDivElement.prototype, |
56 | 60 |
57 decorate: function() { | 61 decorate: function() { |
58 this.findAllObjectsMatchingFilterReturnValue = []; | 62 this.addAllObjectsMatchingFilterToSelectionReturnValue = []; |
59 | 63 |
60 this.selection = []; | 64 this.selection = new tracing.TimelineSelection(); |
61 this.keyHelp = "<keyHelp>"; | 65 this.keyHelp = "<keyHelp>"; |
62 | 66 |
63 // Put some simple UI in for testing purposes. | 67 // Put some simple UI in for testing purposes. |
64 var noteEl = document.createElement('div'); | 68 var noteEl = document.createElement('div'); |
65 noteEl.textContent = "FakeTimeline:"; | 69 noteEl.textContent = "FakeTimeline:"; |
66 this.appendChild(noteEl); | 70 this.appendChild(noteEl); |
67 | 71 |
68 this.statusEl_ = document.createElement('div'); | 72 this.statusEl_ = document.createElement('div'); |
69 this.appendChild(this.statusEl_); | 73 this.appendChild(this.statusEl_); |
70 this.refresh_(); | 74 this.refresh_(); |
71 }, | 75 }, |
72 | 76 |
73 refresh_: function() { | 77 refresh_: function() { |
74 var status; | 78 var status; |
75 if (this.model) | 79 if (this.model) |
76 status = "model=set"; | 80 status = "model=set"; |
77 else | 81 else |
78 status = "model=undefined"; | 82 status = "model=undefined"; |
79 this.statusEl_.textContent = status; | 83 this.statusEl_.textContent = status; |
80 }, | 84 }, |
81 | 85 |
82 setSelectionAndMakeVisible: function(selection, zoomAllowed) { | 86 setSelectionAndMakeVisible: function(selection, zoomAllowed) { |
83 this.selection = selection; | 87 this.selection = selection; |
84 }, | 88 }, |
85 | 89 |
86 findAllObjectsMatchingFilter: function(filter) { | 90 addAllObjectsMatchingFilterToSelection: function(filter, selection) { |
87 return this.findAllObjectsMatchingFilterReturnValue; | 91 var n = this.addAllObjectsMatchingFilterToSelectionReturnValue.length; |
| 92 for (var i = 0; i < n; i++) |
| 93 selection.push_( |
| 94 this.addAllObjectsMatchingFilterToSelectionReturnValue[i]); |
88 } | 95 } |
89 }; | 96 }; |
90 | 97 |
91 /* | 98 /* |
92 * This test just instantiates a TimelineView and adds it to the DOM | 99 * This test just instantiates a TimelineView and adds it to the DOM |
93 * to help with non-unittest UI work. | 100 * to help with non-unittest UI work. |
94 */ | 101 */ |
95 function testInstantiateTimelineView() { | 102 function testInstantiateTimelineView() { |
96 var events = [ | 103 var events = [ |
97 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, | 104 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 var controller = new tracing.TimelineFindController(); | 155 var controller = new tracing.TimelineFindController(); |
149 controller.findNext(); | 156 controller.findNext(); |
150 controller.findPrevious(); | 157 controller.findPrevious(); |
151 } | 158 } |
152 | 159 |
153 function testFindControllerEmptyHit() { | 160 function testFindControllerEmptyHit() { |
154 var timeline = new FakeTimeline(); | 161 var timeline = new FakeTimeline(); |
155 var controller = new tracing.TimelineFindController(); | 162 var controller = new tracing.TimelineFindController(); |
156 controller.timeline = timeline; | 163 controller.timeline = timeline; |
157 | 164 |
158 timeline.selection = []; | 165 timeline.selection = new tracing.TimelineSelection(); |
159 controller.findNext(); | 166 controller.findNext(); |
160 assertArrayEquals([], timeline.selection); | 167 assertArrayishEquals([], timeline.selection); |
161 controller.findPrevious(); | 168 controller.findPrevious(); |
162 assertArrayEquals([], timeline.selection); | 169 assertArrayishEquals([], timeline.selection); |
163 } | 170 } |
164 | 171 |
165 function testFindControllerOneHit() { | 172 function testFindControllerOneHit() { |
166 var timeline = new FakeTimeline(); | 173 var timeline = new FakeTimeline(); |
167 var controller = new tracing.TimelineFindController(); | 174 var controller = new tracing.TimelineFindController(); |
168 controller.timeline = timeline; | 175 controller.timeline = timeline; |
169 | 176 |
170 timeline.findAllObjectsMatchingFilterReturnValue = [1]; | 177 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1]; |
171 controller.findNext(); | 178 controller.findNext(); |
172 assertArrayEquals([1], timeline.selection); | 179 assertArrayishEquals([1], timeline.selection); |
173 controller.findNext(); | 180 controller.findNext(); |
174 assertArrayEquals([1], timeline.selection); | 181 assertArrayishEquals([1], timeline.selection); |
175 controller.findPrevious(); | 182 controller.findPrevious(); |
176 assertArrayEquals([1], timeline.selection); | 183 assertArrayishEquals([1], timeline.selection); |
177 } | 184 } |
178 | 185 |
179 function testFindControllerMultipleHits() { | 186 function testFindControllerMultipleHits() { |
180 var timeline = new FakeTimeline(); | 187 var timeline = new FakeTimeline(); |
181 var controller = new tracing.TimelineFindController(); | 188 var controller = new tracing.TimelineFindController(); |
182 controller.timeline = timeline; | 189 controller.timeline = timeline; |
183 | 190 |
184 timeline.findAllObjectsMatchingFilterReturnValue = [1,2,3]; | 191 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; |
185 | 192 |
186 // Loop through hits then when we wrap, try moving backward. | 193 // Loop through hits then when we wrap, try moving backward. |
187 controller.findNext(); | 194 controller.findNext(); |
188 assertArrayEquals([1], timeline.selection); | 195 assertArrayishEquals([1], timeline.selection); |
189 controller.findNext(); | 196 controller.findNext(); |
190 assertArrayEquals([2], timeline.selection); | 197 assertArrayishEquals([2], timeline.selection); |
191 controller.findNext(); | 198 controller.findNext(); |
192 assertArrayEquals([3], timeline.selection); | 199 assertArrayishEquals([3], timeline.selection); |
193 controller.findNext(); | 200 controller.findNext(); |
194 assertArrayEquals([1], timeline.selection); | 201 assertArrayishEquals([1], timeline.selection); |
195 controller.findPrevious(); | 202 controller.findPrevious(); |
196 assertArrayEquals([3], timeline.selection); | 203 assertArrayishEquals([3], timeline.selection); |
197 controller.findPrevious(); | 204 controller.findPrevious(); |
198 assertArrayEquals([2], timeline.selection); | 205 assertArrayishEquals([2], timeline.selection); |
199 } | 206 } |
200 | 207 |
201 function testFindControllerChangeFilterAfterNext() { | 208 function testFindControllerChangeFilterAfterNext() { |
202 var timeline = new FakeTimeline(); | 209 var timeline = new FakeTimeline(); |
203 var controller = new tracing.TimelineFindController(); | 210 var controller = new tracing.TimelineFindController(); |
204 controller.timeline = timeline; | 211 controller.timeline = timeline; |
205 | 212 |
206 timeline.findAllObjectsMatchingFilterReturnValue = [1,2,3]; | 213 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; |
207 | 214 |
208 // Loop through hits then when we wrap, try moving backward. | 215 // Loop through hits then when we wrap, try moving backward. |
209 controller.findNext(); | 216 controller.findNext(); |
210 timeline.findAllObjectsMatchingFilterReturnValue = [4]; | 217 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [4]; |
211 controller.filterText = "asdfsf"; | 218 controller.filterText = "asdfsf"; |
212 controller.findNext(); | 219 controller.findNext(); |
213 assertArrayEquals([4], timeline.selection); | 220 assertArrayishEquals([4], timeline.selection); |
214 } | 221 } |
215 | 222 |
216 function testFindControllerSelectsFirstItemImmediately() { | 223 function testFindControllerSelectsFirstItemImmediately() { |
217 var timeline = new FakeTimeline(); | 224 var timeline = new FakeTimeline(); |
218 var controller = new tracing.TimelineFindController(); | 225 var controller = new tracing.TimelineFindController(); |
219 controller.timeline = timeline; | 226 controller.timeline = timeline; |
220 timeline.findAllObjectsMatchingFilterReturnValue = [1,2,3]; | 227 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; |
221 controller.filterText = "asdfsf"; | 228 controller.filterText = "asdfsf"; |
222 assertArrayEquals([1], timeline.selection); | 229 assertArrayishEquals([1], timeline.selection); |
223 controller.findNext(); | 230 controller.findNext(); |
224 assertArrayEquals([2], timeline.selection); | 231 assertArrayishEquals([2], timeline.selection); |
225 } | 232 } |
226 | 233 |
227 function testFindControllerWithRealTimeline() { | 234 function testFindControllerWithRealTimeline() { |
228 var model = new tracing.TimelineModel(); | 235 var model = new tracing.TimelineModel(); |
229 var p1 = model.getOrCreateProcess(1); | 236 var p1 = model.getOrCreateProcess(1); |
230 var t1 = p1.getOrCreateThread(1); | 237 var t1 = p1.getOrCreateThread(1); |
231 t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3)); | 238 t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3)); |
232 | 239 |
233 var timeline = new tracing.Timeline(); | 240 var timeline = new tracing.Timeline(); |
234 timeline.model = model; | 241 timeline.model = model; |
(...skipping 13 matching lines...) Expand all Loading... |
248 controller.filterText = 'xxx'; | 255 controller.filterText = 'xxx'; |
249 controller.findNext(); | 256 controller.findNext(); |
250 assertEquals(0, timeline.selection.length); | 257 assertEquals(0, timeline.selection.length); |
251 controller.findNext(); | 258 controller.findNext(); |
252 assertEquals(0, timeline.selection.length); | 259 assertEquals(0, timeline.selection.length); |
253 } | 260 } |
254 | 261 |
255 </script> | 262 </script> |
256 </body> | 263 </body> |
257 </html> | 264 </html> |
OLD | NEW |