blob: 6a90adb4346c3f1b07e266cfa4413c4c09919899 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 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/location.html">
<link rel="import" href="/core/test_utils.html">
<link rel="import" href="/core/timeline_track_view.html">
<link rel="import" href="/core/timeline_viewport.html">
<link rel="import" href="/core/trace_model/trace_model.html">
<script>
'use strict';
tv.b.unittest.testSuite(function() {
var Location = tv.c.Location;
var Model = tv.c.TraceModel;
test('locationObj', function() {
var model = new tv.c.TraceModel();
var process = model.getOrCreateProcess(123);
var thread = process.getOrCreateThread(456);
model.importTraces([], false, false, function() {
thread.asyncSliceGroup.push(
tv.c.test_utils.newAsyncSliceNamed('a', 80, 20, thread, thread));
thread.asyncSliceGroup.push(
tv.c.test_utils.newAsyncSliceNamed('a', 85, 10, thread, thread));
});
var timeline = new tv.c.TimelineTrackView();
var vp = new tv.c.TimelineViewport(timeline);
timeline.model = model;
timeline.focusElement = timeline;
timeline.tabIndex = 0;
timeline.style.maxHeight = '600px';
this.addHTMLOutput(timeline);
// Our stableId to track map is not automatically built. We need to
// search for the tracks and manually build the stableId map here.
var processTracks = document.getElementsByClassName('process-track-base');
vp.modelTrackContainer = {
addContainersToTrackMap: function(containerToTrackObj) {
// Invoking the process track's addContainersToTrackMap is enough to
// build the map for all children (i.e. Threads, AsyncSliceGroups)
// as well.
for (var i = 0; i < processTracks.length; i++)
processTracks[i].addContainersToTrackMap(containerToTrackObj);
},
addEventListener: function() {},
canvas: {
offsetLeft: tv.c.constants.HEADING_WIDTH,
offsetTop: 0
}
};
vp.rebuildContainerToTrackMap();
var asyncTrack =
vp.containerToTrackObj.getTrackByStableId('123.456.AsyncSliceGroup');
assert.isNotNull(asyncTrack);
assert.isFalse(asyncTrack.expanded); // Make sure this starts unexpanded.
// Hack to allow Location to find the element we're looking for.
// This ensures the correct behaviour of document.elementFrompoint(x,y) of
// an originally off-screen element.
asyncTrack.scrollIntoView();
var boundRect = asyncTrack.getBoundingClientRect();
var viewX = boundRect.left;
var viewY = boundRect.top + boundRect.height / 2;
var location = Location.fromViewCoordinates(vp, viewX, viewY);
assert.equal(asyncTrack, location.getContainingTrack(vp));
assert.deepEqual(location.toViewCoordinates(vp),
{ viewX: viewX, viewY: viewY });
// Try expanding the multi-row track so that the dimensions of the thread
// track changes.
asyncTrack.expanded = true;
// Expanding the track causes the height to double. We can calculate the new
// viewY with respect to the track's old boundRect. ViewX remains unchanged.
var expandedViewY = boundRect.top + boundRect.height;
assert.deepEqual(location.toViewCoordinates(vp),
{ viewX: viewX, viewY: expandedViewY });
// Test the functionality of fromStableIdAndTimestamp.
var locationFromCoord =
Location.fromViewCoordinates(vp, viewX, boundRect.top);
var locationFromStableId =
Location.fromStableIdAndTimestamp(vp, '123.456.AsyncSliceGroup',
location.xWorld);
assert.deepEqual(locationFromCoord, locationFromStableId);
// Undo scroll.
document.getElementById('results-container').scrollTop = 0;
});
});
</script>