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