1// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5'use strict';
6
7base.require('tracing.test_utils');
8base.require('tracing.trace_model.cpu');
9
10base.unittest.testSuite('tracing.trace_model.cpu', function() {
11  var Cpu = tracing.trace_model.Cpu;
12
13  test('cpuBounds_Empty', function() {
14    var cpu = new Cpu(undefined, 1);
15    cpu.updateBounds();
16    assertEquals(undefined, cpu.bounds.min);
17    assertEquals(undefined, cpu.bounds.max);
18  });
19
20  test('cpuBounds_OneSlice', function() {
21    var cpu = new Cpu(undefined, 1);
22    cpu.slices.push(tracing.test_utils.newSlice(1, 3));
23    cpu.updateBounds();
24    assertEquals(1, cpu.bounds.min);
25    assertEquals(4, cpu.bounds.max);
26  });
27
28  test('getOrCreateCounter', function() {
29    var cpu = new Cpu(undefined, 1);
30    var ctrBar = cpu.getOrCreateCounter('foo', 'bar');
31    var ctrBar2 = cpu.getOrCreateCounter('foo', 'bar');
32    assertEquals(ctrBar2, ctrBar);
33  });
34
35  test('shiftTimestampsForward', function() {
36    var cpu = new Cpu(undefined, 1);
37    var ctr = cpu.getOrCreateCounter('foo', 'bar');
38    cpu.slices.push(tracing.test_utils.newSlice(1, 3));
39    var shiftCount = 0;
40    ctr.shiftTimestampsForward = function(ts) {
41      if (ts == 0.32)
42        shiftCount++;
43    };
44    cpu.slices.push(tracing.test_utils.newSlice(1, 3));
45    cpu.shiftTimestampsForward(0.32);
46    assertEquals(shiftCount, 1);
47    assertEquals(1.32, cpu.slices[0].start);
48  });
49});
50