<!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>
<title>Timeline tests</title>
<script src="base.js"></script>
<script>
base.require('unittest');
base.require('test_utils');
base.require('timeline');
base.require('trace_event_importer');
</script>
</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(events);
var timeline = new tracing.Timeline();
timeline.model = model;
timeline.focusElement = timeline;
timeline.tabIndex = 0;
var outputEl = this.addHTMLOutput();
outputEl.appendChild(timeline);
}
function testAddAllObjectsMatchingFilterToSelection() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 1, {}, 3));
t1.pushSlice(new tracing.TimelineThreadSlice('', 'b', 0, 1.1, {}, 2.8));
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.slices[0]}];
var result = new tracing.TimelineSelection();
timeline.addAllObjectsMatchingFilterToSelection(
new tracing.TimelineTitleFilter('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.slices[1]}];
var result = new tracing.TimelineSelection();
timeline.addAllObjectsMatchingFilterToSelection(
new tracing.TimelineTitleFilter('b'), result);
assertEquals(2, result.length);
assertEquals(expected[0].slice, result[0].slice);
assertEquals(expected[1].slice, result[1].slice);
}
function testEmptyThreadsDeleted() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
var timeline = new tracing.Timeline();
timeline.model = model;
assertEquals(0, timeline.numVisibleTracks);
}
function NoCountersFilter() {
}
NoCountersFilter.prototype = {
__proto__: tracing.TimelineFilter.prototype,
matchCounter: function(c) {
return false;
}
};
function testFilteredCounters() {
var model = new tracing.TimelineModel();
var c1 = model.getOrCreateCpu(0);
c1.getOrCreateCounter('', 'b');
var p1 = model.getOrCreateProcess(1);
p1.getOrCreateCounter('', 'a').samples = [1];
var timeline = new tracing.Timeline();
timeline.model = model;
assertEquals(2, timeline.numVisibleTracks);
timeline.categoryFilter = new NoCountersFilter();
assertEquals(0, timeline.numVisibleTracks);
}
function NoCpusFilter() {}
NoCpusFilter.prototype = {
__proto__: tracing.TimelineFilter.prototype,
matchCpu: function(c) {
return false;
}
};
function testFilteredCpus() {
var model = new tracing.TimelineModel();
var c1 = model.getOrCreateCpu(1);
c1.getOrCreateCounter('', 'a');
var timeline = new tracing.Timeline();
timeline.model = model;
assertEquals(1, timeline.numVisibleTracks);
timeline.categoryFilter = new NoCpusFilter();
assertEquals(0, timeline.numVisibleTracks);
}
function NoProcessesFilter() {
}
NoProcessesFilter.prototype = {
__proto__: tracing.TimelineFilter.prototype,
matchProcess: function(c) {
return false;
}
};
function testFilteredProcesses() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
p1.getOrCreateCounter('', 'a');
var timeline = new tracing.Timeline();
timeline.model = model;
assertEquals(1, timeline.numVisibleTracks);
timeline.categoryFilter = new NoProcessesFilter();
assertEquals(0, timeline.numVisibleTracks);
}
function NoThreadsFilter() {
}
NoThreadsFilter.prototype = {
__proto__: tracing.TimelineFilter.prototype,
matchThread: function(c) {
return false;
}
};
function testFilteredThreads() {
var model = new tracing.TimelineModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(2);
t1.pushSlice(test_utils.newSlice(0, 1));
var timeline = new tracing.Timeline();
timeline.model = model;
assertEquals(1, timeline.numVisibleTracks);
timeline.categoryFilter = new NoThreadsFilter();
assertEquals(0, timeline.numVisibleTracks);
}
</script>
</body>
</html>