1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. 5 Use of this source code is governed by a BSD-style license that can be 6 found in the LICENSE file. 7 --> 8 <head> 9 <title>Timeline selection tests</title> 10 <script src="base.js"></script> 11 <script> 12 base.require('unittest'); 13 base.require('test_utils'); 14 base.require('timeline_model'); 15 base.require('timeline_selection'); 16 base.require('tracks.timeline_slice_track'); 17 </script> 18 </head> 19 <body> 20 <script> 21 'use strict'; 22 23 function testSelectionObject() { 24 var model = new tracing.TimelineModel(); 25 var p1 = model.getOrCreateProcess(1); 26 var t1 = p1.getOrCreateThread(1); 27 t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 1, {}, 3)); 28 t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 5, {}, 1)); 29 30 var sel = new tracing.TimelineSelection(); 31 sel.addSlice({}, t1.slices[0]); 32 33 assertEquals(1, sel.range.min); 34 assertEquals(4, sel.range.max); 35 assertEquals(t1.slices[0], sel[0].slice); 36 37 sel.addSlice({}, t1.slices[1]); 38 assertEquals(1, sel.range.min); 39 assertEquals(6, sel.range.max); 40 assertEquals(t1.slices[1], sel[1].slice); 41 42 sel.clear(); 43 assertEquals(0, sel.length); 44 } 45 46 function testShiftedSelection() { 47 var model = new tracing.TimelineModel(); 48 var p1 = model.getOrCreateProcess(1); 49 var t1 = p1.getOrCreateThread(1); 50 t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 1, {}, 3)); 51 t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 5, {}, 1)); 52 53 var track = new tracks.TimelineSliceTrack(); 54 track.slices = t1.slices; 55 56 var sel = new tracing.TimelineSelection(); 57 sel.addSlice(track, t1.slices[0]); 58 59 var shifted = sel.getShiftedSelection(1); 60 assertEquals(1, shifted.length); 61 assertEquals(t1.slices[1], shifted[0].slice); 62 } 63 </script> 64 </body> 65 </html> 66