Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Side by Side Diff: chrome/browser/resources/tracing/timeline_track_test.html

Issue 8513009: Add TRACE_COUNTER support to about:tracing (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 Copyright (c) 2010 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>TimelineTrack tests</title>
10 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.j s"></script>
11 <script>
12 goog.require('goog.testing.jsunit');
13 </script>
14 <style>
15 * {
16 box-sizing: border-box;
17 -webkit-user-select: none;
18 }
19
20 .timeline-container {
21 border: 1px solid red;
22 }
23
24 </style>
25 <link rel="stylesheet" href="timeline.css">
26 <script src="../shared/js/cr.js"></script>
27 <script src="../shared/js/cr/event_target.js"></script>
28 <script src="../shared/js/cr/ui.js"></script>
29 <script src="../shared/js/util.js"></script>
30 <script src="timeline_model.js"></script>
31 <script src="sorted_array_utils.js"></script>
32 <script src="measuring_stick.js"></script>
33 <script src="timeline.js"></script>
34 <script src="timeline_track.js"></script>
35 <script src="fast_rect_renderer.js"></script>
36 </head>
37 <body>
38 <script>
39 </script>
40 <script>
41 var TimelineCounter = tracing.TimelineCounter;
42 var TimelineCounterTrack = tracing.TimelineCounterTrack;
43 var TimelineSliceTrack = tracing.TimelineSliceTrack;
44 var TimelineSlice = tracing.TimelineSlice;
45 var TimelineViewport = tracing.TimelineViewport;
46 var testDivs = {};
47
48 function getTestDiv(name) {
49 if (!testDivs[name]) {
50 testDivs[name] = document.createElement('div');
51 document.body.appendChild(testDivs[name]);
52 }
53 testDivs[name].textContent = '';
54 return testDivs[name];
55 }
56
57 function testBasicSlices() {
58 var testEl = getTestDiv('testBasicSlices');
59 var track = TimelineSliceTrack();
60 testEl.appendChild(track);
61 track.heading = 'testBasicSlices';
62 track.slices = [
63 new TimelineSlice('a', 0, 1, {}, 1),
64 new TimelineSlice('b', 1, 2.1, {}, 4.8),
65 new TimelineSlice('b', 1, 7, {}, 0.5),
66 new TimelineSlice('c', 2, 7.6, {}, 0.4)
67 ];
68 track.viewport = new TimelineViewport(testEl);
69 track.viewport.setPanAndScale(0,
70 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end));
71 }
72
73 function testShrinkingSliceSizes() {
74 var testEl = getTestDiv('testShrinkingSliceSizes');
75 var track = TimelineSliceTrack();
76 testEl.appendChild(track);
77 track.heading = 'testShrinkingSliceSizes';
78 var x = 0;
79 var widths = [10, 5, 4, 3, 2, 1, 0.5, 0.4, 0.3, 0.2, 0.1, 0.05];
80 var slices = [];
81 for (var i = 0; i < widths.length; i++) {
82 var s = new TimelineSlice('a', 1, x, {}, widths[i]);
83 x += s.duration + 0.5;
84 slices.push(s);
85 }
86 track.slices = slices;
87 track.viewport = new TimelineViewport(testEl);
88 track.viewport.setPanAndScale(0,
89 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end));
90 }
91
92 function testPick() {
93 var testEl = getTestDiv('testPick');
94 var track = TimelineSliceTrack();
95 testEl.appendChild(track);
96 track.heading = 'testPick';
97 track.headingWidth = '100px';
98 track.slices = [
99 new TimelineSlice('a', 0, 1, {}, 1),
100 new TimelineSlice('b', 1, 2.1, {}, 4.8)
101 ];
102 track.style.width = '500px';
103 track.viewport = new TimelineViewport(testEl);
104 track.viewport.setPanAndScale(0,
105 track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end));
106 var clientRect = track.getBoundingClientRect();
107
108 var hits = [];
109 track.pick(1.5, clientRect.top + 5, function(x, y, z) { hits.push(z); });
110 assertEquals(track.slices[0], hits[0]);
111
112 hits = [];
113 track.pick(2, clientRect.top + 5, function(x, y, z) { hits.push(z); });
114 assertEquals(0, hits.length);
115
116 hits = [];
117 track.pick(6.8, clientRect.top + 5, function(x, y, z) { hits.push(z); });
118 assertEquals(track.slices[1], hits[0]);
119
120 hits = [];
121 track.pick(6.9, clientRect.top + 5, function(x, y, z) { hits.push(z); });
122 assertEquals(0, hits.length);
123 }
124
125 function testBasicCounter() {
126 var testEl = getTestDiv('testBasicCounter');
127
128 var ctr = new TimelineCounter(undefined, 'testBasicCounter');
129 ctr.numSeries = 1;
130 ctr.seriesNames = ['value1', 'value2'];
131 ctr.seriesColors = [tracing.getStringColorId('testBasicCounter.value1'),
132 tracing.getStringColorId('testBasicCounter.value2')];
133 ctr.timestamps = [0, 1, 2, 3, 4, 5, 6, 7];
134 ctr.samples = [0, 5,
135 3, 3,
136 1, 1,
137 2, 1.1,
138 3, 0,
139 1, 7,
140 3, 0,
141 3.1, 0.5];
142 ctr.updateBounds();
143
144 var track = TimelineCounterTrack();
145 testEl.appendChild(track);
146 track.heading = ctr.name;
147 track.counter = ctr;
148 track.viewport = new TimelineViewport(testEl);
149 track.viewport.setPanAndScale(0,
150 track.clientWidth / (1.1 * ctr.maxTimestamp));
151 }
152
153 </script>
154 </body>
155 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698