| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE HTML> | |
| 2 <html> | |
| 3 <!-- | |
| 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 | |
| 6 found in the LICENSE file. | |
| 7 --> | |
| 8 <head i18n-values="dir:textdirection;"> | |
| 9 <title>TimelineView tests</title> | |
| 10 <link rel="stylesheet" href="overlay.css"> | |
| 11 <link rel="stylesheet" href="timeline.css"> | |
| 12 <link rel="stylesheet" href="timeline_analysis.css"> | |
| 13 <link rel="stylesheet" href="timeline_view.css"> | |
| 14 <link rel="stylesheet" href="../shared/css/tabs.css"> | |
| 15 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j
s"></script> | |
| 16 <script src="../shared/js/cr.js"></script> | |
| 17 <script src="../shared/js/cr/event_target.js"></script> | |
| 18 <script src="../shared/js/cr/ui.js"></script> | |
| 19 <script src="../shared/js/cr/ui/tabs.js"></script> | |
| 20 <script src="overlay.js"></script> | |
| 21 <script src="measuring_stick.js"></script> | |
| 22 <script src="profiling_view.js"></script> | |
| 23 <script src="timeline_analysis.js"></script> | |
| 24 <script src="timeline_view.js"></script> | |
| 25 <script src="timeline_model.js"></script> | |
| 26 <script src="linux_perf_importer.js"></script> | |
| 27 <script src="trace_event_importer.js"></script> | |
| 28 <script src="timeline.js"></script> | |
| 29 <script src="timeline_track.js"></script> | |
| 30 <script src="sorted_array_utils.js"></script> | |
| 31 <script src="fast_rect_renderer.js"></script> | |
| 32 <script src="test_utils.js"></script> | |
| 33 <script> | |
| 34 goog.require('goog.testing.jsunit'); | |
| 35 </script> | |
| 36 <style> | |
| 37 .timeline-view { | |
| 38 border: 1px solid black; | |
| 39 margin: 10px; | |
| 40 } | |
| 41 .timeline-find-dialog { | |
| 42 border: 1px solid black; | |
| 43 margin: 10px; | |
| 44 } | |
| 45 </style> | |
| 46 </head> | |
| 47 <body> | |
| 48 <script> | |
| 49 'use strict'; | |
| 50 | |
| 51 var assertArrayishEquals = test_utils.assertArrayishEquals; | |
| 52 | |
| 53 /* | |
| 54 * Just enough of the Timeline to support the tests below. | |
| 55 */ | |
| 56 var FakeTimeline = cr.ui.define('div'); | |
| 57 | |
| 58 FakeTimeline.prototype = { | |
| 59 __proto__: HTMLDivElement.prototype, | |
| 60 | |
| 61 decorate: function() { | |
| 62 this.addAllObjectsMatchingFilterToSelectionReturnValue = []; | |
| 63 | |
| 64 this.selection = new tracing.TimelineSelection(); | |
| 65 this.keyHelp = "<keyHelp>"; | |
| 66 | |
| 67 // Put some simple UI in for testing purposes. | |
| 68 var noteEl = document.createElement('div'); | |
| 69 noteEl.textContent = "FakeTimeline:"; | |
| 70 this.appendChild(noteEl); | |
| 71 | |
| 72 this.statusEl_ = document.createElement('div'); | |
| 73 this.appendChild(this.statusEl_); | |
| 74 this.refresh_(); | |
| 75 }, | |
| 76 | |
| 77 refresh_: function() { | |
| 78 var status; | |
| 79 if (this.model) | |
| 80 status = "model=set"; | |
| 81 else | |
| 82 status = "model=undefined"; | |
| 83 this.statusEl_.textContent = status; | |
| 84 }, | |
| 85 | |
| 86 setSelectionAndMakeVisible: function(selection, zoomAllowed) { | |
| 87 this.selection = selection; | |
| 88 }, | |
| 89 | |
| 90 addAllObjectsMatchingFilterToSelection: function(filter, selection) { | |
| 91 var n = this.addAllObjectsMatchingFilterToSelectionReturnValue.length; | |
| 92 for (var i = 0; i < n; i++) | |
| 93 selection.push_( | |
| 94 this.addAllObjectsMatchingFilterToSelectionReturnValue[i]); | |
| 95 } | |
| 96 }; | |
| 97 | |
| 98 /* | |
| 99 * This test just instantiates a TimelineView and adds it to the DOM | |
| 100 * to help with non-unittest UI work. | |
| 101 */ | |
| 102 function testInstantiateTimelineView() { | |
| 103 var events = [ | |
| 104 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, | |
| 105 {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'}, | |
| 106 {name: 'b', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'}, | |
| 107 {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}, | |
| 108 {name: 'a', args: {}, pid: 52, ts: 640, cat: 'foo', tid: 53, ph: 'B'}, | |
| 109 {name: 'a', args: {}, pid: 52, ts: 700, cat: 'foo', tid: 53, ph: 'E'}, | |
| 110 {name: 'a', args: {}, pid: 52, ts: 710, cat: 'foo', tid: 53, ph: 'B'}, | |
| 111 {name: 'a', args: {}, pid: 52, ts: 740, cat: 'foo', tid: 53, ph: 'E'} | |
| 112 ]; | |
| 113 var model = new tracing.TimelineModel(); | |
| 114 model.importEvents(events); | |
| 115 var view = new tracing.TimelineView(); | |
| 116 view.model = model; | |
| 117 view.tabIndex = 0; | |
| 118 view.focusElement = view; | |
| 119 | |
| 120 document.body.appendChild(view); | |
| 121 } | |
| 122 | |
| 123 /* | |
| 124 * This test just instantiates a FindDialog and adds it to the DOM | |
| 125 * to help with non-unittest UI work. | |
| 126 */ | |
| 127 function testInstantiateTimelineFindControl() { | |
| 128 var ctl = new tracing.TimelineFindControl(); | |
| 129 var didFindPrevious = false; | |
| 130 var didFindNext = false; | |
| 131 ctl.controller = { | |
| 132 findNext: function() { | |
| 133 didFindNext = true; | |
| 134 }, | |
| 135 | |
| 136 findPrevious: function() { | |
| 137 didFindPrevious = true; | |
| 138 }, | |
| 139 | |
| 140 filterHits: [], | |
| 141 | |
| 142 currentHitIndex: 0, | |
| 143 } | |
| 144 document.body.appendChild(ctl); | |
| 145 ctl.querySelector('input').focus(); | |
| 146 ctl.querySelector('input').blur(); | |
| 147 | |
| 148 ctl.querySelector('.find-previous').click(); | |
| 149 assertTrue(didFindPrevious); | |
| 150 ctl.querySelector('.find-next').click(); | |
| 151 assertTrue(didFindNext); | |
| 152 } | |
| 153 | |
| 154 function testFindControllerNoTimeline() { | |
| 155 var controller = new tracing.TimelineFindController(); | |
| 156 controller.findNext(); | |
| 157 controller.findPrevious(); | |
| 158 } | |
| 159 | |
| 160 function testFindControllerEmptyHit() { | |
| 161 var timeline = new FakeTimeline(); | |
| 162 var controller = new tracing.TimelineFindController(); | |
| 163 controller.timeline = timeline; | |
| 164 | |
| 165 timeline.selection = new tracing.TimelineSelection(); | |
| 166 controller.findNext(); | |
| 167 assertArrayishEquals([], timeline.selection); | |
| 168 controller.findPrevious(); | |
| 169 assertArrayishEquals([], timeline.selection); | |
| 170 } | |
| 171 | |
| 172 function testFindControllerOneHit() { | |
| 173 var timeline = new FakeTimeline(); | |
| 174 var controller = new tracing.TimelineFindController(); | |
| 175 controller.timeline = timeline; | |
| 176 | |
| 177 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1]; | |
| 178 controller.findNext(); | |
| 179 assertArrayishEquals([1], timeline.selection); | |
| 180 controller.findNext(); | |
| 181 assertArrayishEquals([1], timeline.selection); | |
| 182 controller.findPrevious(); | |
| 183 assertArrayishEquals([1], timeline.selection); | |
| 184 } | |
| 185 | |
| 186 function testFindControllerMultipleHits() { | |
| 187 var timeline = new FakeTimeline(); | |
| 188 var controller = new tracing.TimelineFindController(); | |
| 189 controller.timeline = timeline; | |
| 190 | |
| 191 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; | |
| 192 | |
| 193 // Loop through hits then when we wrap, try moving backward. | |
| 194 controller.findNext(); | |
| 195 assertArrayishEquals([1], timeline.selection); | |
| 196 controller.findNext(); | |
| 197 assertArrayishEquals([2], timeline.selection); | |
| 198 controller.findNext(); | |
| 199 assertArrayishEquals([3], timeline.selection); | |
| 200 controller.findNext(); | |
| 201 assertArrayishEquals([1], timeline.selection); | |
| 202 controller.findPrevious(); | |
| 203 assertArrayishEquals([3], timeline.selection); | |
| 204 controller.findPrevious(); | |
| 205 assertArrayishEquals([2], timeline.selection); | |
| 206 } | |
| 207 | |
| 208 function testFindControllerChangeFilterAfterNext() { | |
| 209 var timeline = new FakeTimeline(); | |
| 210 var controller = new tracing.TimelineFindController(); | |
| 211 controller.timeline = timeline; | |
| 212 | |
| 213 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; | |
| 214 | |
| 215 // Loop through hits then when we wrap, try moving backward. | |
| 216 controller.findNext(); | |
| 217 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [4]; | |
| 218 controller.filterText = "asdfsf"; | |
| 219 controller.findNext(); | |
| 220 assertArrayishEquals([4], timeline.selection); | |
| 221 } | |
| 222 | |
| 223 function testFindControllerSelectsFirstItemImmediately() { | |
| 224 var timeline = new FakeTimeline(); | |
| 225 var controller = new tracing.TimelineFindController(); | |
| 226 controller.timeline = timeline; | |
| 227 timeline.addAllObjectsMatchingFilterToSelectionReturnValue = [1,2,3]; | |
| 228 controller.filterText = "asdfsf"; | |
| 229 assertArrayishEquals([1], timeline.selection); | |
| 230 controller.findNext(); | |
| 231 assertArrayishEquals([2], timeline.selection); | |
| 232 } | |
| 233 | |
| 234 function testFindControllerWithRealTimeline() { | |
| 235 var model = new tracing.TimelineModel(); | |
| 236 var p1 = model.getOrCreateProcess(1); | |
| 237 var t1 = p1.getOrCreateThread(1); | |
| 238 t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3)); | |
| 239 | |
| 240 var timeline = new tracing.Timeline(); | |
| 241 timeline.model = model; | |
| 242 | |
| 243 var controller = new tracing.TimelineFindController(); | |
| 244 controller.timeline = timeline; | |
| 245 | |
| 246 // Test find with no filterText. | |
| 247 controller.findNext(); | |
| 248 | |
| 249 // Test find with filter txt. | |
| 250 controller.filterText = 'a'; | |
| 251 controller.findNext(); | |
| 252 assertEquals(1, timeline.selection.length); | |
| 253 assertEquals(t1.subRows[0][0], timeline.selection[0].slice); | |
| 254 | |
| 255 controller.filterText = 'xxx'; | |
| 256 controller.findNext(); | |
| 257 assertEquals(0, timeline.selection.length); | |
| 258 controller.findNext(); | |
| 259 assertEquals(0, timeline.selection.length); | |
| 260 } | |
| 261 | |
| 262 </script> | |
| 263 </body> | |
| 264 </html> | |
| OLD | NEW |