Html程序  |  89行  |  2.99 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>
<title>Counter Selection Analysis Tests</title>
<script src="/src/base.js"></script>
</head>
<body>
  <script>
    base.require('unittest');
    base.require('analysis.counter_selection_analysis');
    base.require('analysis.test.analysis_test_support');
  </script>
  <script>
    'use strict';

    function testEmptySelection() {
      var selection = new tracing.Selection();
      var analysis = new tracing.analysis.CounterSelectionAnalysis();
      assertThrows(function() {
        analysis.selection = selection;
      });
    }

    function testCounterSelectionAnalysisWithSlice() {
      var data = tracing.analysis.test.createReferenceData(true);

      var selection = new tracing.Selection();
      data.t1track.selectByTitle('b', selection);

      var analysis = new tracing.analysis.CounterSelectionAnalysis();
      assertThrows(function() {
        analysis.selection = selection;
      });
    }

    function testCounterSelectionAnalysisWithOneCounter() {
      var data = tracing.analysis.test.createReferenceData(true);

      var selection = new tracing.Selection();
      selection.addCounterSample(data.ctr1track, data.ctr1track.counter, 0);

      var analysis = new tracing.analysis.CounterSelectionAnalysis();
      analysis.selection = selection;

      var counterSelectionEl = analysis;
      var singleCounterEl = counterSelectionEl.children[1];

      assertEquals(true, counterSelectionEl instanceof
          tracing.analysis.CounterSelectionAnalysis);
      assertEquals(true, singleCounterEl instanceof
          tracing.analysis.SingleCounterSelectionAnalysis);
      assertEquals(2, counterSelectionEl.children.length);
      assertEquals(1, singleCounterEl.children.length);
    }

    function testSelectionAnalysisWithTwoCounters() {
      var data = tracing.analysis.test.createReferenceData(true);

      var selection = new tracing.Selection();
      selection.addCounterSample(data.ctr1track, data.ctr1track.counter, 0);
      selection.addCounterSample(data.ctr2track, data.ctr2track.counter, 3);

      var analysis = new tracing.analysis.CounterSelectionAnalysis();
      analysis.selection = selection;

      var counterSelectionEl = analysis;
      var singleCounterEl = counterSelectionEl.children[1];
      var singleCounterEl2 = counterSelectionEl.children[2];

      assertEquals(true, counterSelectionEl instanceof
          tracing.analysis.CounterSelectionAnalysis);
      assertEquals(true, singleCounterEl instanceof
          tracing.analysis.SingleCounterSelectionAnalysis);
      assertEquals(true, singleCounterEl2 instanceof
          tracing.analysis.SingleCounterSelectionAnalysis);
      assertEquals(3, counterSelectionEl.children.length);
      assertEquals(1, singleCounterEl.children.length);
      assertEquals(1, singleCounterEl2.children.length);
    }

  </script>
</body>
</html>