<!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 i18n-values="dir:textdirection;"> <title>Track tests</title> <style> .container { border: 1px solid red; } </style> <script src="/src/base.js"></script> <script> base.require('unittest'); base.require('test_utils'); base.require('timeline_track_view'); base.require('model.slice_group'); </script> </head> <body> <script> 'use strict'; var SliceGroup = tracing.model.SliceGroup; var SliceGroupTrack = tracing.tracks.SliceGroupTrack; var newSliceNamed = test_utils.newSliceNamed; function testSubRowBuilderBasic() { var group = new SliceGroup(); var sA = group.pushSlice(newSliceNamed('a', 1, 2)); var sB = group.pushSlice(newSliceNamed('a', 3, 1)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(1, subRows.length); assertEquals(2, subRows[0].length); assertArrayEquals([sA, sB], subRows[0]); } function testSubRowBuilderBasic2() { var group = new SliceGroup(); var sA = group.pushSlice(newSliceNamed('a', 1, 4)); var sB = group.pushSlice(newSliceNamed('b', 3, 1)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(2, subRows.length); assertEquals(1, subRows[0].length); assertEquals(1, subRows[1].length); assertArrayEquals([sA], subRows[0]); assertArrayEquals([sB], subRows[1]); } function testSubRowBuilderNestedExactly() { var group = new SliceGroup(); var sA = group.pushSlice(newSliceNamed('a', 1, 4)); var sB = group.pushSlice(newSliceNamed('b', 1, 4)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(2, subRows.length); assertEquals(1, subRows[0].length); assertEquals(1, subRows[1].length); assertArrayEquals([sB], subRows[0]); assertArrayEquals([sA], subRows[1]); } function testSubRowBuilderInstantEvents() { var group = new SliceGroup(); var sA = group.pushSlice(newSliceNamed('a', 1, 0)); var sB = group.pushSlice(newSliceNamed('b', 2, 0)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(1, subRows.length); assertEquals(2, subRows[0].length); assertArrayEquals([sA, sB], subRows[0]); } function testSubRowBuilderTwoInstantEvents() { var group = new SliceGroup(); var sB = group.pushSlice(newSliceNamed('b', 1, 0)); var sA = group.pushSlice(newSliceNamed('a', 1, 0)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(2, subRows.length); assertArrayEquals([sA], subRows[0]); assertArrayEquals([sB], subRows[1]); } function testSubRowBuilderOutOfOrderAddition() { var group = new SliceGroup(); // Pattern being tested: // [ a ][ b ] // Where insertion is done backward. var sB = group.pushSlice(newSliceNamed('b', 3, 1)); var sA = group.pushSlice(newSliceNamed('a', 1, 2)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(1, subRows.length); assertEquals(2, subRows[0].length); assertArrayEquals([sA, sB], subRows[0]); } function testSubRowBuilderOutOfOrderAddition2() { var group = new SliceGroup(); // Pattern being tested: // [ a ] // [ b ] // Where insertion is done backward. var sB = group.pushSlice(newSliceNamed('b', 3, 1)); var sA = group.pushSlice(newSliceNamed('a', 1, 5)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(2, subRows.length); assertEquals(1, subRows[0].length); assertEquals(1, subRows[1].length); assertArrayEquals([sA], subRows[0]); assertArrayEquals([sB], subRows[1]); } function testSubRowBuilderOnNestedZeroLength() { var group = new SliceGroup(); // Pattern being tested: // [ a ] // [ b1 ] []<- b2 where b2.duration = 0 and b2.end == a.end. var sB1 = group.pushSlice(newSliceNamed('b1', 1, 2)); var sB2 = group.pushSlice(newSliceNamed('b2', 4, 0)); var sA = group.pushSlice(newSliceNamed('a', 1, 3)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(2, subRows.length); assertArrayEquals([sA], subRows[0]); assertArrayEquals([sB1, sB2], subRows[1]); } function testSubRowBuilderOnGroup1() { var group = new SliceGroup(); // Pattern being tested: // [ a ] [ c ] // [ b ] var sA = group.pushSlice(newSliceNamed('a', 1, 3)); var sB = group.pushSlice(newSliceNamed('b', 1.5, 1)); var sC = group.pushSlice(newSliceNamed('c', 5, 0)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(2, subRows.length); assertArrayEquals([sA, sC], subRows[0]); assertArrayEquals([sB], subRows[1]); } function testSubRowBuilderOnGroup2() { var group = new SliceGroup(); // Pattern being tested: // [ a ] [ d ] // [ b ] // [ c ] var sA = group.pushSlice(newSliceNamed('a', 1, 3)); var sB = group.pushSlice(newSliceNamed('b', 1.5, 1)); var sC = group.pushSlice(newSliceNamed('c', 1.75, 0.5)); var sD = group.pushSlice(newSliceNamed('c', 5, 0.25)); var track = new SliceGroupTrack(); track.group = group; var subRows = track.subRows_; assertEquals(0, track.badSlices_.length); assertEquals(3, subRows.length); assertArrayEquals([sA, sD], subRows[0]); assertArrayEquals([sB], subRows[1]); assertArrayEquals([sC], subRows[2]); } function testTrackFiltering() { var group = new SliceGroup(); var sA = group.pushSlice(newSliceNamed('a', 1, 3)); var sB = group.pushSlice(newSliceNamed('b', 1.5, 1)); var track = new SliceGroupTrack(); track.group = group; assertEquals(2, track.subRows_.length); assertTrue(track.visible); track.categoryFilter = new tracing.TitleFilter('x'); assertFalse(track.visible); track.categoryFilter = new tracing.TitleFilter('a'); assertTrue(track.visible); assertEquals(1, track.subRows_.length); track.categoryFilter = new tracing.TitleFilter('b'); assertTrue(track.visible); assertEquals(1, track.subRows_.length); } </script> </body> </html>