<!DOCTYPE HTML>
<html>
<!--
Copyright (c) 2012 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>Timeline tests</title>
<link rel="stylesheet" href="overlay.css">
<link rel="stylesheet" href="timeline_view.css">
<link rel="stylesheet" href="timeline.css">
<link rel="stylesheet" href="../shared/css/tabs.css">
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
<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/cr/ui/tabs.js"></script>
<script src="overlay.js"></script>
<script src="measuring_stick.js"></script>
<script src="profiling_view.js"></script>
<script src="timeline_view.js"></script>
<script src="timeline_model.js"></script>
<script src="linux_perf_importer.js"></script>
<script src="trace_event_importer.js"></script>
<script src="timeline.js"></script>
<script src="timeline_track.js"></script>
<script src="sorted_array_utils.js"></script>
<script src="fast_rect_renderer.js"></script>
<script src="test_utils.js"></script>
<script>
goog.require('goog.testing.jsunit');
</script>
<style>
</style>
</head>
<body>
<script>
'use strict';
/*
* This test just instantiates a TimelineView and adds it to the DOM
* to help with non-unittest UI work.
*/
function testInstantiateTimeline() {
var events = [
{name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
{name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'},
{name: 'b', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'},
{name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}
];
var model = new tracing.TimelineModel();
model.importEvents(events);
var timeline = new tracing.Timeline();
timeline.model = model;
timeline.focusElement = timeline;
timeline.tabIndex = 0;
document.body.appendChild(timeline);
}
function testAddAllObjectsMatchingFilterToSelection() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3));
t1.subRows[0].push(new tracing.TimelineThreadSlice('b', 0, 1, {}, 3));
var t1asg = t1.asyncSlices;
t1asg.slices.push(test_utils.newAsyncSliceNamed('a', 0, 1, t1, t1));
t1asg.slices.push(test_utils.newAsyncSliceNamed('b', 1, 2, t1, t1));
var timeline = new tracing.Timeline();
timeline.model = model;
var expected = [{slice: t1asg.slices[0].subSlices[0]},
{slice: t1.subRows[0][0]}];
var result = new tracing.TimelineSelection();
timeline.addAllObjectsMatchingFilterToSelection(new tracing.TimelineFilter('a'), result);
assertEquals(2, result.length);
assertEquals(expected[0].slice, result[0].slice);
assertEquals(expected[1].slice, result[1].slice);
var expected = [{slice: t1asg.slices[1].subSlices[0]},
{slice: t1.subRows[0][1]}];
var result = new tracing.TimelineSelection();
timeline.addAllObjectsMatchingFilterToSelection(new tracing.TimelineFilter('b'), result);
assertEquals(2, result.length);
assertEquals(expected[0].slice, result[0].slice);
assertEquals(expected[1].slice, result[1].slice);
}
function testSelectionObject() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3));
t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 5, {}, 1));
var sel = new tracing.TimelineSelection();
sel.addSlice({}, t1.subRows[0][0]);
assertEquals(1, sel.range.min);
assertEquals(4, sel.range.max);
assertEquals(t1.subRows[0][0], sel[0].slice);
sel.addSlice({}, t1.subRows[0][1]);
assertEquals(1, sel.range.min);
assertEquals(6, sel.range.max);
assertEquals(t1.subRows[0][1], sel[1].slice);
sel.clear();
assertEquals(0, sel.length);
}
function testShiftedSelection() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3));
t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 5, {}, 1));
var track = new tracing.TimelineSliceTrack();
track.slices = t1.subRows[0];
var sel = new tracing.TimelineSelection();
sel.addSlice(track, t1.subRows[0][0]);
var shifted = sel.getShiftedSelection(1);
assertEquals(1, shifted.length);
assertEquals(t1.subRows[0][1], shifted[0].slice);
}
</script>
</body>
</html>