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>Track tests</title> 10 <style> 11 .container { 12 border: 1px solid red; 13 } 14 </style> 15 <script src="/src/base.js"></script> 16 <script> 17 base.require('unittest'); 18 base.require('test_utils'); 19 base.require('timeline_track_view'); 20 base.require('tracks.thread_track'); 21 </script> 22 </head> 23 <body> 24 <script> 25 'use strict'; 26 27 var Process = tracing.model.Process; 28 var Selection = tracing.Selection; 29 var Thread = tracing.model.Thread; 30 var ThreadSlice = tracing.model.ThreadSlice; 31 var ThreadTrack = tracing.tracks.ThreadTrack; 32 var Viewport = tracing.TimelineViewport; 33 var newAsyncSlice = test_utils.newAsyncSlice; 34 var newAsyncSliceNamed = test_utils.newAsyncSliceNamed; 35 var newSliceNamed = test_utils.newSliceNamed; 36 37 function testSelectionHitTestingWithThreadTrack() { 38 var model = new tracing.Model(); 39 var p1 = model.getOrCreateProcess(1); 40 var t1 = p1.getOrCreateThread(1); 41 t1.pushSlice(new tracing.model.ThreadSlice('', 'a', 0, 1, {}, 4)); 42 t1.pushSlice(new tracing.model.ThreadSlice('', 'b', 0, 5.1, {}, 4)); 43 44 var testEl = this.addHTMLOutput(); 45 testEl.style.width = '600px'; 46 var track = new ThreadTrack(); 47 testEl.appendChild(track); 48 track.heading = 'testSelectionHitTestingWithThreadTrack'; 49 track.headingWidth = '100px'; 50 track.thread = t1; 51 52 var y = track.getBoundingClientRect().top; 53 var h = track.getBoundingClientRect().height; 54 var wW = 10; 55 var vW = track.firstCanvas.getBoundingClientRect().width; 56 track.viewport = new Viewport(testEl); 57 track.viewport.xSetWorldBounds(0, wW, vW); 58 59 var selection = new Selection(); 60 track.addIntersectingItemsToSelection((1.5/wW)*vW, y, selection); 61 assertEquals(t1.slices[0], selection[0].slice); 62 63 var selection = new Selection(); 64 track.addIntersectingItemsInRangeToSelection( 65 (1.5/wW)*vW, (1.8/wW)*vW, 66 y, y + h, selection); 67 assertEquals(t1.slices[0], selection[0].slice); 68 } 69 70 function testThreadTrackWithRegularSlices() { 71 var testEl = this.addHTMLOutput(); 72 var track = ThreadTrack(); 73 testEl.appendChild(track); 74 track.heading = 'testThreadTrackWithRegularSlices'; 75 var thread = new Thread(new Process(7), 1); 76 thread.pushSlices([ 77 new ThreadSlice('', 'a', 0, 1, {}, 1), 78 new ThreadSlice('', 'b', 1, 2.1, {}, 4.8), 79 new ThreadSlice('', 'b', 1, 7, {}, 0.5), 80 new ThreadSlice('', 'c', 2, 7.6, {}, 0.4), 81 new ThreadSlice('', 'd', 3, 1.1, {}, 0.8), 82 new ThreadSlice('', 'e', 4, 7.1, {}, 0.3) 83 ]); 84 thread.updateBounds(); 85 track.heading = 'thread regular'; 86 track.headingWidth = '150px'; 87 track.toolTip = thread.userFriendlyDetails + ':'; 88 track.thread = thread; 89 track.viewport = new Viewport(testEl); 90 track.viewport.xSetWorldBounds(0, 8.2, track.clientWidth); 91 } 92 93 function testThreadTrackWithTallSlices() { 94 var testEl = this.addHTMLOutput(); 95 var track = ThreadTrack(); 96 testEl.appendChild(track); 97 track.heading = 'testThreadTrackWithTallSlices'; 98 var thread = new Thread(new Process(7), 1); 99 thread.pushSlices([ 100 new ThreadSlice('', 'a', 1, 0, {}, 1), 101 new ThreadSlice('', 'b', 2, 0.1, {}, 0.8), 102 new ThreadSlice('', 'c', 3, 0.15, {}, 0.70), 103 new ThreadSlice('', 'd', 4, 0.20, {}, 0.50), 104 new ThreadSlice('', 'e', 5, 0.30, {}, 0.28), 105 new ThreadSlice('', 'e', 6, 0.35, {}, 0.20), 106 new ThreadSlice('', 'f', 7, 0.40, {}, 0.10) 107 ]); 108 thread.updateBounds(); 109 track.heading = 'thread tall'; 110 track.headingWidth = '150px'; 111 track.toolTip = thread.userFriendlyDetails + ':'; 112 track.thread = thread; 113 track.viewport = new Viewport(testEl); 114 track.viewport.xSetWorldBounds(0, 1.1, track.clientWidth); 115 } 116 117 function testThreadTrackWithRegularAndAsyncSlices() { 118 var testEl = this.addHTMLOutput(); 119 var track = ThreadTrack(); 120 testEl.appendChild(track); 121 var thread = new Thread(new Process(7), 1); 122 thread.pushSlices([ 123 new ThreadSlice('', 'a', 0, 1, {}, 1), 124 new ThreadSlice('', 'b', 1, 2.1, {}, 4.8), 125 new ThreadSlice('', 'b', 1, 7, {}, 0.5), 126 new ThreadSlice('', 'c', 2, 7.6, {}, 0.4), 127 new ThreadSlice('', 'd', 3, 1.1, {}, 0.8), 128 new ThreadSlice('', 'e', 4, 7.1, {}, 0.3) 129 ]); 130 thread.asyncSlices.push(newAsyncSlice(1.2, 7.2 - 1.2, thread, thread)); 131 thread.asyncSlices.push(newAsyncSlice(1.3, 7.3 - 1.3, thread, thread)); 132 thread.updateBounds(); 133 track.heading = 'thread regular + async'; 134 track.headingWidth = '150px'; 135 track.toolTip = thread.userFriendlyDetails + ':'; 136 track.thread = thread; 137 track.viewport = new Viewport(testEl); 138 track.viewport.xSetWorldBounds(0, 8.15, track.clientWidth); 139 } 140 141 function testFilterThreadSlices() { 142 var thread = new Thread(new Process(7), 1); 143 thread.pushSlice(newSliceNamed('a', 0, 0)); 144 thread.asyncSlices.push(newAsyncSliceNamed('a', 0, 5, t, t)); 145 146 var t = new ThreadTrack(); 147 t.thread = thread; 148 149 assertTrue(t.tracks_[1].visible); 150 assertEquals(1, t.tracks_[1].tracks_.length); 151 assertTrue(t.tracks_[1].visible); 152 assertEquals(1, t.tracks_[2].tracks_.length); 153 154 t.categoryFilter = new tracing.TitleFilter('x'); 155 assertFalse(t.tracks_[1].visible); 156 assertFalse(t.tracks_[1].visible); 157 158 t.categoryFilter = new tracing.TitleFilter('a'); 159 assertTrue(t.tracks_[1].visible); 160 assertEquals(1, t.tracks_[1].tracks_.length); 161 assertTrue(t.tracks_[1].visible); 162 assertEquals(1, t.tracks_[2].tracks_.length); 163 } 164 165 function testSampleThreadSlices() { 166 var thread = new Thread(new Process(7), 1); 167 thread.addSample('a', 'b', 0); 168 thread.addSample('a', 'c', 5); 169 thread.addSample('aa', 'd', 10); 170 thread.addSample('aa', 'e', 15); 171 var t = new ThreadTrack(); 172 t.thread = thread; 173 // Track is visible. 174 assertTrue(t.tracks_[3].visible); 175 // Track has 4 slices. 176 assertEquals(t.tracks_[3].slices.length, 4); 177 } 178 </script> 179 </body> 180 </html> 181