Chromium Code Reviews| 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_(this.addAllObjectsMatchingFilterToSelectionReturnValue [i]); | |
|
jbates
2012/04/23 20:44:24
nit: 80 chars
| |
| 88 } | 94 } |
| 89 }; | 95 }; |
| 90 | 96 |
| 91 /* | 97 /* |
| 92 * This test just instantiates a TimelineView and adds it to the DOM | 98 * This test just instantiates a TimelineView and adds it to the DOM |
| 93 * to help with non-unittest UI work. | 99 * to help with non-unittest UI work. |
| 94 */ | 100 */ |
| 95 function testInstantiateTimelineView() { | 101 function testInstantiateTimelineView() { |
| 96 var events = [ | 102 var events = [ |
| 97 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, | 103 {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(); | 154 var controller = new tracing.TimelineFindController(); |
| 149 controller.findNext(); | 155 controller.findNext(); |
| 150 controller.findPrevious(); | 156 controller.findPrevious(); |
| 151 } | 157 } |
| 152 | 158 |
| 153 function testFindControllerEmptyHit() { | 159 function testFindControllerEmptyHit() { |
| 154 var timeline = new FakeTimeline(); | 160 var timeline = new FakeTimeline(); |
| 155 var controller = new tracing.TimelineFindController(); | 161 var controller = new tracing.TimelineFindController(); |
| 156 controller.timeline = timeline; | 162 controller.timeline = timeline; |
| 157 | 163 |
| 158 timeline.selection = []; | 164 timeline.selection = new tracing.TimelineSelection(); |
| 159 controller.findNext(); | 165 controller.findNext(); |
| 160 assertArrayEquals([], timeline.selection); | 166 assertArrayishEquals([], timeline.selection); |
| 161 controller.findPrevious(); | 167 controller.findPrevious(); |
| 162 assertArrayEquals([], timeline.selection); | 168 assertArrayishEquals([], timeline.selection); |
| 163 } | 169 } |
| 164 | 170 |
| 165 function testFindControllerOneHit() { | 171 function testFindControllerOneHit() { |
| 166 var timeline = new FakeTimeline(); | 172 var timeline = new FakeTimeline(); |
| 167 var controller = new tracing.TimelineFindController(); | 173 var controller = new tracing.TimelineFindController(); |
| 168 controller.timeline = timeline; | 174 controller.timeline = timeline; |
| 169 | 175 |
| 170 timeline.findAllObjectsMatchingFilterReturnValue = [1]; | 176 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1]; |
| 171 controller.findNext(); | 177 controller.findNext(); |
| 172 assertArrayEquals([1], timeline.selection); | 178 assertArrayishEquals([1], timeline.selection); |
| 173 controller.findNext(); | 179 controller.findNext(); |
| 174 assertArrayEquals([1], timeline.selection); | 180 assertArrayishEquals([1], timeline.selection); |
| 175 controller.findPrevious(); | 181 controller.findPrevious(); |
| 176 assertArrayEquals([1], timeline.selection); | 182 assertArrayishEquals([1], timeline.selection); |
| 177 } | 183 } |
| 178 | 184 |
| 179 function testFindControllerMultipleHits() { | 185 function testFindControllerMultipleHits() { |
| 180 var timeline = new FakeTimeline(); | 186 var timeline = new FakeTimeline(); |
| 181 var controller = new tracing.TimelineFindController(); | 187 var controller = new tracing.TimelineFindController(); |
| 182 controller.timeline = timeline; | 188 controller.timeline = timeline; |
| 183 | 189 |
| 184 timeline.findAllObjectsMatchingFilterReturnValue = [1,2,3]; | 190 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; |
| 185 | 191 |
| 186 // Loop through hits then when we wrap, try moving backward. | 192 // Loop through hits then when we wrap, try moving backward. |
| 187 controller.findNext(); | 193 controller.findNext(); |
| 188 assertArrayEquals([1], timeline.selection); | 194 assertArrayishEquals([1], timeline.selection); |
| 189 controller.findNext(); | 195 controller.findNext(); |
| 190 assertArrayEquals([2], timeline.selection); | 196 assertArrayishEquals([2], timeline.selection); |
| 191 controller.findNext(); | 197 controller.findNext(); |
| 192 assertArrayEquals([3], timeline.selection); | 198 assertArrayishEquals([3], timeline.selection); |
| 193 controller.findNext(); | 199 controller.findNext(); |
| 194 assertArrayEquals([1], timeline.selection); | 200 assertArrayishEquals([1], timeline.selection); |
| 195 controller.findPrevious(); | 201 controller.findPrevious(); |
| 196 assertArrayEquals([3], timeline.selection); | 202 assertArrayishEquals([3], timeline.selection); |
| 197 controller.findPrevious(); | 203 controller.findPrevious(); |
| 198 assertArrayEquals([2], timeline.selection); | 204 assertArrayishEquals([2], timeline.selection); |
| 199 } | 205 } |
| 200 | 206 |
| 201 function testFindControllerChangeFilterAfterNext() { | 207 function testFindControllerChangeFilterAfterNext() { |
| 202 var timeline = new FakeTimeline(); | 208 var timeline = new FakeTimeline(); |
| 203 var controller = new tracing.TimelineFindController(); | 209 var controller = new tracing.TimelineFindController(); |
| 204 controller.timeline = timeline; | 210 controller.timeline = timeline; |
| 205 | 211 |
| 206 timeline.findAllObjectsMatchingFilterReturnValue = [1,2,3]; | 212 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; |
| 207 | 213 |
| 208 // Loop through hits then when we wrap, try moving backward. | 214 // Loop through hits then when we wrap, try moving backward. |
| 209 controller.findNext(); | 215 controller.findNext(); |
| 210 timeline.findAllObjectsMatchingFilterReturnValue = [4]; | 216 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [4]; |
| 211 controller.filterText = "asdfsf"; | 217 controller.filterText = "asdfsf"; |
| 212 controller.findNext(); | 218 controller.findNext(); |
| 213 assertArrayEquals([4], timeline.selection); | 219 assertArrayishEquals([4], timeline.selection); |
| 214 } | 220 } |
| 215 | 221 |
| 216 function testFindControllerSelectsFirstItemImmediately() { | 222 function testFindControllerSelectsFirstItemImmediately() { |
| 217 var timeline = new FakeTimeline(); | 223 var timeline = new FakeTimeline(); |
| 218 var controller = new tracing.TimelineFindController(); | 224 var controller = new tracing.TimelineFindController(); |
| 219 controller.timeline = timeline; | 225 controller.timeline = timeline; |
| 220 timeline.findAllObjectsMatchingFilterReturnValue = [1,2,3]; | 226 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; |
| 221 controller.filterText = "asdfsf"; | 227 controller.filterText = "asdfsf"; |
| 222 assertArrayEquals([1], timeline.selection); | 228 assertArrayishEquals([1], timeline.selection); |
| 223 controller.findNext(); | 229 controller.findNext(); |
| 224 assertArrayEquals([2], timeline.selection); | 230 assertArrayishEquals([2], timeline.selection); |
| 225 } | 231 } |
| 226 | 232 |
| 227 function testFindControllerWithRealTimeline() { | 233 function testFindControllerWithRealTimeline() { |
| 228 var model = new tracing.TimelineModel(); | 234 var model = new tracing.TimelineModel(); |
| 229 var p1 = model.getOrCreateProcess(1); | 235 var p1 = model.getOrCreateProcess(1); |
| 230 var t1 = p1.getOrCreateThread(1); | 236 var t1 = p1.getOrCreateThread(1); |
| 231 t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3)); | 237 t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3)); |
| 232 | 238 |
| 233 var timeline = new tracing.Timeline(); | 239 var timeline = new tracing.Timeline(); |
| 234 timeline.model = model; | 240 timeline.model = model; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 248 controller.filterText = 'xxx'; | 254 controller.filterText = 'xxx'; |
| 249 controller.findNext(); | 255 controller.findNext(); |
| 250 assertEquals(0, timeline.selection.length); | 256 assertEquals(0, timeline.selection.length); |
| 251 controller.findNext(); | 257 controller.findNext(); |
| 252 assertEquals(0, timeline.selection.length); | 258 assertEquals(0, timeline.selection.length); |
| 253 } | 259 } |
| 254 | 260 |
| 255 </script> | 261 </script> |
| 256 </body> | 262 </body> |
| 257 </html> | 263 </html> |
| OLD | NEW |