Home | History | Annotate | Download | only in src
      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>TimelineSliceGroup tests</title>
     10 <script src="base.js"></script>
     11 <script>
     12   base.require('unittest');
     13   base.require('test_utils');
     14   base.require('timeline_slice_group');
     15 </script>
     16 </head>
     17 <body>
     18 <script>
     19   'use strict';
     20 
     21   var TimelineSlice = tracing.TimelineSlice;
     22   var TimelineSliceGroup = tracing.TimelineSliceGroup;
     23   var newSlice = test_utils.newSlice;
     24   var newSliceNamed = test_utils.newSliceNamed;
     25 
     26   function testBasicBeginEnd() {
     27     var group = new TimelineSliceGroup();
     28     assertEquals(group.openSliceCount, 0);
     29     var sliceA = group.beginSlice('', 'a', 1, {a: 1});
     30     assertEquals(1, group.openSliceCount);
     31     assertEquals('a', sliceA.title);
     32     assertEquals(1, sliceA.start);
     33     assertEquals(1, sliceA.args.a);
     34 
     35     var sliceB = group.endSlice(3);
     36     assertEquals(sliceA, sliceB);
     37     assertEquals(2, sliceB.duration);
     38   }
     39 
     40   function testNestedBeginEnd() {
     41     var group = new TimelineSliceGroup();
     42     assertEquals(group.openSliceCount, 0);
     43     group.beginSlice('', 'a', 1);
     44     group.beginSlice('', 'b', 2);
     45     group.endSlice(2.5);
     46     group.endSlice(3);
     47 
     48     assertEquals(2, group.slices.length);
     49     assertEquals('b', group.slices[0].title);
     50     assertEquals(0.5, group.slices[0].duration);
     51 
     52     assertEquals('a', group.slices[1].title);
     53     assertEquals(2, group.slices[1].duration);
     54   }
     55 
     56   function testBounds() {
     57     var group = new TimelineSliceGroup();
     58     group.updateBounds();
     59     assertEquals(group.minTimestamp, undefined);
     60     assertEquals(group.maxTimestamp, undefined);
     61 
     62     group.pushSlice(newSlice(1, 3));
     63     group.pushSlice(newSlice(7, 2));
     64     group.updateBounds();
     65     assertEquals(1, group.minTimestamp);
     66     assertEquals(9, group.maxTimestamp);
     67   }
     68 
     69   function testBoundsWithPartial() {
     70     var group = new TimelineSliceGroup();
     71     group.beginSlice('', 'a', 7);
     72     group.updateBounds();
     73     assertEquals(7, group.minTimestamp);
     74     assertEquals(7, group.maxTimestamp);
     75   }
     76 
     77   function testBoundsWithTwoPartials() {
     78     var group = new TimelineSliceGroup();
     79     group.beginSlice('', 'a', 0);
     80     group.beginSlice('', 'a', 1);
     81     group.updateBounds();
     82     assertEquals(0, group.minTimestamp);
     83     assertEquals(1, group.maxTimestamp);
     84   }
     85 
     86   function testBoundsWithBothPartialAndRegular() {
     87     var group = new TimelineSliceGroup();
     88     group.updateBounds();
     89     assertEquals(undefined, group.minTimestamp);
     90     assertEquals(undefined, group.maxTimestamp);
     91 
     92     group.pushSlice(newSlice(1, 3));
     93     group.beginSlice('', 'a', 7);
     94     group.updateBounds();
     95     assertEquals(1, group.minTimestamp);
     96     assertEquals(7, group.maxTimestamp);
     97   }
     98 
     99   function testAutocloserBasic() {
    100     var group = new TimelineSliceGroup();
    101     assertEquals(group.openSliceCount, 0);
    102 
    103     group.pushSlice(newSliceNamed('a', 1, 0.5));
    104 
    105     group.beginSlice('', 'b', 2);
    106     group.beginSlice('', 'c', 2.5);
    107     group.endSlice(3);
    108 
    109     group.autoCloseOpenSlices();
    110     group.updateBounds();
    111 
    112     assertEquals(1, group.minTimestamp);
    113     assertEquals(3, group.maxTimestamp);
    114     assertEquals(3, group.slices.length);
    115     assertEquals('a', group.slices[0].title);
    116     assertEquals('c', group.slices[1].title);
    117     assertEquals('b', group.slices[2].title);
    118     assertTrue(group.slices[2].didNotFinish);
    119     assertEquals(1, group.slices[2].duration);
    120   }
    121 
    122   function testAutocloserWithSubTasks() {
    123     var group = new TimelineSliceGroup();
    124     assertEquals(group.openSliceCount, 0);
    125 
    126     group.beginSlice('', 'a', 1);
    127     group.beginSlice('', 'b1', 2);
    128     group.endSlice(3);
    129     group.beginSlice('', 'b2', 3);
    130 
    131     group.autoCloseOpenSlices();
    132     assertEquals(3, group.slices.length);
    133     assertEquals('b1', group.slices[0].title);
    134 
    135     assertEquals('b2', group.slices[1].title);
    136     assertTrue(group.slices[1].didNotFinish);
    137     assertEquals(0, group.slices[1].duration);
    138 
    139     assertEquals('a', group.slices[2].title);
    140     assertTrue(group.slices[2].didNotFinish);
    141     assertEquals(2, group.slices[2].duration);
    142   }
    143 
    144   // TODO: test cretion of subSlices
    145 </script>
    146 </body>
    147 </html>
    148