1<!DOCTYPE html> 2<!-- 3Copyright (c) 2013 The Chromium Authors. All rights reserved. 4Use of this source code is governed by a BSD-style license that can be 5found in the LICENSE file. 6--> 7 8<link rel="import" href="/tracing/base/task.html"> 9<link rel="import" href="/tracing/core/test_utils.html"> 10<link rel="import" href="/tracing/extras/importer/trace_event_importer.html"> 11<link rel="import" href="/tracing/model/event_set.html"> 12<link rel="import" href="/tracing/ui/timeline_track_view.html"> 13 14<script> 15'use strict'; 16 17tr.b.unittest.testSuite(function() { 18 var EventSet = tr.model.EventSet; 19 var SelectionState = tr.model.SelectionState; 20 var Task = tr.b.Task; 21 22 test('instantiate', function() { 23 var num_threads = 500; 24 var model = tr.c.TestUtils.newModelWithEvents([], { 25 shiftWorldToZero: false, 26 pruneContainers: false, 27 customizeModelCallback: function(model) { 28 var p100 = model.getOrCreateProcess(100); 29 for (var i = 0; i < num_threads; i++) { 30 var t = p100.getOrCreateThread(101 + i); 31 if (i % 2 == 0) { 32 t.sliceGroup.beginSlice('cat', 'a', 100); 33 t.sliceGroup.endSlice(110); 34 } else { 35 t.sliceGroup.beginSlice('cat', 'b', 50); 36 t.sliceGroup.endSlice(120); 37 } 38 } 39 } 40 }); 41 42 var timeline = document.createElement('tr-ui-timeline-track-view'); 43 timeline.model = model; 44 timeline.style.maxHeight = '600px'; 45 this.addHTMLOutput(timeline); 46 }); 47 48 test('addAllEventsMatchingFilterToSelectionAsTask', function() { 49 var model = new tr.Model(); 50 var p1 = model.getOrCreateProcess(1); 51 var t1 = p1.getOrCreateThread(1); 52 53 t1.sliceGroup.pushSlice( 54 new tr.model.ThreadSlice('', 'a', 0, 1, {}, 3)); 55 t1.sliceGroup.pushSlice( 56 new tr.model.ThreadSlice('', 'b', 0, 1.1, {}, 2.8)); 57 58 var t1asg = t1.asyncSliceGroup; 59 t1asg.slices.push( 60 tr.c.TestUtils.newAsyncSliceNamed('a', 0, 1, t1, t1)); 61 t1asg.slices.push( 62 tr.c.TestUtils.newAsyncSliceNamed('b', 1, 2, t1, t1)); 63 64 var timeline = document.createElement('tr-ui-timeline-track-view'); 65 timeline.model = model; 66 67 var expected = [t1asg.slices[0], 68 t1.sliceGroup.slices[0]]; 69 var result = new tr.model.EventSet; 70 var filterTask = timeline.addAllEventsMatchingFilterToSelectionAsTask( 71 new tr.c.TitleOrCategoryFilter('a'), result); 72 Task.RunSynchronously(filterTask); 73 assert.equal(result.length, 2); 74 assert.equal(result[0], expected[0]); 75 assert.equal(result[1], expected[1]); 76 77 var expected = [t1asg.slices[1], 78 t1.sliceGroup.slices[1]]; 79 var result = new tr.model.EventSet(); 80 var filterTask = timeline.addAllEventsMatchingFilterToSelectionAsTask( 81 new tr.c.TitleOrCategoryFilter('b'), result); 82 Task.RunSynchronously(filterTask); 83 assert.equal(result.length, 2); 84 assert.equal(result[0], expected[0]); 85 assert.equal(result[1], expected[1]); 86 }); 87 88 test('emptyThreadsDeleted', function() { 89 var model = new tr.Model(); 90 var p1 = model.getOrCreateProcess(1); 91 var t1 = p1.getOrCreateThread(1); 92 93 var timeline = document.createElement('tr-ui-timeline-track-view'); 94 timeline.model = model; 95 96 assert.isFalse(timeline.hasVisibleContent); 97 }); 98 99 test('filteredCounters', function() { 100 var model = new tr.Model(); 101 var c1 = model.kernel.getOrCreateCpu(0); 102 c1.getOrCreateCounter('', 'b'); 103 104 var p1 = model.getOrCreateProcess(1); 105 var ctr = p1.getOrCreateCounter('', 'a'); 106 var series = new tr.model.CounterSeries('a', 0); 107 series.addCounterSample(0, 1); 108 ctr.addSeries(series); 109 110 var timeline = document.createElement('tr-ui-timeline-track-view'); 111 timeline.model = model; 112 113 assert.isTrue(timeline.hasVisibleContent); 114 }); 115 116 test('filteredCpus', function() { 117 var model = new tr.Model(); 118 var c1 = model.kernel.getOrCreateCpu(1); 119 c1.getOrCreateCounter('', 'a'); 120 121 var timeline = document.createElement('tr-ui-timeline-track-view'); 122 timeline.model = model; 123 124 assert.isTrue(timeline.hasVisibleContent); 125 }); 126 127 test('filteredProcesses', function() { 128 var model = new tr.Model(); 129 var p1 = model.getOrCreateProcess(1); 130 p1.getOrCreateCounter('', 'a'); 131 132 var timeline = document.createElement('tr-ui-timeline-track-view'); 133 timeline.model = model; 134 135 assert.isTrue(timeline.hasVisibleContent); 136 }); 137 138 test('filteredThreads', function() { 139 var model = new tr.Model(); 140 var p1 = model.getOrCreateProcess(1); 141 var t1 = p1.getOrCreateThread(2); 142 t1.sliceGroup.pushSlice(tr.c.TestUtils.newSliceEx({start: 0, duration: 1})); 143 144 var timeline = document.createElement('tr-ui-timeline-track-view'); 145 timeline.model = model; 146 147 assert.isTrue(timeline.hasVisibleContent); 148 }); 149 150 test('interestRange', function() { 151 var events = [ 152 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, 153 {name: 'b', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, 154 {name: 'c', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, 155 {name: 'c', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'E'}, 156 {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}, 157 {name: 'a', args: {}, pid: 52, ts: 634, cat: 'foo', tid: 53, ph: 'E'} 158 ]; 159 var model = tr.c.TestUtils.newModelWithEvents([events]); 160 var trackView = document.createElement('tr-ui-timeline-track-view'); 161 trackView.model = model; 162 this.addHTMLOutput(trackView); 163 164 var slice = model.processes[52].threads[53].sliceGroup.slices[2]; 165 trackView.viewport.interestRange.setMinAndMax(slice.start, slice.end); 166 }); 167 168 test('emptyInterestRange', function() { 169 var events = [ 170 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, 171 {name: 'b', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, 172 {name: 'c', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, 173 {name: 'c', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'E'}, 174 {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}, 175 {name: 'a', args: {}, pid: 52, ts: 634, cat: 'foo', tid: 53, ph: 'E'} 176 ]; 177 var model = tr.c.TestUtils.newModelWithEvents([events]); 178 var trackView = document.createElement('tr-ui-timeline-track-view'); 179 trackView.model = model; 180 this.addHTMLOutput(trackView); 181 trackView.viewport.interestRange.reset(); 182 }); 183 184 185 test('thinnestInterestRange', function() { 186 var events = [ 187 {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'}, 188 {name: 'b', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, 189 {name: 'c', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'B'}, 190 {name: 'c', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'E'}, 191 {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}, 192 {name: 'a', args: {}, pid: 52, ts: 634, cat: 'foo', tid: 53, ph: 'E'} 193 ]; 194 var model = tr.c.TestUtils.newModelWithEvents([events]); 195 var trackView = document.createElement('tr-ui-timeline-track-view'); 196 trackView.model = model; 197 this.addHTMLOutput(trackView); 198 trackView.viewport.interestRange.reset(); 199 200 var slice = model.processes[52].threads[53].sliceGroup.slices[2]; 201 trackView.viewport.interestRange.setMinAndMax(slice.start, slice.start); 202 }); 203}); 204</script> 205