1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 'use strict'; 6 7 base.require('tracing.test_utils'); 8 base.require('tracing.selection'); 9 base.require('tracing.trace_model.object_collection'); 10 base.require('tracing.timeline_viewport'); 11 base.require('tracing.tracks.drawing_container'); 12 base.require('tracing.tracks.object_instance_track'); 13 14 base.unittest.testSuite('tracing.tracks.object_instance_track', function() { 15 var Selection = tracing.Selection; 16 var ObjectInstanceTrack = tracing.tracks.ObjectInstanceTrack; 17 var Viewport = tracing.TimelineViewport; 18 19 var createObjects = function() { 20 var objects = new tracing.trace_model.ObjectCollection({}); 21 objects.idWasCreated('0x1000', 'cc', 'Frame', 10); 22 objects.addSnapshot('0x1000', 'cc', 'Frame', 10, 'snapshot-1'); 23 objects.addSnapshot('0x1000', 'cc', 'Frame', 25, 'snapshot-2'); 24 objects.addSnapshot('0x1000', 'cc', 'Frame', 40, 'snapshot-3'); 25 objects.idWasDeleted('0x1000', 'cc', 'Frame', 45); 26 27 objects.idWasCreated('0x1001', 'skia', 'Picture', 20); 28 objects.addSnapshot('0x1001', 'skia', 'Picture', 20, 'snapshot-1'); 29 objects.idWasDeleted('0x1001', 'skia', 'Picture', 25); 30 return objects; 31 }; 32 33 test('instantiate', function() { 34 var objects = createObjects(); 35 var frames = objects.getAllInstancesByTypeName()['Frame']; 36 frames[0].snapshots[1].selected = true; 37 38 var div = document.createElement('div'); 39 this.addHTMLOutput(div); 40 41 var viewport = new Viewport(div); 42 var drawingContainer = new tracing.tracks.DrawingContainer(viewport); 43 div.appendChild(drawingContainer); 44 45 var track = ObjectInstanceTrack(viewport); 46 drawingContainer.invalidate(); 47 drawingContainer.appendChild(track); 48 49 track.heading = 'testBasic'; 50 track.objectInstances = frames; 51 track.viewport.xSetWorldBounds(0, 50, track.clientWidth); 52 }); 53 54 test('selectionHitTestingWithThreadTrack', function() { 55 var objects = createObjects(); 56 var frames = objects.getAllInstancesByTypeName()['Frame']; 57 58 var track = ObjectInstanceTrack(new Viewport()); 59 track.objectInstances = frames; 60 61 // Hit outside range 62 var selection = new Selection(); 63 track.addIntersectingItemsInRangeToSelectionInWorldSpace( 64 8, 8.1, 0.1, selection); 65 assertEquals(0, selection.length); 66 67 // Hit the first snapshot, via pixel-nearness. 68 selection = new Selection(); 69 track.addIntersectingItemsInRangeToSelectionInWorldSpace( 70 9.98, 9.99, 0.1, selection); 71 assertEquals(1, selection.length); 72 assertEquals(1, selection.getNumObjectSnapshotHits()); 73 74 // Hit the instance, between the 1st and 2nd snapshots 75 selection = new Selection(); 76 track.addIntersectingItemsInRangeToSelectionInWorldSpace( 77 20, 20.1, 0.1, selection); 78 assertEquals(1, selection.length); 79 assertEquals(1, selection.getNumObjectInstanceHits()); 80 }); 81 }); 82