Home | History | Annotate | Download | only in tracks
      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 i18n-values="dir:textdirection;">
      9 <title>Track tests</title>
     10 <style>
     11 .container {
     12   border: 1px solid red;
     13 }
     14 </style>
     15 <script src="/src/base.js"></script>
     16 <script>
     17   base.require('unittest');
     18   base.require('test_utils');
     19   base.require('timeline_track_view');
     20   base.require('model.slice_group');
     21 </script>
     22 </head>
     23 <body>
     24 <script>
     25   'use strict';
     26 
     27   var SliceGroup = tracing.model.SliceGroup;
     28   var SliceGroupTrack = tracing.tracks.SliceGroupTrack;
     29   var newSliceNamed = test_utils.newSliceNamed;
     30 
     31   function testSubRowBuilderBasic() {
     32     var group = new SliceGroup();
     33     var sA = group.pushSlice(newSliceNamed('a', 1, 2));
     34     var sB = group.pushSlice(newSliceNamed('a', 3, 1));
     35 
     36     var track = new SliceGroupTrack();
     37     track.group = group;
     38     var subRows = track.subRows_;
     39 
     40     assertEquals(0, track.badSlices_.length);
     41     assertEquals(1, subRows.length);
     42     assertEquals(2, subRows[0].length);
     43     assertArrayEquals([sA, sB], subRows[0]);
     44   }
     45 
     46   function testSubRowBuilderBasic2() {
     47     var group = new SliceGroup();
     48     var sA = group.pushSlice(newSliceNamed('a', 1, 4));
     49     var sB = group.pushSlice(newSliceNamed('b', 3, 1));
     50 
     51     var track = new SliceGroupTrack();
     52     track.group = group;
     53     var subRows = track.subRows_;
     54 
     55     assertEquals(0, track.badSlices_.length);
     56     assertEquals(2, subRows.length);
     57     assertEquals(1, subRows[0].length);
     58     assertEquals(1, subRows[1].length);
     59     assertArrayEquals([sA], subRows[0]);
     60     assertArrayEquals([sB], subRows[1]);
     61   }
     62 
     63   function testSubRowBuilderNestedExactly() {
     64     var group = new SliceGroup();
     65     var sA = group.pushSlice(newSliceNamed('a', 1, 4));
     66     var sB = group.pushSlice(newSliceNamed('b', 1, 4));
     67 
     68     var track = new SliceGroupTrack();
     69     track.group = group;
     70     var subRows = track.subRows_;
     71 
     72     assertEquals(0, track.badSlices_.length);
     73     assertEquals(2, subRows.length);
     74     assertEquals(1, subRows[0].length);
     75     assertEquals(1, subRows[1].length);
     76     assertArrayEquals([sB], subRows[0]);
     77     assertArrayEquals([sA], subRows[1]);
     78   }
     79 
     80   function testSubRowBuilderInstantEvents() {
     81     var group = new SliceGroup();
     82     var sA = group.pushSlice(newSliceNamed('a', 1, 0));
     83     var sB = group.pushSlice(newSliceNamed('b', 2, 0));
     84 
     85     var track = new SliceGroupTrack();
     86     track.group = group;
     87     var subRows = track.subRows_;
     88 
     89     assertEquals(0, track.badSlices_.length);
     90     assertEquals(1, subRows.length);
     91     assertEquals(2, subRows[0].length);
     92     assertArrayEquals([sA, sB], subRows[0]);
     93   }
     94 
     95   function testSubRowBuilderTwoInstantEvents() {
     96     var group = new SliceGroup();
     97     var sB = group.pushSlice(newSliceNamed('b', 1, 0));
     98     var sA = group.pushSlice(newSliceNamed('a', 1, 0));
     99 
    100     var track = new SliceGroupTrack();
    101     track.group = group;
    102     var subRows = track.subRows_;
    103 
    104     assertEquals(0, track.badSlices_.length);
    105     assertEquals(2, subRows.length);
    106     assertArrayEquals([sA], subRows[0]);
    107     assertArrayEquals([sB], subRows[1]);
    108   }
    109 
    110   function testSubRowBuilderOutOfOrderAddition() {
    111     var group = new SliceGroup();
    112 
    113     // Pattern being tested:
    114     // [    a     ][   b   ]
    115     // Where insertion is done backward.
    116     var sB = group.pushSlice(newSliceNamed('b', 3, 1));
    117     var sA = group.pushSlice(newSliceNamed('a', 1, 2));
    118 
    119     var track = new SliceGroupTrack();
    120     track.group = group;
    121     var subRows = track.subRows_;
    122 
    123     assertEquals(0, track.badSlices_.length);
    124     assertEquals(1, subRows.length);
    125     assertEquals(2, subRows[0].length);
    126     assertArrayEquals([sA, sB], subRows[0]);
    127   }
    128 
    129 
    130   function testSubRowBuilderOutOfOrderAddition2() {
    131     var group = new SliceGroup();
    132 
    133     // Pattern being tested:
    134     // [    a     ]
    135     //   [  b   ]
    136     // Where insertion is done backward.
    137     var sB = group.pushSlice(newSliceNamed('b', 3, 1));
    138     var sA = group.pushSlice(newSliceNamed('a', 1, 5));
    139 
    140     var track = new SliceGroupTrack();
    141     track.group = group;
    142     var subRows = track.subRows_;
    143 
    144     assertEquals(0, track.badSlices_.length);
    145     assertEquals(2, subRows.length);
    146     assertEquals(1, subRows[0].length);
    147     assertEquals(1, subRows[1].length);
    148     assertArrayEquals([sA], subRows[0]);
    149     assertArrayEquals([sB], subRows[1]);
    150   }
    151 
    152   function testSubRowBuilderOnNestedZeroLength() {
    153     var group = new SliceGroup();
    154 
    155     // Pattern being tested:
    156     // [    a    ]
    157     // [  b1 ]  []<- b2 where b2.duration = 0 and b2.end == a.end.
    158     var sB1 = group.pushSlice(newSliceNamed('b1', 1, 2));
    159     var sB2 = group.pushSlice(newSliceNamed('b2', 4, 0));
    160     var sA = group.pushSlice(newSliceNamed('a', 1, 3));
    161 
    162     var track = new SliceGroupTrack();
    163     track.group = group;
    164     var subRows = track.subRows_;
    165 
    166     assertEquals(0, track.badSlices_.length);
    167     assertEquals(2, subRows.length);
    168     assertArrayEquals([sA], subRows[0]);
    169     assertArrayEquals([sB1, sB2], subRows[1]);
    170   }
    171 
    172   function testSubRowBuilderOnGroup1() {
    173     var group = new SliceGroup();
    174 
    175     // Pattern being tested:
    176     // [    a     ]   [  c   ]
    177     //   [  b   ]
    178     var sA = group.pushSlice(newSliceNamed('a', 1, 3));
    179     var sB = group.pushSlice(newSliceNamed('b', 1.5, 1));
    180     var sC = group.pushSlice(newSliceNamed('c', 5, 0));
    181 
    182     var track = new SliceGroupTrack();
    183     track.group = group;
    184     var subRows = track.subRows_;
    185 
    186     assertEquals(0, track.badSlices_.length);
    187     assertEquals(2, subRows.length);
    188     assertArrayEquals([sA, sC], subRows[0]);
    189     assertArrayEquals([sB], subRows[1]);
    190   }
    191 
    192   function testSubRowBuilderOnGroup2() {
    193     var group = new SliceGroup();
    194 
    195     // Pattern being tested:
    196     // [    a     ]   [  d   ]
    197     //   [  b   ]
    198     //    [ c ]
    199     var sA = group.pushSlice(newSliceNamed('a', 1, 3));
    200     var sB = group.pushSlice(newSliceNamed('b', 1.5, 1));
    201     var sC = group.pushSlice(newSliceNamed('c', 1.75, 0.5));
    202     var sD = group.pushSlice(newSliceNamed('c', 5, 0.25));
    203 
    204     var track = new SliceGroupTrack();
    205     track.group = group;
    206 
    207     var subRows = track.subRows_;
    208     assertEquals(0, track.badSlices_.length);
    209     assertEquals(3, subRows.length);
    210     assertArrayEquals([sA, sD], subRows[0]);
    211     assertArrayEquals([sB], subRows[1]);
    212     assertArrayEquals([sC], subRows[2]);
    213   }
    214 
    215   function testTrackFiltering() {
    216     var group = new SliceGroup();
    217 
    218     var sA = group.pushSlice(newSliceNamed('a', 1, 3));
    219     var sB = group.pushSlice(newSliceNamed('b', 1.5, 1));
    220 
    221     var track = new SliceGroupTrack();
    222     track.group = group;
    223 
    224     assertEquals(2, track.subRows_.length);
    225     assertTrue(track.visible);
    226 
    227     track.categoryFilter = new tracing.TitleFilter('x');
    228     assertFalse(track.visible);
    229 
    230     track.categoryFilter = new tracing.TitleFilter('a');
    231     assertTrue(track.visible);
    232     assertEquals(1, track.subRows_.length);
    233 
    234     track.categoryFilter = new tracing.TitleFilter('b');
    235     assertTrue(track.visible);
    236     assertEquals(1, track.subRows_.length);
    237   }
    238 </script>
    239 </body>
    240 </html>
    241