Index: chrome/browser/resources/tracing/timeline_track_test.html |
diff --git a/chrome/browser/resources/tracing/timeline_track_test.html b/chrome/browser/resources/tracing/timeline_track_test.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..02eaa941fe16a37f566a617870014c021e0b5660 |
--- /dev/null |
+++ b/chrome/browser/resources/tracing/timeline_track_test.html |
@@ -0,0 +1,155 @@ |
+<!DOCTYPE HTML> |
+<html> |
+<!-- |
+Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+Use of this source code is governed by a BSD-style license that can be |
+found in the LICENSE file. |
+--> |
+<head i18n-values="dir:textdirection;"> |
+<title>TimelineTrack tests</title> |
+<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> |
James Hawkins
2011/11/17 05:19:32
80 cols.
|
+<script> |
+ goog.require('goog.testing.jsunit'); |
+</script> |
+<style> |
+* { |
+ box-sizing: border-box; |
+ -webkit-user-select: none; |
+} |
+ |
+.timeline-container { |
+ border: 1px solid red; |
+} |
+ |
+</style> |
+<link rel="stylesheet" href="timeline.css"> |
+<script src="../shared/js/cr.js"></script> |
+<script src="../shared/js/cr/event_target.js"></script> |
+<script src="../shared/js/cr/ui.js"></script> |
+<script src="../shared/js/util.js"></script> |
+<script src="timeline_model.js"></script> |
+<script src="sorted_array_utils.js"></script> |
+<script src="measuring_stick.js"></script> |
+<script src="timeline.js"></script> |
+<script src="timeline_track.js"></script> |
+<script src="fast_rect_renderer.js"></script> |
+</head> |
+<body> |
+<script> |
+</script> |
+<script> |
+ var TimelineCounter = tracing.TimelineCounter; |
+ var TimelineCounterTrack = tracing.TimelineCounterTrack; |
+ var TimelineSliceTrack = tracing.TimelineSliceTrack; |
+ var TimelineSlice = tracing.TimelineSlice; |
+ var TimelineViewport = tracing.TimelineViewport; |
+ var testDivs = {}; |
+ |
+ function getTestDiv(name) { |
+ if (!testDivs[name]) { |
+ testDivs[name] = document.createElement('div'); |
+ document.body.appendChild(testDivs[name]); |
+ } |
+ testDivs[name].textContent = ''; |
+ return testDivs[name]; |
+ } |
+ |
+ function testBasicSlices() { |
+ var testEl = getTestDiv('testBasicSlices'); |
+ var track = TimelineSliceTrack(); |
+ testEl.appendChild(track); |
+ track.heading = 'testBasicSlices'; |
+ track.slices = [ |
+ new TimelineSlice('a', 0, 1, {}, 1), |
+ new TimelineSlice('b', 1, 2.1, {}, 4.8), |
+ new TimelineSlice('b', 1, 7, {}, 0.5), |
+ new TimelineSlice('c', 2, 7.6, {}, 0.4) |
+ ]; |
+ track.viewport = new TimelineViewport(testEl); |
+ track.viewport.setPanAndScale(0, |
+ track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); |
+ } |
+ |
+ function testShrinkingSliceSizes() { |
+ var testEl = getTestDiv('testShrinkingSliceSizes'); |
+ var track = TimelineSliceTrack(); |
+ testEl.appendChild(track); |
+ track.heading = 'testShrinkingSliceSizes'; |
+ var x = 0; |
+ var widths = [10, 5, 4, 3, 2, 1, 0.5, 0.4, 0.3, 0.2, 0.1, 0.05]; |
+ var slices = []; |
+ for (var i = 0; i < widths.length; i++) { |
+ var s = new TimelineSlice('a', 1, x, {}, widths[i]); |
+ x += s.duration + 0.5; |
+ slices.push(s); |
+ } |
+ track.slices = slices; |
+ track.viewport = new TimelineViewport(testEl); |
+ track.viewport.setPanAndScale(0, |
+ track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); |
+ } |
+ |
+ function testPick() { |
+ var testEl = getTestDiv('testPick'); |
+ var track = TimelineSliceTrack(); |
+ testEl.appendChild(track); |
+ track.heading = 'testPick'; |
+ track.headingWidth = '100px'; |
+ track.slices = [ |
+ new TimelineSlice('a', 0, 1, {}, 1), |
+ new TimelineSlice('b', 1, 2.1, {}, 4.8) |
+ ]; |
+ track.style.width = '500px'; |
+ track.viewport = new TimelineViewport(testEl); |
+ track.viewport.setPanAndScale(0, |
+ track.clientWidth / (1.1 * track.slices[track.slices.length - 1].end)); |
+ var clientRect = track.getBoundingClientRect(); |
+ |
+ var hits = []; |
+ track.pick(1.5, clientRect.top + 5, function(x, y, z) { hits.push(z); }); |
+ assertEquals(track.slices[0], hits[0]); |
+ |
+ hits = []; |
+ track.pick(2, clientRect.top + 5, function(x, y, z) { hits.push(z); }); |
+ assertEquals(0, hits.length); |
+ |
+ hits = []; |
+ track.pick(6.8, clientRect.top + 5, function(x, y, z) { hits.push(z); }); |
+ assertEquals(track.slices[1], hits[0]); |
+ |
+ hits = []; |
+ track.pick(6.9, clientRect.top + 5, function(x, y, z) { hits.push(z); }); |
+ assertEquals(0, hits.length); |
+ } |
+ |
+ function testBasicCounter() { |
+ var testEl = getTestDiv('testBasicCounter'); |
+ |
+ var ctr = new TimelineCounter(undefined, 'testBasicCounter'); |
+ ctr.numSeries = 1; |
+ ctr.seriesNames = ['value1', 'value2']; |
+ ctr.seriesColors = [tracing.getStringColorId('testBasicCounter.value1'), |
+ tracing.getStringColorId('testBasicCounter.value2')]; |
+ ctr.timestamps = [0, 1, 2, 3, 4, 5, 6, 7]; |
+ ctr.samples = [0, 5, |
+ 3, 3, |
+ 1, 1, |
+ 2, 1.1, |
+ 3, 0, |
+ 1, 7, |
+ 3, 0, |
+ 3.1, 0.5]; |
+ ctr.updateBounds(); |
+ |
+ var track = TimelineCounterTrack(); |
+ testEl.appendChild(track); |
+ track.heading = ctr.name; |
+ track.counter = ctr; |
+ track.viewport = new TimelineViewport(testEl); |
+ track.viewport.setPanAndScale(0, |
+ track.clientWidth / (1.1 * ctr.maxTimestamp)); |
+ } |
+ |
+</script> |
+</body> |
+</html> |