Home | History | Annotate | Download | only in model
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2013 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/core/test_utils.html">
      9 <link rel="import" href="/tracing/model/frame.html">
     10 <link rel="import" href="/tracing/model/global_memory_dump.html">
     11 <link rel="import" href="/tracing/model/instant_event.html">
     12 <link rel="import" href="/tracing/model/model.html">
     13 <link rel="import" href="/tracing/model/process.html">
     14 <link rel="import" href="/tracing/model/thread_slice.html">
     15 
     16 <script>
     17 'use strict';
     18 
     19 tr.b.unittest.testSuite(function() {
     20   test('getOrCreateCounter', function() {
     21     var model = new tr.Model();
     22     var process = new tr.model.Process(model, 7);
     23     var ctrBar = process.getOrCreateCounter('foo', 'bar');
     24     var ctrBar2 = process.getOrCreateCounter('foo', 'bar');
     25     assert.equal(ctrBar2, ctrBar);
     26   });
     27 
     28   test('shiftTimestampsForward', function() {
     29     var model = new tr.Model();
     30     var process = new tr.model.Process(model, 7);
     31     var ctr = process.getOrCreateCounter('foo', 'bar');
     32     var thread = process.getOrCreateThread(1);
     33 
     34     var instantEvent = new tr.model.InstantEvent('cat', 'event1', 1, 100);
     35     process.instantEvents.push(instantEvent);
     36 
     37     var slice = new tr.model.ThreadSlice('', 'a', 0, 1, {}, 4);
     38     var frame =
     39         new tr.model.Frame([slice], [{thread: thread, start: 100, end: 200}]);
     40     process.frames.push(frame);
     41 
     42     var memoryDump = new tr.model.GlobalMemoryDump(model, 100);
     43     process.memoryDumps.push(memoryDump);
     44 
     45     var shiftCount = 0;
     46     thread.shiftTimestampsForward = function(ts) {
     47       if (ts == 0.32)
     48         shiftCount++;
     49     };
     50     ctr.shiftTimestampsForward = function(ts) {
     51       if (ts == 0.32)
     52         shiftCount++;
     53     };
     54 
     55     process.shiftTimestampsForward(0.32);
     56     assert.equal(shiftCount, 2);
     57     assert.equal(instantEvent.start, 100.32);
     58     assert.equal(frame.start, 100.32);
     59     assert.equal(frame.end, 200.32);
     60     assert.equal(memoryDump.start, 100.32);
     61   });
     62 
     63   test('compareOnPID', function() {
     64     var model = new tr.Model();
     65     var p1 = new tr.model.Process(model, 1);
     66     p1.name = 'Renderer';
     67 
     68     var model = new tr.Model();
     69     var p2 = new tr.model.Process(model, 2);
     70     p2.name = 'Renderer';
     71 
     72     assert.isBelow(p1.compareTo(p2), 0);
     73   });
     74 
     75   test('compareOnSortIndex', function() {
     76     var model = new tr.Model();
     77     var p1 = new tr.model.Process(model, 1);
     78     p1.name = 'Renderer';
     79     p1.sortIndex = 1;
     80 
     81     var p2 = new tr.model.Process(model, 2);
     82     p2.name = 'Renderer';
     83 
     84     assert.isAbove(p1.compareTo(p2), 0);
     85   });
     86 
     87   test('compareOnName', function() {
     88     var model = new tr.Model();
     89     var p1 = new tr.model.Process(model, 1);
     90     p1.name = 'Browser';
     91 
     92     var p2 = new tr.model.Process(model, 2);
     93     p2.name = 'Renderer';
     94 
     95     assert.isBelow(p1.compareTo(p2), 0);
     96   });
     97 
     98   test('compareOnLabels', function() {
     99     var model = new tr.Model();
    100     var p1 = new tr.model.Process(model, 1);
    101     p1.name = 'Renderer';
    102     p1.labels = ['a'];
    103 
    104     var p2 = new tr.model.Process(model, 2);
    105     p2.name = 'Renderer';
    106     p2.labels = ['b'];
    107 
    108     assert.isBelow(p1.compareTo(p2), 0);
    109   });
    110 });
    111 </script>
    112 
    113