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>TimelineThread tests</title>
     10 <script src="base.js"></script>
     11 <script>
     12   base.require('unittest');
     13   base.require('test_utils');
     14   base.require('timeline_model');
     15 </script>
     16 </head>
     17 <body>
     18 <script>
     19   'use strict';
     20 
     21   var TimelineThreadSlice = tracing.TimelineThreadSlice;
     22   var TimelineProcess = tracing.TimelineProcess;
     23   var TimelineThread = tracing.TimelineThread;
     24   var newSliceNamed = test_utils.newSliceNamed;
     25   var newAsyncSlice = test_utils.newAsyncSlice;
     26   var newAsyncSliceNamed = test_utils.newAsyncSliceNamed;
     27 
     28   function testPTIDFromPidAndTid() {
     29     assertEquals('1:2', TimelineThread.getPTIDFromPidAndTid(1, 2));
     30   }
     31 
     32   function testThreadBounds_Empty() {
     33     var t = new TimelineThread(new TimelineProcess(7), 1);
     34     t.updateBounds();
     35     assertEquals(undefined, t.minTimestamp);
     36     assertEquals(undefined, t.maxTimestamp);
     37   }
     38 
     39   function testThreadBounds_SubRow() {
     40     var t = new TimelineThread(new TimelineProcess(7), 1);
     41     t.pushSlice(new TimelineThreadSlice('', 'a', 0, 1, {}, 3));
     42     t.updateBounds();
     43     assertEquals(1, t.minTimestamp);
     44     assertEquals(4, t.maxTimestamp);
     45   }
     46 
     47   function testThreadBounds_AsyncSliceGroup() {
     48     var t = new TimelineThread(new TimelineProcess(7), 1);
     49     t.pushSlice(new TimelineThreadSlice('', 'a', 0, 1, {}, 3));
     50     t.asyncSlices.push(newAsyncSlice(0.1, 5, t, t));
     51     t.updateBounds();
     52     assertEquals(0.1, t.minTimestamp);
     53     assertEquals(5.1, t.maxTimestamp);
     54   }
     55 
     56   function testThreadBounds_Cpu() {
     57     var t = new TimelineThread(new TimelineProcess(7), 1);
     58     t.cpuSlices = [newSliceNamed('x', 0, 1)];
     59     t.updateBounds();
     60     assertEquals(0, t.minTimestamp);
     61     assertEquals(1, t.maxTimestamp);
     62   }
     63 
     64   function testShiftTimestampsForwardWithCpu() {
     65     var t = new TimelineThread(new TimelineProcess(7), 1);
     66     t.pushSlice(new TimelineThreadSlice('', 'a', 0, 0, {}, 3));
     67     t.asyncSlices.push(newAsyncSlice(0, 5, t, t));
     68     t.cpuSlices = [newSliceNamed('x', 0, 1)];
     69 
     70     var shiftCount = 0;
     71     t.asyncSlices.shiftTimestampsForward = function(ts) {
     72       if (ts == 0.32)
     73         shiftCount++;
     74     };
     75 
     76     t.shiftTimestampsForward(0.32);
     77 
     78     assertEquals(1, shiftCount);
     79     assertEquals(0.32, t.slices[0].start);
     80     assertEquals(0.32, t.cpuSlices[0].start);
     81   }
     82 
     83   function testShiftTimestampsForwardWithoutCpu() {
     84     var t = new TimelineThread(new TimelineProcess(7), 1);
     85     t.pushSlice(new TimelineThreadSlice('', 'a', 0, 0, {}, 3));
     86     t.asyncSlices.push(newAsyncSlice(0, 5, t, t));
     87 
     88     var shiftCount = 0;
     89     t.asyncSlices.shiftTimestampsForward = function(ts) {
     90       if (ts == 0.32)
     91         shiftCount++;
     92     };
     93 
     94     t.shiftTimestampsForward(0.32);
     95 
     96     assertEquals(1, shiftCount);
     97     assertEquals(0.32, t.slices[0].start);
     98   }
     99 </script>
    100 </body>
    101 </html>
    102