• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7base.require('tracing.timeline_viewport');
8base.require('tracing.test_utils');
9base.require('tracing.trace_model');
10base.require('tracing.selection');
11base.require('tracing.tracks.slice_track');
12
13base.unittest.testSuite('tracing.selection', function() {
14  test('selectionObject', function() {
15    var model = new tracing.TraceModel();
16    var p1 = model.getOrCreateProcess(1);
17    var t1 = p1.getOrCreateThread(1);
18    t1.sliceGroup.pushSlice(
19        new tracing.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
20    t1.sliceGroup.pushSlice(
21        new tracing.trace_model.ThreadSlice('', 'a', 0, 5, {}, 1));
22
23    var sel = new tracing.Selection();
24    sel.addSlice({}, t1.sliceGroup.slices[0]);
25
26    assertEquals(1, sel.bounds.min);
27    assertEquals(4, sel.bounds.max);
28    assertEquals(t1.sliceGroup.slices[0], sel[0].slice);
29
30    sel.addSlice({}, t1.sliceGroup.slices[1]);
31    assertEquals(1, sel.bounds.min);
32    assertEquals(6, sel.bounds.max);
33    assertEquals(t1.sliceGroup.slices[1], sel[1].slice);
34
35    sel.clear();
36    assertEquals(0, sel.length);
37  });
38
39  test('shiftedSelection', function() {
40    var model = new tracing.TraceModel();
41    var p1 = model.getOrCreateProcess(1);
42    var t1 = p1.getOrCreateThread(1);
43    t1.sliceGroup.pushSlice(
44        new tracing.trace_model.ThreadSlice('', 'a', 0, 1, {}, 3));
45    t1.sliceGroup.pushSlice(
46        new tracing.trace_model.ThreadSlice('', 'a', 0, 5, {}, 1));
47
48    var track = new tracing.tracks.SliceTrack(new tracing.TimelineViewport());
49    track.slices = t1.sliceGroup.slices;
50
51    var sel = new tracing.Selection();
52    sel.addSlice(track, t1.sliceGroup.slices[0]);
53
54    var shifted = sel.getShiftedSelection(1);
55    assertEquals(1, shifted.length);
56    assertEquals(t1.sliceGroup.slices[1], shifted[0].slice);
57  });
58});
59