Home | History | Annotate | Download | only in src
      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 Copyright (c) 2012 The Chromium Authors. All rights reserved.
      5 Use of this source code is governed by a BSD-style license that can be
      6 found in the LICENSE file.
      7 -->
      8 <head>
      9 <title>Timeline tests</title>
     10 <script src="base.js"></script>
     11 <script>
     12   base.require('unittest');
     13   base.require('test_utils');
     14   base.require('timeline');
     15   base.require('trace_event_importer');
     16 </script>
     17 </head>
     18 <body>
     19 <script>
     20     'use strict';
     21 
     22     /*
     23      * This test just instantiates a TimelineView and adds it to the DOM
     24      * to help with non-unittest UI work.
     25      */
     26     function testInstantiateTimeline() {
     27       var events = [
     28         {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
     29         {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'},
     30         {name: 'b', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'},
     31         {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}
     32       ];
     33       var model = new tracing.TimelineModel(events);
     34       var timeline = new tracing.Timeline();
     35       timeline.model = model;
     36       timeline.focusElement = timeline;
     37       timeline.tabIndex = 0;
     38       var outputEl = this.addHTMLOutput();
     39       outputEl.appendChild(timeline);
     40     }
     41 
     42     function testAddAllObjectsMatchingFilterToSelection() {
     43       var model = new tracing.TimelineModel();
     44       var p1 = model.getOrCreateProcess(1);
     45       var t1 = p1.getOrCreateThread(1);
     46 
     47       t1.pushSlice(new tracing.TimelineThreadSlice('', 'a', 0, 1, {}, 3));
     48       t1.pushSlice(new tracing.TimelineThreadSlice('', 'b', 0, 1.1, {}, 2.8));
     49 
     50       var t1asg = t1.asyncSlices;
     51       t1asg.slices.push(test_utils.newAsyncSliceNamed('a', 0, 1, t1, t1));
     52       t1asg.slices.push(test_utils.newAsyncSliceNamed('b', 1, 2, t1, t1));
     53 
     54       var timeline = new tracing.Timeline();
     55       timeline.model = model;
     56 
     57       var expected = [{slice: t1asg.slices[0].subSlices[0]},
     58                       {slice: t1.slices[0]}];
     59       var result = new tracing.TimelineSelection();
     60       timeline.addAllObjectsMatchingFilterToSelection(
     61           new tracing.TimelineTitleFilter('a'), result);
     62       assertEquals(2, result.length);
     63       assertEquals(expected[0].slice, result[0].slice);
     64       assertEquals(expected[1].slice, result[1].slice);
     65 
     66       var expected = [{slice: t1asg.slices[1].subSlices[0]},
     67                       {slice: t1.slices[1]}];
     68       var result = new tracing.TimelineSelection();
     69       timeline.addAllObjectsMatchingFilterToSelection(
     70           new tracing.TimelineTitleFilter('b'), result);
     71       assertEquals(2, result.length);
     72       assertEquals(expected[0].slice, result[0].slice);
     73       assertEquals(expected[1].slice, result[1].slice);
     74     }
     75 
     76     function testEmptyThreadsDeleted() {
     77       var model = new tracing.TimelineModel();
     78       var p1 = model.getOrCreateProcess(1);
     79       var t1 = p1.getOrCreateThread(1);
     80 
     81       var timeline = new tracing.Timeline();
     82       timeline.model = model;
     83 
     84       assertEquals(0, timeline.numVisibleTracks);
     85     }
     86 
     87     function NoCountersFilter() {
     88     }
     89     NoCountersFilter.prototype = {
     90       __proto__: tracing.TimelineFilter.prototype,
     91       matchCounter: function(c) {
     92         return false;
     93       }
     94     };
     95 
     96     function testFilteredCounters() {
     97       var model = new tracing.TimelineModel();
     98       var c1 = model.getOrCreateCpu(0);
     99       c1.getOrCreateCounter('', 'b');
    100       var p1 = model.getOrCreateProcess(1);
    101       p1.getOrCreateCounter('', 'a').samples = [1];
    102 
    103       var timeline = new tracing.Timeline();
    104       timeline.model = model;
    105 
    106       assertEquals(2, timeline.numVisibleTracks);
    107 
    108       timeline.categoryFilter = new NoCountersFilter();
    109       assertEquals(0, timeline.numVisibleTracks);
    110     }
    111 
    112     function NoCpusFilter() {}
    113     NoCpusFilter.prototype = {
    114       __proto__: tracing.TimelineFilter.prototype,
    115       matchCpu: function(c) {
    116         return false;
    117       }
    118     };
    119 
    120     function testFilteredCpus() {
    121       var model = new tracing.TimelineModel();
    122       var c1 = model.getOrCreateCpu(1);
    123       c1.getOrCreateCounter('', 'a');
    124 
    125       var timeline = new tracing.Timeline();
    126       timeline.model = model;
    127 
    128       assertEquals(1, timeline.numVisibleTracks);
    129 
    130       timeline.categoryFilter = new NoCpusFilter();
    131       assertEquals(0, timeline.numVisibleTracks);
    132     }
    133 
    134     function NoProcessesFilter() {
    135     }
    136     NoProcessesFilter.prototype = {
    137       __proto__: tracing.TimelineFilter.prototype,
    138       matchProcess: function(c) {
    139         return false;
    140       }
    141     };
    142 
    143     function testFilteredProcesses() {
    144       var model = new tracing.TimelineModel();
    145       var p1 = model.getOrCreateProcess(1);
    146       p1.getOrCreateCounter('', 'a');
    147 
    148       var timeline = new tracing.Timeline();
    149       timeline.model = model;
    150 
    151       assertEquals(1, timeline.numVisibleTracks);
    152 
    153       timeline.categoryFilter = new NoProcessesFilter();
    154       assertEquals(0, timeline.numVisibleTracks);
    155     }
    156 
    157     function NoThreadsFilter() {
    158     }
    159     NoThreadsFilter.prototype = {
    160       __proto__: tracing.TimelineFilter.prototype,
    161       matchThread: function(c) {
    162         return false;
    163       }
    164     };
    165 
    166     function testFilteredThreads() {
    167       var model = new tracing.TimelineModel();
    168       var p1 = model.getOrCreateProcess(1);
    169       var t1 = p1.getOrCreateThread(2);
    170       t1.pushSlice(test_utils.newSlice(0, 1));
    171 
    172       var timeline = new tracing.Timeline();
    173       timeline.model = model;
    174 
    175       assertEquals(1, timeline.numVisibleTracks);
    176 
    177       timeline.categoryFilter = new NoThreadsFilter();
    178       assertEquals(0, timeline.numVisibleTracks);
    179     }
    180 </script>
    181 </body>
    182 </html>
    183