166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis// Copyright (c) 2013 The Chromium Authors. All rights reserved. 266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis// Use of this source code is governed by a BSD-style license that can be 366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis// found in the LICENSE file. 466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis'use strict'; 666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennisbase.require('tracing.test_utils'); 866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennisbase.require('tracing.timeline_track_view'); 966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennisbase.require('tracing.tracks.thread_track'); 1066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennisbase.require('ui.dom_helpers'); 1166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 1266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennisbase.unittest.testSuite('tracing.tracks.thread_track', function() { 1366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var Process = tracing.trace_model.Process; 1466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var Selection = tracing.Selection; 1566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var Thread = tracing.trace_model.Thread; 1666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var ThreadSlice = tracing.trace_model.ThreadSlice; 1766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var ThreadTrack = tracing.tracks.ThreadTrack; 1866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var Viewport = tracing.TimelineViewport; 1966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var newAsyncSlice = tracing.test_utils.newAsyncSlice; 2066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var newAsyncSliceNamed = tracing.test_utils.newAsyncSliceNamed; 2166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var newSliceNamed = tracing.test_utils.newSliceNamed; 2266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 2366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis test('selectionHitTestingWithThreadTrack', function() { 2466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var model = new tracing.TraceModel(); 2566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var p1 = model.getOrCreateProcess(1); 2666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var t1 = p1.getOrCreateThread(1); 2766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis t1.sliceGroup.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 4)); 2866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis t1.sliceGroup.pushSlice(new ThreadSlice('', 'b', 0, 5.1, {}, 4)); 2966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 3066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var testEl = document.createElement('div'); 3166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis testEl.appendChild(ui.createScopedStyle('heading { width: 100px; }')); 3266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis testEl.style.width = '600px'; 3366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 3466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var viewport = new Viewport(testEl); 3566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var drawingContainer = new tracing.tracks.DrawingContainer(viewport); 3666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis testEl.appendChild(drawingContainer); 3766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 3866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var track = new ThreadTrack(viewport); 3966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis drawingContainer.appendChild(track); 4066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis drawingContainer.updateCanvasSizeIfNeeded_(); 4166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis track.thread = t1; 4266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 4366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var y = track.getBoundingClientRect().top; 4466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var h = track.getBoundingClientRect().height; 4566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var wW = 10; 4666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var vW = drawingContainer.canvas.getBoundingClientRect().width; 4766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis track.viewport.xSetWorldBounds(0, wW, vW); 4866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 4966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var selection = new Selection(); 5066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var x = (1.5 / wW) * vW; 5166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis track.addIntersectingItemsInRangeToSelection(x, x + 1, y, y + 1, selection); 5266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertEquals(t1.sliceGroup.slices[0], selection[0].slice); 5366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 5466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var selection = new Selection(); 5566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis track.addIntersectingItemsInRangeToSelection( 5666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis (1.5 / wW) * vW, (1.8 / wW) * vW, 5766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis y, y + h, selection); 5866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertEquals(t1.sliceGroup.slices[0], selection[0].slice); 5966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis }); 6066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 6166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis test('filterThreadSlices', function() { 6266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var model = new tracing.TraceModel(); 6366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var thread = new Thread(new Process(model, 7), 1); 6466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis thread.sliceGroup.pushSlice(newSliceNamed('a', 0, 0)); 6566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis thread.asyncSliceGroup.push(newAsyncSliceNamed('a', 0, 5, t, t)); 6666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 6766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var t = new ThreadTrack(new tracing.TimelineViewport()); 6866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis t.thread = thread; 6966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 7066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertEquals(t.tracks_.length, 2); 7166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertTrue(t.tracks_[0] instanceof tracing.tracks.AsyncSliceGroupTrack); 7266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertTrue(t.tracks_[1] instanceof tracing.tracks.SliceGroupTrack); 7366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 7466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis t.categoryFilter = new tracing.TitleFilter('x'); 7566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertEquals(0, t.tracks_.length); 7666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 7766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis t.categoryFilter = new tracing.TitleFilter('a'); 7866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertTrue(t.tracks_[0] instanceof tracing.tracks.AsyncSliceGroupTrack); 7966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertTrue(t.tracks_[1] instanceof tracing.tracks.SliceGroupTrack); 8066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis }); 8166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis 8266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis test('sampleThreadSlices', function() { 8366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var model = new tracing.TraceModel(); 8466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var thread = new Thread(new Process(model, 7), 1); 8566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis thread.addSample('a', 'b', 0); 8666a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis thread.addSample('a', 'c', 5); 8766a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis thread.addSample('aa', 'd', 10); 8866a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis thread.addSample('aa', 'e', 15); 8966a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis var t = new ThreadTrack(new tracing.TimelineViewport()); 9066a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis t.thread = thread; 9166a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertEquals(1, t.tracks_.length); 9266a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertTrue(t.tracks_[0] instanceof tracing.tracks.SliceTrack); 9366a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis assertTrue(4, t.tracks_[0].slices.length); 9466a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis }); 9566a37686207944273ced825e0e8b6b6375f8c3deJamie Gennis}); 96