Html程序  |  63行  |  1.64 KB

<!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>
<title>TimelineCpu tests</title>
<script src="base.js"></script>
<script>
  base.require('unittest');
  base.require('test_utils');
  base.require('timeline_cpu');
</script>
</head>
<body>
<script>
  'use strict';

  var TimelineCpu = tracing.TimelineCpu;
  var TimelineSlice = tracing.TimelineSlice;

  function testCpuBounds_Empty() {
    var cpu = new TimelineCpu(undefined, 1);
    cpu.updateBounds();
    assertEquals(undefined, cpu.minTimestamp);
    assertEquals(undefined, cpu.maxTimestamp);
  }

  function testCpuBounds_OneSlice() {
    var cpu = new TimelineCpu(undefined, 1);
    cpu.slices.push(test_utils.newSlice(1, 3));
    cpu.updateBounds();
    assertEquals(1, cpu.minTimestamp);
    assertEquals(4, cpu.maxTimestamp);
  }

  function testGetOrCreateCounter() {
    var cpu = new TimelineCpu(undefined, 1);
    var ctrBar = cpu.getOrCreateCounter('foo', 'bar');
    var ctrBar2 = cpu.getOrCreateCounter('foo', 'bar');
    assertEquals(ctrBar2, ctrBar);
  }

  function testShiftTimestampsForward() {
    var cpu = new TimelineCpu(undefined, 1);
    var ctr = cpu.getOrCreateCounter('foo', 'bar');
    cpu.slices.push(test_utils.newSlice(1, 3));
    var shiftCount = 0;
    ctr.shiftTimestampsForward = function(ts) {
      if (ts == 0.32)
        shiftCount++;
    };
    cpu.slices.push(test_utils.newSlice(1, 3));
    cpu.shiftTimestampsForward(0.32);
    assertEquals(shiftCount, 1);
    assertEquals(1.32, cpu.slices[0].start);
  }
</script>
</body>
</html>