Home | History | Annotate | Download | only in tracks
      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 <link rel='import' href='/tracing/ui/base/constants.html'>
     12 <link rel='import' href='/tracing/ui/timeline_viewport.html'>
     13 <link rel='import' href='/tracing/ui/tracks/container_to_track_map.html'>
     14 <link rel='import' href='/tracing/ui/tracks/drawing_container.html'>
     15 <link rel="import" href="/tracing/ui/tracks/power_series_track.html">
     16 
     17 <script>
     18 'use strict';
     19 
     20 tr.b.unittest.testSuite(function() {
     21 
     22   var Device = tr.model.Device;
     23   var Model = tr.Model;
     24   var PowerSeries = tr.model.PowerSeries;
     25   var PowerSeriesTrack = tr.ui.tracks.PowerSeriesTrack;
     26 
     27   var createDrawingContainer = function(series) {
     28     var div = document.createElement('div');
     29     var viewport = new tr.ui.TimelineViewport(div);
     30     var drawingContainer = new tr.ui.tracks.DrawingContainer(viewport);
     31     div.appendChild(drawingContainer);
     32 
     33     if (series) {
     34       series.updateBounds();
     35       setDisplayTransformFromBounds(viewport, series.bounds);
     36     }
     37 
     38     return drawingContainer;
     39   };
     40 
     41   /**
     42    * Sets the mapping between the input range of timestamps and the output range
     43    * of horizontal pixels.
     44    */
     45   var setDisplayTransformFromBounds = function(viewport, bounds) {
     46     var dt = new tr.ui.TimelineDisplayTransform();
     47     var pixelRatio = window.devicePixelRatio || 1;
     48     var chartPixelWidth =
     49         (window.innerWidth - tr.ui.b.constants.HEADING_WIDTH) * pixelRatio;
     50     dt.xSetWorldBounds(bounds.min, bounds.max, chartPixelWidth);
     51     viewport.setDisplayTransformImmediately(dt);
     52   };
     53 
     54   test('instantiate', function() {
     55     var series = new PowerSeries(new Model().device);
     56     series.addPowerSample(0, 1);
     57     series.addPowerSample(0.5, 2);
     58     series.addPowerSample(1, 3);
     59     series.addPowerSample(1.5, 4);
     60 
     61     var drawingContainer = createDrawingContainer(series);
     62     var track = new PowerSeriesTrack(drawingContainer.viewport);
     63     track.powerSeries = series;
     64     drawingContainer.appendChild(track);
     65 
     66     this.addHTMLOutput(drawingContainer);
     67   });
     68 
     69   test('hasVisibleContent_trueWithPowerSamplesPresent', function() {
     70     var series = new PowerSeries(new Model().device);
     71     series.addPowerSample(0, 1);
     72     series.addPowerSample(0.5, 2);
     73     series.addPowerSample(1, 3);
     74     series.addPowerSample(1.5, 4);
     75 
     76     var div = document.createElement('div');
     77     var viewport = new tr.ui.TimelineViewport(div);
     78 
     79     var track = new PowerSeriesTrack(viewport);
     80     track.powerSeries = series;
     81 
     82     assert.isTrue(track.hasVisibleContent);
     83   });
     84 
     85   test('hasVisibleContent_falseWithUndefinedPowerSeries', function() {
     86     var div = document.createElement('div');
     87     var viewport = new tr.ui.TimelineViewport(div);
     88 
     89     var track = new PowerSeriesTrack(viewport);
     90     track.powerSeries = undefined;
     91 
     92     assert.notOk(track.hasVisibleContent);
     93   });
     94 
     95   test('hasVisibleContent_falseWithEmptyPowerSeries', function() {
     96     var div = document.createElement('div');
     97     var viewport = new tr.ui.TimelineViewport(div);
     98 
     99     var track = new PowerSeriesTrack(viewport);
    100     var series = new PowerSeries(new Model().device);
    101     track.powerSeries = series;
    102 
    103     assert.notOk(track.hasVisibleContent);
    104   });
    105 
    106   test('addContainersToTrackMap', function() {
    107     var div = document.createElement('div');
    108     var viewport = new tr.ui.TimelineViewport(div);
    109 
    110     var powerSeriesTrack = new PowerSeriesTrack(viewport);
    111     var series = new PowerSeries(new Model().device);
    112     powerSeriesTrack.powerSeries = series;
    113 
    114     var containerToTrackMap = new tr.ui.tracks.ContainerToTrackMap();
    115     powerSeriesTrack.addContainersToTrackMap(containerToTrackMap);
    116 
    117     assert.equal(
    118         containerToTrackMap.getTrackByStableId('Device.PowerSeries'),
    119         powerSeriesTrack);
    120   });
    121 });
    122 </script>
    123