Home | History | Annotate | Download | only in model
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2015 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 
      8 <link rel="import" href="/tracing/model/device.html">
      9 <link rel="import" href="/tracing/model/model.html">
     10 <link rel="import" href="/tracing/model/power_series.html">
     11 
     12 <script>
     13 'use strict';
     14 
     15 tr.b.unittest.testSuite(function() {
     16 
     17   var Device = tr.model.Device;
     18   var Model = tr.Model;
     19   var PowerSeries = tr.model.PowerSeries;
     20 
     21   test('updateBounds', function() {
     22     var device = new Device(new Model());
     23     device.powerSeries = new PowerSeries(device);
     24 
     25     // Verify that the bounds match the lowest and highest timestamps.
     26     device.powerSeries.addPowerSample(100, 5);
     27     device.powerSeries.addPowerSample(200, 5);
     28     device.updateBounds();
     29 
     30     assert.equal(device.bounds.min, 100);
     31     assert.equal(device.bounds.max, 200);
     32 
     33     // Add a new sample and verify that the bounds change.
     34     device.powerSeries.addPowerSample(700, 5);
     35     device.updateBounds();
     36 
     37     assert.equal(device.bounds.min, 100);
     38     assert.equal(device.bounds.max, 700);
     39  });
     40 
     41   test('shiftTimestampsForward', function() {
     42     var device = new Device(new Model());
     43     device.powerSeries = new PowerSeries(device);
     44 
     45     device.powerSeries.addPowerSample(100, 2);
     46     device.powerSeries.addPowerSample(200, 2);
     47     device.shiftTimestampsForward(2);
     48 
     49     assert.equal(device.powerSeries.samples[0].start, 102);
     50     assert.equal(device.powerSeries.samples[1].start, 202);
     51   });
     52 
     53   test('iterateAllChildEventContainers', function() {
     54     var device = new Device(new Model());
     55 
     56     // Power series shouldn't be included as a child until one's set.
     57     var childEventContainers = [];
     58     device.iterateAllChildEventContainers(function(eventContainer) {
     59       childEventContainers.push(eventContainer);
     60     });
     61 
     62     assert.deepEqual(childEventContainers, []);
     63 
     64     device.powerSeries = new PowerSeries(device);
     65 
     66     // Verify that the power series is now included as a child.
     67     var childEventContainers = [];
     68     device.iterateAllChildEventContainers(function(eventContainer) {
     69       childEventContainers.push(eventContainer);
     70     });
     71 
     72     assert.deepEqual(childEventContainers, [device.powerSeries]);
     73   });
     74 });
     75 </script>
     76