<!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 selection tests</title> <script src="base.js"></script> <script> base.require('unittest'); base.require('test_utils'); base.require('model'); base.require('selection'); base.require('tracks.slice_track'); </script> </head> <body> <script> 'use strict'; function testSelectionObject() { var model = new tracing.Model(); var p1 = model.getOrCreateProcess(1); var t1 = p1.getOrCreateThread(1); t1.pushSlice(new tracing.model.ThreadSlice('', 'a', 0, 1, {}, 3)); t1.pushSlice(new tracing.model.ThreadSlice('', 'a', 0, 5, {}, 1)); var sel = new tracing.Selection(); sel.addSlice({}, t1.slices[0]); assertEquals(1, sel.bounds.min); assertEquals(4, sel.bounds.max); assertEquals(t1.slices[0], sel[0].slice); sel.addSlice({}, t1.slices[1]); assertEquals(1, sel.bounds.min); assertEquals(6, sel.bounds.max); assertEquals(t1.slices[1], sel[1].slice); sel.clear(); assertEquals(0, sel.length); } function testShiftedSelection() { var model = new tracing.Model(); var p1 = model.getOrCreateProcess(1); var t1 = p1.getOrCreateThread(1); t1.pushSlice(new tracing.model.ThreadSlice('', 'a', 0, 1, {}, 3)); t1.pushSlice(new tracing.model.ThreadSlice('', 'a', 0, 5, {}, 1)); var track = new tracing.tracks.SliceTrack(); track.slices = t1.slices; var sel = new tracing.Selection(); sel.addSlice(track, t1.slices[0]); var shifted = sel.getShiftedSelection(1); assertEquals(1, shifted.length); assertEquals(t1.slices[1], shifted[0].slice); } </script> </body> </html>