Home | History | Annotate | Download | only in tracing
      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 i18n-values="dir:textdirection;">
      9 <title>Timeline tests</title>
     10 <link rel="stylesheet" href="overlay.css">
     11 <link rel="stylesheet" href="timeline_view.css">
     12 <link rel="stylesheet" href="timeline.css">
     13 <link rel="stylesheet" href="../shared/css/tabs.css">
     14 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
     15 <script src="../shared/js/cr.js"></script>
     16 <script src="../shared/js/cr/event_target.js"></script>
     17 <script src="../shared/js/cr/ui.js"></script>
     18 <script src="../shared/js/cr/ui/tabs.js"></script>
     19 <script src="overlay.js"></script>
     20 <script src="measuring_stick.js"></script>
     21 <script src="profiling_view.js"></script>
     22 <script src="timeline_view.js"></script>
     23 <script src="timeline_model.js"></script>
     24 <script src="linux_perf_importer.js"></script>
     25 <script src="trace_event_importer.js"></script>
     26 <script src="timeline.js"></script>
     27 <script src="timeline_track.js"></script>
     28 <script src="sorted_array_utils.js"></script>
     29 <script src="fast_rect_renderer.js"></script>
     30 <script src="test_utils.js"></script>
     31 <script>
     32   goog.require('goog.testing.jsunit');
     33 </script>
     34 <style>
     35 </style>
     36 </head>
     37 <body>
     38   <script>
     39     'use strict';
     40 
     41     /*
     42      * This test just instantiates a TimelineView and adds it to the DOM
     43      * to help with non-unittest UI work.
     44      */
     45     function testInstantiateTimeline() {
     46       var events = [
     47         {name: 'a', args: {}, pid: 52, ts: 520, cat: 'foo', tid: 53, ph: 'B'},
     48         {name: 'a', args: {}, pid: 52, ts: 560, cat: 'foo', tid: 53, ph: 'E'},
     49         {name: 'b', args: {}, pid: 52, ts: 629, cat: 'foo', tid: 53, ph: 'B'},
     50         {name: 'b', args: {}, pid: 52, ts: 631, cat: 'foo', tid: 53, ph: 'E'}
     51       ];
     52       var model = new tracing.TimelineModel();
     53       model.importEvents(events);
     54       var timeline = new tracing.Timeline();
     55       timeline.model = model;
     56       timeline.focusElement = timeline;
     57       timeline.tabIndex = 0;
     58       document.body.appendChild(timeline);
     59     }
     60 
     61     function testAddAllObjectsMatchingFilterToSelection() {
     62       var model = new tracing.TimelineModel();
     63       var p1 = model.getOrCreateProcess(1);
     64       var t1 = p1.getOrCreateThread(1);
     65 
     66       t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3));
     67       t1.subRows[0].push(new tracing.TimelineThreadSlice('b', 0, 1, {}, 3));
     68 
     69       var t1asg = t1.asyncSlices;
     70       t1asg.slices.push(test_utils.newAsyncSliceNamed('a', 0, 1, t1, t1));
     71       t1asg.slices.push(test_utils.newAsyncSliceNamed('b', 1, 2, t1, t1));
     72 
     73 
     74       var timeline = new tracing.Timeline();
     75       timeline.model = model;
     76 
     77       var expected = [{slice: t1asg.slices[0].subSlices[0]},
     78                       {slice: t1.subRows[0][0]}];
     79       var result = new tracing.TimelineSelection();
     80       timeline.addAllObjectsMatchingFilterToSelection(new tracing.TimelineFilter('a'), result);
     81       assertEquals(2, result.length);
     82       assertEquals(expected[0].slice, result[0].slice);
     83       assertEquals(expected[1].slice, result[1].slice);
     84 
     85       var expected = [{slice: t1asg.slices[1].subSlices[0]},
     86                       {slice: t1.subRows[0][1]}];
     87       var result = new tracing.TimelineSelection();
     88       timeline.addAllObjectsMatchingFilterToSelection(new tracing.TimelineFilter('b'), result);
     89       assertEquals(2, result.length);
     90       assertEquals(expected[0].slice, result[0].slice);
     91       assertEquals(expected[1].slice, result[1].slice);
     92     }
     93 
     94     function testSelectionObject() {
     95       var model = new tracing.TimelineModel();
     96       var p1 = model.getOrCreateProcess(1);
     97       var t1 = p1.getOrCreateThread(1);
     98       t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3));
     99       t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 5, {}, 1));
    100 
    101       var sel = new tracing.TimelineSelection();
    102       sel.addSlice({}, t1.subRows[0][0]);
    103 
    104       assertEquals(1, sel.range.min);
    105       assertEquals(4, sel.range.max);
    106       assertEquals(t1.subRows[0][0], sel[0].slice);
    107 
    108       sel.addSlice({}, t1.subRows[0][1]);
    109       assertEquals(1, sel.range.min);
    110       assertEquals(6, sel.range.max);
    111       assertEquals(t1.subRows[0][1], sel[1].slice);
    112 
    113       sel.clear();
    114       assertEquals(0, sel.length);
    115     }
    116 
    117     function testShiftedSelection() {
    118       var model = new tracing.TimelineModel();
    119       var p1 = model.getOrCreateProcess(1);
    120       var t1 = p1.getOrCreateThread(1);
    121       t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 1, {}, 3));
    122       t1.subRows[0].push(new tracing.TimelineThreadSlice('a', 0, 5, {}, 1));
    123 
    124       var track = new tracing.TimelineSliceTrack();
    125       track.slices = t1.subRows[0];
    126 
    127       var sel = new tracing.TimelineSelection();
    128       sel.addSlice(track, t1.subRows[0][0]);
    129 
    130       var shifted = sel.getShiftedSelection(1);
    131       assertEquals(1, shifted.length);
    132       assertEquals(t1.subRows[0][1], shifted[0].slice);
    133     }
    134 
    135   </script>
    136 </body>
    137 </html>
    138