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>TimelineCpu tests</title>
     10 <script src="base.js"></script>
     11 <script>
     12   base.require('unittest');
     13   base.require('test_utils');
     14   base.require('timeline_cpu');
     15 </script>
     16 </head>
     17 <body>
     18 <script>
     19   'use strict';
     20 
     21   var TimelineCpu = tracing.TimelineCpu;
     22   var TimelineSlice = tracing.TimelineSlice;
     23 
     24   function testCpuBounds_Empty() {
     25     var cpu = new TimelineCpu(undefined, 1);
     26     cpu.updateBounds();
     27     assertEquals(undefined, cpu.minTimestamp);
     28     assertEquals(undefined, cpu.maxTimestamp);
     29   }
     30 
     31   function testCpuBounds_OneSlice() {
     32     var cpu = new TimelineCpu(undefined, 1);
     33     cpu.slices.push(test_utils.newSlice(1, 3));
     34     cpu.updateBounds();
     35     assertEquals(1, cpu.minTimestamp);
     36     assertEquals(4, cpu.maxTimestamp);
     37   }
     38 
     39   function testGetOrCreateCounter() {
     40     var cpu = new TimelineCpu(undefined, 1);
     41     var ctrBar = cpu.getOrCreateCounter('foo', 'bar');
     42     var ctrBar2 = cpu.getOrCreateCounter('foo', 'bar');
     43     assertEquals(ctrBar2, ctrBar);
     44   }
     45 
     46   function testShiftTimestampsForward() {
     47     var cpu = new TimelineCpu(undefined, 1);
     48     var ctr = cpu.getOrCreateCounter('foo', 'bar');
     49     cpu.slices.push(test_utils.newSlice(1, 3));
     50     var shiftCount = 0;
     51     ctr.shiftTimestampsForward = function(ts) {
     52       if (ts == 0.32)
     53         shiftCount++;
     54     };
     55     cpu.slices.push(test_utils.newSlice(1, 3));
     56     cpu.shiftTimestampsForward(0.32);
     57     assertEquals(shiftCount, 1);
     58     assertEquals(1.32, cpu.slices[0].start);
     59   }
     60 </script>
     61 </body>
     62 </html>
     63