Home | History | Annotate | Download | only in tracks
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('tracing.test_utils');
      8 base.require('tracing.timeline_track_view');
      9 base.require('tracing.tracks.thread_track');
     10 base.require('ui.dom_helpers');
     11 
     12 base.unittest.testSuite('tracing.tracks.thread_track', function() {
     13   var Process = tracing.trace_model.Process;
     14   var Selection = tracing.Selection;
     15   var Thread = tracing.trace_model.Thread;
     16   var ThreadSlice = tracing.trace_model.ThreadSlice;
     17   var ThreadTrack = tracing.tracks.ThreadTrack;
     18   var Viewport = tracing.TimelineViewport;
     19   var newAsyncSlice = tracing.test_utils.newAsyncSlice;
     20   var newAsyncSliceNamed = tracing.test_utils.newAsyncSliceNamed;
     21   var newSliceNamed = tracing.test_utils.newSliceNamed;
     22 
     23   test('selectionHitTestingWithThreadTrack', function() {
     24     var model = new tracing.TraceModel();
     25     var p1 = model.getOrCreateProcess(1);
     26     var t1 = p1.getOrCreateThread(1);
     27     t1.sliceGroup.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 4));
     28     t1.sliceGroup.pushSlice(new ThreadSlice('', 'b', 0, 5.1, {}, 4));
     29 
     30     var testEl = document.createElement('div');
     31     testEl.appendChild(ui.createScopedStyle('heading { width: 100px; }'));
     32     testEl.style.width = '600px';
     33 
     34     var viewport = new Viewport(testEl);
     35     var drawingContainer = new tracing.tracks.DrawingContainer(viewport);
     36     testEl.appendChild(drawingContainer);
     37 
     38     var track = new ThreadTrack(viewport);
     39     drawingContainer.appendChild(track);
     40     drawingContainer.updateCanvasSizeIfNeeded_();
     41     track.thread = t1;
     42 
     43     var y = track.getBoundingClientRect().top;
     44     var h = track.getBoundingClientRect().height;
     45     var wW = 10;
     46     var vW = drawingContainer.canvas.getBoundingClientRect().width;
     47     track.viewport.xSetWorldBounds(0, wW, vW);
     48 
     49     var selection = new Selection();
     50     var x = (1.5 / wW) * vW;
     51     track.addIntersectingItemsInRangeToSelection(x, x + 1, y, y + 1, selection);
     52     assertEquals(t1.sliceGroup.slices[0], selection[0].slice);
     53 
     54     var selection = new Selection();
     55     track.addIntersectingItemsInRangeToSelection(
     56         (1.5 / wW) * vW, (1.8 / wW) * vW,
     57         y, y + h, selection);
     58     assertEquals(t1.sliceGroup.slices[0], selection[0].slice);
     59   });
     60 
     61   test('filterThreadSlices', function() {
     62     var model = new tracing.TraceModel();
     63     var thread = new Thread(new Process(model, 7), 1);
     64     thread.sliceGroup.pushSlice(newSliceNamed('a', 0, 0));
     65     thread.asyncSliceGroup.push(newAsyncSliceNamed('a', 0, 5, t, t));
     66 
     67     var t = new ThreadTrack(new tracing.TimelineViewport());
     68     t.thread = thread;
     69 
     70     assertEquals(t.tracks_.length, 2);
     71     assertTrue(t.tracks_[0] instanceof tracing.tracks.AsyncSliceGroupTrack);
     72     assertTrue(t.tracks_[1] instanceof tracing.tracks.SliceGroupTrack);
     73 
     74     t.categoryFilter = new tracing.TitleFilter('x');
     75     assertEquals(0, t.tracks_.length);
     76 
     77     t.categoryFilter = new tracing.TitleFilter('a');
     78     assertTrue(t.tracks_[0] instanceof tracing.tracks.AsyncSliceGroupTrack);
     79     assertTrue(t.tracks_[1] instanceof tracing.tracks.SliceGroupTrack);
     80   });
     81 
     82   test('sampleThreadSlices', function() {
     83     var model = new tracing.TraceModel();
     84     var thread = new Thread(new Process(model, 7), 1);
     85     thread.addSample('a', 'b', 0);
     86     thread.addSample('a', 'c', 5);
     87     thread.addSample('aa', 'd', 10);
     88     thread.addSample('aa', 'e', 15);
     89     var t = new ThreadTrack(new tracing.TimelineViewport());
     90     t.thread = thread;
     91     assertEquals(1, t.tracks_.length);
     92     assertTrue(t.tracks_[0] instanceof tracing.tracks.SliceTrack);
     93     assertTrue(4, t.tracks_[0].slices.length);
     94   });
     95 });
     96