1// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5'use strict'; 6 7base.require('tracing.test_utils'); 8base.require('tracing.timeline_track_view'); 9base.require('tracing.trace_model.slice_group'); 10 11base.unittest.testSuite('tracing.tracks.slice_group_track', function() { 12 var SliceGroup = tracing.trace_model.SliceGroup; 13 var SliceGroupTrack = tracing.tracks.SliceGroupTrack; 14 var newSliceNamed = tracing.test_utils.newSliceNamed; 15 16 test('subRowBuilderBasic', function() { 17 var group = new SliceGroup(); 18 var sA = group.pushSlice(newSliceNamed('a', 1, 2)); 19 var sB = group.pushSlice(newSliceNamed('a', 3, 1)); 20 21 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 22 track.group = group; 23 var subRows = track.subRows; 24 25 assertEquals(0, track.badSlices_.length); 26 assertEquals(1, subRows.length); 27 assertEquals(2, subRows[0].length); 28 assertArrayEquals([sA, sB], subRows[0]); 29 }); 30 31 test('subRowBuilderBasic2', function() { 32 var group = new SliceGroup(); 33 var sA = group.pushSlice(newSliceNamed('a', 1, 4)); 34 var sB = group.pushSlice(newSliceNamed('b', 3, 1)); 35 36 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 37 track.group = group; 38 var subRows = track.subRows; 39 40 assertEquals(0, track.badSlices_.length); 41 assertEquals(2, subRows.length); 42 assertEquals(1, subRows[0].length); 43 assertEquals(1, subRows[1].length); 44 assertArrayEquals([sA], subRows[0]); 45 assertArrayEquals([sB], subRows[1]); 46 }); 47 48 test('subRowBuilderNestedExactly', function() { 49 var group = new SliceGroup(); 50 var sA = group.pushSlice(newSliceNamed('a', 1, 4)); 51 var sB = group.pushSlice(newSliceNamed('b', 1, 4)); 52 53 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 54 track.group = group; 55 var subRows = track.subRows; 56 57 assertEquals(0, track.badSlices_.length); 58 assertEquals(2, subRows.length); 59 assertEquals(1, subRows[0].length); 60 assertEquals(1, subRows[1].length); 61 assertArrayEquals([sB], subRows[0]); 62 assertArrayEquals([sA], subRows[1]); 63 }); 64 65 test('subRowBuilderInstantEvents', function() { 66 var group = new SliceGroup(); 67 var sA = group.pushSlice(newSliceNamed('a', 1, 0)); 68 var sB = group.pushSlice(newSliceNamed('b', 2, 0)); 69 70 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 71 track.group = group; 72 var subRows = track.subRows; 73 74 assertEquals(0, track.badSlices_.length); 75 assertEquals(1, subRows.length); 76 assertEquals(2, subRows[0].length); 77 assertArrayEquals([sA, sB], subRows[0]); 78 }); 79 80 test('subRowBuilderTwoInstantEvents', function() { 81 var group = new SliceGroup(); 82 var sB = group.pushSlice(newSliceNamed('b', 1, 0)); 83 var sA = group.pushSlice(newSliceNamed('a', 1, 0)); 84 85 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 86 track.group = group; 87 var subRows = track.subRows; 88 89 assertEquals(0, track.badSlices_.length); 90 assertEquals(2, subRows.length); 91 assertArrayEquals([sA], subRows[0]); 92 assertArrayEquals([sB], subRows[1]); 93 }); 94 95 test('subRowBuilderOutOfOrderAddition', function() { 96 var group = new SliceGroup(); 97 98 // Pattern being tested: 99 // [ a ][ b ] 100 // Where insertion is done backward. 101 var sB = group.pushSlice(newSliceNamed('b', 3, 1)); 102 var sA = group.pushSlice(newSliceNamed('a', 1, 2)); 103 104 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 105 track.group = group; 106 var subRows = track.subRows; 107 108 assertEquals(0, track.badSlices_.length); 109 assertEquals(1, subRows.length); 110 assertEquals(2, subRows[0].length); 111 assertArrayEquals([sA, sB], subRows[0]); 112 }); 113 114 test('subRowBuilderOutOfOrderAddition2', function() { 115 var group = new SliceGroup(); 116 117 // Pattern being tested: 118 // [ a ] 119 // [ b ] 120 // Where insertion is done backward. 121 var sB = group.pushSlice(newSliceNamed('b', 3, 1)); 122 var sA = group.pushSlice(newSliceNamed('a', 1, 5)); 123 124 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 125 track.group = group; 126 var subRows = track.subRows; 127 128 assertEquals(0, track.badSlices_.length); 129 assertEquals(2, subRows.length); 130 assertEquals(1, subRows[0].length); 131 assertEquals(1, subRows[1].length); 132 assertArrayEquals([sA], subRows[0]); 133 assertArrayEquals([sB], subRows[1]); 134 }); 135 136 test('subRowBuilderOnNestedZeroLength', function() { 137 var group = new SliceGroup(); 138 139 // Pattern being tested: 140 // [ a ] 141 // [ b1 ] []<- b2 where b2.duration = 0 and b2.end == a.end. 142 var sB1 = group.pushSlice(newSliceNamed('b1', 1, 2)); 143 var sB2 = group.pushSlice(newSliceNamed('b2', 4, 0)); 144 var sA = group.pushSlice(newSliceNamed('a', 1, 3)); 145 146 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 147 track.group = group; 148 var subRows = track.subRows; 149 150 assertEquals(0, track.badSlices_.length); 151 assertEquals(2, subRows.length); 152 assertArrayEquals([sA], subRows[0]); 153 assertArrayEquals([sB1, sB2], subRows[1]); 154 }); 155 156 test('subRowBuilderOnGroup1', function() { 157 var group = new SliceGroup(); 158 159 // Pattern being tested: 160 // [ a ] [ c ] 161 // [ b ] 162 var sA = group.pushSlice(newSliceNamed('a', 1, 3)); 163 var sB = group.pushSlice(newSliceNamed('b', 1.5, 1)); 164 var sC = group.pushSlice(newSliceNamed('c', 5, 0)); 165 166 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 167 track.group = group; 168 var subRows = track.subRows; 169 170 assertEquals(0, track.badSlices_.length); 171 assertEquals(2, subRows.length); 172 assertArrayEquals([sA, sC], subRows[0]); 173 assertArrayEquals([sB], subRows[1]); 174 }); 175 176 test('subRowBuilderOnGroup2', function() { 177 var group = new SliceGroup(); 178 179 // Pattern being tested: 180 // [ a ] [ d ] 181 // [ b ] 182 // [ c ] 183 var sA = group.pushSlice(newSliceNamed('a', 1, 3)); 184 var sB = group.pushSlice(newSliceNamed('b', 1.5, 1)); 185 var sC = group.pushSlice(newSliceNamed('c', 1.75, 0.5)); 186 var sD = group.pushSlice(newSliceNamed('c', 5, 0.25)); 187 188 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 189 track.group = group; 190 191 var subRows = track.subRows; 192 assertEquals(0, track.badSlices_.length); 193 assertEquals(3, subRows.length); 194 assertArrayEquals([sA, sD], subRows[0]); 195 assertArrayEquals([sB], subRows[1]); 196 assertArrayEquals([sC], subRows[2]); 197 }); 198 199 test('trackFiltering', function() { 200 var group = new SliceGroup(); 201 202 var sA = group.pushSlice(newSliceNamed('a', 1, 3)); 203 var sB = group.pushSlice(newSliceNamed('b', 1.5, 1)); 204 205 var track = new SliceGroupTrack(new tracing.TimelineViewport()); 206 track.group = group; 207 208 assertEquals(2, track.subRows.length); 209 assertTrue(track.hasVisibleContent); 210 211 track.categoryFilter = new tracing.TitleFilter('x'); 212 assertFalse(track.hasVisibleContent); 213 214 track.categoryFilter = new tracing.TitleFilter('a'); 215 assertTrue(track.hasVisibleContent); 216 assertEquals(1, track.subRows.length); 217 218 track.categoryFilter = new tracing.TitleFilter('b'); 219 assertTrue(track.hasVisibleContent); 220 assertEquals(1, track.subRows.length); 221 }); 222}); 223