Html程序  |  152行  |  4.71 KB

<!DOCTYPE HTML>
<html>
<!--
Copyright (c) 2012 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head i18n-values="dir:textdirection;">
<title>AsyncSliceGroupTrack tests</title>
<style>
.container {
  border: 1px solid red;
}
</style>
<script src="/src/base.js"></script>
<script>
  base.require('unittest');
  base.require('test_utils');
  base.require('timeline_track_view');
  base.require('model');
</script>
</head>
<body>
<script>
  'use strict';

  var AsyncSliceGroup = tracing.model.AsyncSliceGroup;
  var AsyncSliceGroupTrack =
      tracing.tracks.AsyncSliceGroupTrack;
  var Process = tracing.model.Process;
  var Thread = tracing.model.Thread;
  var newAsyncSlice = test_utils.newAsyncSlice;

  function testAsyncSliceGroup_filterSubRows() {
    var p1 = new Process(1);
    var t1 = new Thread(p1, 1);
    var g = new AsyncSliceGroup();
    g.slices.push(newAsyncSlice(0, 1, t1, t1));
    var track = new AsyncSliceGroupTrack();
    track.group = g;

    assertEquals(1, track.subRows_.length);
    assertTrue(track.visible);

    track.categoryFilter = new tracing.TitleFilter('x');
    assertFalse(track.visible);

    track.categoryFilter = new tracing.TitleFilter('a');
    assertTrue(track.visible);
    assertEquals(1, track.subRows_.length);
  }

  function testAsyncSliceGroup_rebuildSubRows_twoNonOverlappingSlices() {
    var p1 = new Process(1);
    var t1 = new Thread(p1, 1);
    var g = new AsyncSliceGroup();
    g.slices.push(newAsyncSlice(0, 1, t1, t1));
    g.slices.push(newAsyncSlice(1, 1, t1, t1));
    var track = new AsyncSliceGroupTrack();
    track.group = g;
    var subRows = track.subRows_;

    assertEquals(1, subRows.length);
    assertEquals(2, subRows[0].length);
    assertEquals(g.slices[0].subSlices[0], subRows[0][0]);
    assertEquals(g.slices[1].subSlices[0], subRows[0][1]);
  }

  function testAsyncSliceGroup_rebuildSubRows_twoOverlappingSlices() {
    var p1 = new Process(1);
    var t1 = new Thread(p1, 1);
    var g = new AsyncSliceGroup();
    g.slices.push(newAsyncSlice(0, 1, t1, t1));
    g.slices.push(newAsyncSlice(0, 1.5, t1, t1));
    g.updateBounds();
    var track = new AsyncSliceGroupTrack();
    track.group = g;
    var subRows = track.subRows_;

    assertEquals(2, subRows.length);
    assertEquals(1, subRows[0].length);
    assertEquals(g.slices[0], subRows[0][0]);
    assertEquals(1, subRows[1].length);
    assertEquals(g.slices[1], subRows[1][0]);
  }

  function testAsyncSliceGroup_rebuildSubRows_threePartlyOverlappingSlices() {
    var p1 = new Process(1);
    var t1 = new Thread(p1, 1);
    var g = new AsyncSliceGroup();
    g.slices.push(newAsyncSlice(0, 1, t1, t1));
    g.slices.push(newAsyncSlice(0, 1.5, t1, t1));
    g.slices.push(newAsyncSlice(1, 1.5, t1, t1));
    g.updateBounds();
    var track = new AsyncSliceGroupTrack();
    track.group = g;
    var subRows = track.subRows_;

    assertEquals(2, subRows.length);
    assertEquals(2, subRows[0].length);
    assertEquals(g.slices[0].subSlices[0], subRows[0][0]);
    assertEquals(g.slices[2].subSlices[0], subRows[0][1]);
    assertEquals(1, subRows[1].length);
    assertEquals(g.slices[1].subSlices[0], subRows[1][0]);
  }

  function testAsyncSliceGroup_rebuildSubRows_twoOverlappingSlices() {
    var p1 = new Process(1);
    var t1 = new Thread(p1, 1);
    var g = new AsyncSliceGroup();
    g.slices.push(newAsyncSlice(0, 1, t1, t1));
    g.slices.push(newAsyncSlice(0, 1.5, t1, t1));
    g.slices.push(newAsyncSlice(2, 1, t1, t1));
    g.updateBounds();
    var track = new AsyncSliceGroupTrack();
    track.group = g;
    var subRows = track.subRows_;

    assertEquals(2, subRows.length);
    assertEquals(2, subRows[0].length);
    assertEquals(g.slices[0].subSlices[0], subRows[0][0]);
    assertEquals(g.slices[2].subSlices[0], subRows[0][1]);
    assertEquals(1, subRows[1].length);
    assertEquals(g.slices[1].subSlices[0], subRows[1][0]);
  }

  function testAsyncSliceGroup_computeSubGroups_twoThreadSpecificSlices() {
    var p1 = new Process(1);
    var t1 = new Thread(p1, 1);
    var t2 = new Thread(p1, 2);
    var g = new AsyncSliceGroup();
    g.slices.push(newAsyncSlice(0, 1, t1, t1));
    g.slices.push(newAsyncSlice(0, 1, t2, t2));
    var track = new AsyncSliceGroupTrack();
    track.group = g;
    var subRows = track.subRows_;

    var subGroups = g.computeSubGroups();
    assertEquals(2, subGroups.length);

    assertEquals(g.name, subGroups[0].name);
    assertEquals(1, subGroups[0].slices.length);
    assertEquals(g.slices[0], subGroups[0].slices[0]);

    assertEquals(g.name, subGroups[1].name);
    assertEquals(1, subGroups[1].slices.length);
    assertEquals(g.slices[1], subGroups[1].slices[0]);
  }
</script>
</body>
</html>