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 7 base.require('tracing.test_utils'); 8 base.require('tracing.timeline_track_view'); 9 base.require('tracing.trace_model'); 10 11 base.unittest.testSuite('tracing.tracks.async_slice_group_track', function() { 12 var AsyncSliceGroup = tracing.trace_model.AsyncSliceGroup; 13 var AsyncSliceGroupTrack = tracing.tracks.AsyncSliceGroupTrack; 14 var Process = tracing.trace_model.Process; 15 var Thread = tracing.trace_model.Thread; 16 var newAsyncSlice = tracing.test_utils.newAsyncSlice; 17 18 test('filterSubRows', function() { 19 var model = new tracing.TraceModel(); 20 var p1 = new Process(model, 1); 21 var t1 = new Thread(p1, 1); 22 var g = new AsyncSliceGroup(); 23 g.push(newAsyncSlice(0, 1, t1, t1)); 24 var track = new AsyncSliceGroupTrack(new tracing.TimelineViewport()); 25 track.group = g; 26 27 assertEquals(1, track.children.length); 28 assertTrue(track.hasVisibleContent); 29 30 track.categoryFilter = new tracing.TitleFilter('x'); 31 assertFalse(track.hasVisibleContent); 32 33 track.categoryFilter = new tracing.TitleFilter('a'); 34 assertTrue(track.hasVisibleContent); 35 assertEquals(1, track.children.length); 36 }); 37 38 test('rebuildSubRows_twoNonOverlappingSlices', function() { 39 var model = new tracing.TraceModel(); 40 var p1 = new Process(model, 1); 41 var t1 = new Thread(p1, 1); 42 var g = new AsyncSliceGroup(); 43 g.push(newAsyncSlice(0, 1, t1, t1)); 44 g.push(newAsyncSlice(1, 1, t1, t1)); 45 var track = new AsyncSliceGroupTrack(new tracing.TimelineViewport()); 46 track.group = g; 47 var subRows = track.subRows; 48 assertEquals(1, subRows.length); 49 assertEquals(2, subRows[0].length); 50 assertEquals(g.slices[0].subSlices[0], subRows[0][0]); 51 assertEquals(g.slices[1].subSlices[0], subRows[0][1]); 52 }); 53 54 test('rebuildSubRows_twoOverlappingSlices', function() { 55 var model = new tracing.TraceModel(); 56 var p1 = new Process(model, 1); 57 var t1 = new Thread(p1, 1); 58 var g = new AsyncSliceGroup(); 59 60 g.push(newAsyncSlice(0, 1, t1, t1)); 61 g.push(newAsyncSlice(0, 1.5, t1, t1)); 62 g.updateBounds(); 63 64 var track = new AsyncSliceGroupTrack(new tracing.TimelineViewport()); 65 track.group = g; 66 67 var subRows = track.subRows; 68 69 assertEquals(2, subRows.length); 70 assertEquals(1, subRows[0].length); 71 assertEquals(g.slices[0].subSlices[0], subRows[0][0]); 72 73 assertEquals(1, subRows[1].length); 74 assertEquals(g.slices[1].subSlices[0], subRows[1][0]); 75 }); 76 77 test('rebuildSubRows_threePartlyOverlappingSlices', function() { 78 var model = new tracing.TraceModel(); 79 var p1 = new Process(model, 1); 80 var t1 = new Thread(p1, 1); 81 var g = new AsyncSliceGroup(); 82 g.push(newAsyncSlice(0, 1, t1, t1)); 83 g.push(newAsyncSlice(0, 1.5, t1, t1)); 84 g.push(newAsyncSlice(1, 1.5, t1, t1)); 85 g.updateBounds(); 86 var track = new AsyncSliceGroupTrack(new tracing.TimelineViewport()); 87 track.group = g; 88 var subRows = track.subRows; 89 90 assertEquals(2, subRows.length); 91 assertEquals(2, subRows[0].length); 92 assertEquals(g.slices[0].subSlices[0], subRows[0][0]); 93 assertEquals(g.slices[2].subSlices[0], subRows[0][1]); 94 95 assertEquals(1, subRows[1].length); 96 assertEquals(g.slices[1].subSlices[0], subRows[1][0]); 97 }); 98 99 test('rebuildSubRows_threeOverlappingSlices', function() { 100 var model = new tracing.TraceModel(); 101 var p1 = new Process(model, 1); 102 var t1 = new Thread(p1, 1); 103 var g = new AsyncSliceGroup(); 104 105 g.push(newAsyncSlice(0, 1, t1, t1)); 106 g.push(newAsyncSlice(0, 1.5, t1, t1)); 107 g.push(newAsyncSlice(2, 1, t1, t1)); 108 g.updateBounds(); 109 110 var track = new AsyncSliceGroupTrack(new tracing.TimelineViewport()); 111 track.group = g; 112 113 var subRows = track.subRows; 114 assertEquals(2, subRows.length); 115 assertEquals(2, subRows[0].length); 116 assertEquals(g.slices[0].subSlices[0], subRows[0][0]); 117 assertEquals(g.slices[2].subSlices[0], subRows[0][1]); 118 assertEquals(1, subRows[1].length); 119 assertEquals(g.slices[1].subSlices[0], subRows[1][0]); 120 }); 121 122 test('computeSubGroups_twoThreadSpecificSlices', function() { 123 var model = new tracing.TraceModel(); 124 var p1 = new Process(model, 1); 125 var t1 = new Thread(p1, 1); 126 var t2 = new Thread(p1, 2); 127 var g = new AsyncSliceGroup(); 128 g.push(newAsyncSlice(0, 1, t1, t1)); 129 g.push(newAsyncSlice(0, 1, t2, t2)); 130 var track = new AsyncSliceGroupTrack(new tracing.TimelineViewport()); 131 track.group = g; 132 var subRows = track.subRows; 133 134 var subGroups = g.computeSubGroups(); 135 assertEquals(2, subGroups.length); 136 137 assertEquals(g.name, subGroups[0].name); 138 assertEquals(1, subGroups[0].slices.length); 139 assertEquals(g.slices[0], subGroups[0].slices[0]); 140 141 assertEquals(g.name, subGroups[1].name); 142 assertEquals(1, subGroups[1].slices.length); 143 assertEquals(g.slices[1], subGroups[1].slices[0]); 144 }); 145 }); 146