1<!DOCTYPE HTML>
2<html>
3<!--
4Copyright (c) 2012 The Chromium Authors. All rights reserved.
5Use of this source code is governed by a BSD-style license that can be
6found in the LICENSE file.
7-->
8<head i18n-values="dir:textdirection;">
9<title>TimelineTrack tests</title>
10<style>
11.timeline-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');
20  base.require('tracks.timeline_thread_track');
21</script>
22</head>
23<body>
24<script>
25  'use strict';
26
27  var TimelineProcess = tracing.TimelineProcess;
28  var TimelineSelection = tracing.TimelineSelection;
29  var TimelineThread = tracing.TimelineThread;
30  var TimelineThreadSlice = tracing.TimelineThreadSlice;
31  var TimelineThreadTrack = tracks.TimelineThreadTrack;
32  var TimelineViewport = tracing.TimelineViewport;
33  var newAsyncSlice = test_utils.newAsyncSlice;
34  var newAsyncSliceNamed = test_utils.newAsyncSliceNamed;
35  var newSliceNamed = test_utils.newSliceNamed;
36
37  function testSelectionHitTestingWithTimelineThreadTrack() {
38    var model = new tracing.TimelineModel();
39    var p1 = model.getOrCreateProcess(1);
40    var t1 = p1.getOrCreateThread(1);
41    t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 1, {}, 4));
42    t1.pushSlice(new tracing.TimelineThreadSlice('', 'b', 0, 5.1, {}, 4));
43
44    var testEl = this.addHTMLOutput();
45    testEl.style.width = '600px';
46    var track = new TimelineThreadTrack();
47    testEl.appendChild(track);
48    track.heading = 'testSelectionHitTestingWithTimelineThreadTrack';
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 TimelineViewport(testEl);
57    track.viewport.xSetWorldRange(0, wW, vW);
58
59    var selection = new TimelineSelection();
60    track.addIntersectingItemsToSelection((1.5/wW)*vW, y, selection);
61    assertEquals(t1.slices[0], selection[0].slice);
62
63    var selection = new TimelineSelection();
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 testTimelineThreadTrackWithRegularSlices() {
71    var testEl = this.addHTMLOutput();
72    var track = TimelineThreadTrack();
73    testEl.appendChild(track);
74    track.heading = 'testTimelineThreadTrackWithRegularSlices';
75    var thread = new TimelineThread(new TimelineProcess(7), 1);
76    thread.pushSlices([
77        new TimelineThreadSlice('', 'a', 0, 1, {}, 1),
78        new TimelineThreadSlice('', 'b', 1, 2.1, {}, 4.8),
79        new TimelineThreadSlice('', 'b', 1, 7, {}, 0.5),
80        new TimelineThreadSlice('', 'c', 2, 7.6, {}, 0.4),
81        new TimelineThreadSlice('', 'd', 3, 1.1, {}, 0.8),
82        new TimelineThreadSlice('', '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 TimelineViewport(testEl);
90    track.viewport.xSetWorldRange(0, 8.2, track.clientWidth);
91  }
92
93  function testTimelineThreadTrackWithTallSlices() {
94    var testEl = this.addHTMLOutput();
95    var track = TimelineThreadTrack();
96    testEl.appendChild(track);
97    track.heading = 'testTimelineThreadTrackWithTallSlices';
98    var thread = new TimelineThread(new TimelineProcess(7), 1);
99    thread.pushSlices([
100      new TimelineThreadSlice('', 'a', 1, 0, {}, 1),
101      new TimelineThreadSlice('', 'b', 2, 0.1, {}, 0.8),
102      new TimelineThreadSlice('', 'c', 3, 0.15, {}, 0.70),
103      new TimelineThreadSlice('', 'd', 4, 0.20, {}, 0.50),
104      new TimelineThreadSlice('', 'e', 5, 0.30, {}, 0.28),
105      new TimelineThreadSlice('', 'e', 6, 0.35, {}, 0.20),
106      new TimelineThreadSlice('', '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 TimelineViewport(testEl);
114    track.viewport.xSetWorldRange(0, 1.1, track.clientWidth);
115  }
116
117  function testTimelineThreadTrackWithRegularAndAsyncSlices() {
118    var testEl = this.addHTMLOutput();
119    var track = TimelineThreadTrack();
120    testEl.appendChild(track);
121    var thread = new TimelineThread(new TimelineProcess(7), 1);
122    thread.pushSlices([
123        new TimelineThreadSlice('', 'a', 0, 1, {}, 1),
124        new TimelineThreadSlice('', 'b', 1, 2.1, {}, 4.8),
125        new TimelineThreadSlice('', 'b', 1, 7, {}, 0.5),
126        new TimelineThreadSlice('', 'c', 2, 7.6, {}, 0.4),
127        new TimelineThreadSlice('', 'd', 3, 1.1, {}, 0.8),
128        new TimelineThreadSlice('', '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 TimelineViewport(testEl);
138    track.viewport.xSetWorldRange(0, 8.15, track.clientWidth);
139  }
140
141  function testFilterThreadSlices() {
142    var thread = new TimelineThread(new TimelineProcess(7), 1);
143    thread.pushSlice(newSliceNamed('a', 0, 0));
144    thread.asyncSlices.push(newAsyncSliceNamed('a', 0, 5, t, t));
145
146    var t = new TimelineThreadTrack();
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.TimelineTitleFilter('x');
155    assertFalse(t.tracks_[1].visible);
156    assertFalse(t.tracks_[1].visible);
157
158    t.categoryFilter = new tracing.TimelineTitleFilter('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</script>
165</body>
166</html>
167