blob: 675638d52c24862e940eb992c24001d0f55660bf [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2013 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.
-->
<link rel="import" href="/core/timeline_viewport.html">
<link rel="import" href="/core/test_utils.html">
<link rel="import" href="/core/trace_model/trace_model.html">
<link rel="import" href="/core/selection.html">
<link rel="import" href="/core/tracks/slice_track.html">
<link rel="import" href="/core/tracks/drawing_container.html">
<script>
'use strict';
tv.b.unittest.testSuite(function() {
test('selectionObject', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 5, {}, 1));
var sel = new tv.c.Selection();
sel.push(t1.sliceGroup.slices[0]);
assert.equal(sel.bounds.min, 1);
assert.equal(sel.bounds.max, 4);
assert.equal(sel[0], t1.sliceGroup.slices[0]);
sel.push(t1.sliceGroup.slices[1]);
assert.equal(sel.bounds.min, 1);
assert.equal(sel.bounds.max, 6);
assert.equal(sel[1], t1.sliceGroup.slices[1]);
sel.clear();
assert.equal(sel.length, 0);
});
test('shiftedSelection', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 5, {}, 1));
var viewport = new tv.c.TimelineViewport();
var track = new tv.c.tracks.SliceTrack(viewport);
viewport.modelTrackContainer = track;
track.slices = t1.sliceGroup.slices;
viewport.rebuildEventToTrackMap();
var sel = new tv.c.Selection();
sel.push(t1.sliceGroup.slices[0]);
var shifted = sel.getShiftedSelection(track.viewport, 1);
assert.equal(shifted.length, 1);
assert.equal(shifted[0], t1.sliceGroup.slices[1]);
});
test('uniqueContents', function() {
var sample1 = {guid: 1};
var sample2 = {guid: 2};
var selection = new tv.c.Selection();
selection.push(sample1);
selection.push(sample2);
assert.equal(selection.length, 2);
selection.push(sample1);
assert.equal(selection.length, 2);
});
test('userFriendlyNameSingular', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
var selection = new tv.c.Selection(t1.sliceGroup.slices[0]);
assert.isDefined(selection.userFriendlyName);
});
test('userFriendlyNamePlural', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 2, {}, 3));
var selection = new tv.c.Selection([
t1.sliceGroup.slices[0],
t1.sliceGroup.slices[1]
]);
assert.isDefined(selection.userFriendlyName);
});
test('userFriendlyNameMixedPlural', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 2, {}, 3));
var i10 = new tv.c.trace_model.ObjectInstance(
{}, '0x1000', 'cat', 'name', 10);
var s10 = i10.addSnapshot(10, {foo: 1});
var selection = new tv.c.Selection([
t1.sliceGroup.slices[0],
s10
]);
assert.isDefined(selection.userFriendlyName);
});
test('groupEventsByTitle', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 2, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'b', 0, 3, {}, 3));
var selection = new tv.c.Selection([
t1.sliceGroup.slices[0],
t1.sliceGroup.slices[1],
t1.sliceGroup.slices[2]
]);
var eventsByTitle = selection.getEventsOrganizedByTitle();
assert.equal(2, tv.b.dictionaryLength(eventsByTitle));
assert.sameMembers(eventsByTitle['a'],
[t1.sliceGroup.slices[0], t1.sliceGroup.slices[1]]);
assert.sameMembers(eventsByTitle['b'],
[t1.sliceGroup.slices[2]]);
});
test('equals', function() {
var model = new tv.c.TraceModel();
var p1 = model.getOrCreateProcess(1);
var t1 = p1.getOrCreateThread(1);
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'b', 0, 2, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'c', 0, 3, {}, 3));
t1.sliceGroup.pushSlice(
new tv.c.trace_model.ThreadSlice('', 'd', 0, 4, {}, 5));
var s1 = new tv.c.Selection([
t1.sliceGroup.slices[0],
t1.sliceGroup.slices[1],
t1.sliceGroup.slices[2]
]);
var s2 = new tv.c.Selection([
t1.sliceGroup.slices[1],
t1.sliceGroup.slices[0],
t1.sliceGroup.slices[2]
]);
var s3 = new tv.c.Selection([
t1.sliceGroup.slices[1],
t1.sliceGroup.slices[0],
t1.sliceGroup.slices[3]
]);
var s4 = new tv.c.Selection([
t1.sliceGroup.slices[1],
t1.sliceGroup.slices[0]
]);
assert.isTrue(s1.equals(s2));
assert.isFalse(s1.equals(s3));
assert.isFalse(s1.equals(s4));
});
});
</script>