Html程序  |  156行  |  4.33 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>All Tracing Tests</title>
<script>
  tests = [
    'unittest_test.html',
    'overlay_test.html',
    'timeline_async_slice_group_test.html',
    'timeline_find_control_test.html',
    'timeline_slice_group_test.html',
    'timeline_stream_importer_test.html',
    'timeline_thread_test.html',
    'timeline_process_test.html',
    'timeline_category_filter_dialog_test.html',
    'timeline_counter_test.html',
    'timeline_cpu_test.html',
    'timeline_filter_test.html',
    'timeline_model_test.html',
    'linux_perf_importer_test.html',
    'linux_perf_android_parser_test.html',
    'linux_perf_bus_parser_test.html',
    'linux_perf_clock_parser_test.html',
    'linux_perf_cpufreq_parser_test.html',
    'linux_perf_drm_parser_test.html',
    'linux_perf_exynos_parser_test.html',
    'linux_perf_gesture_parser_test.html',
    'linux_perf_i915_parser_test.html',
    'linux_perf_mali_parser_test.html',
    'linux_perf_power_parser_test.html',
    'linux_perf_sched_parser_test.html',
    'linux_perf_workqueue_parser_test.html',
    'trace_event_importer_test.html',
    'profiling_view_test.html',
    'timeline_selection_test.html',
    'timeline_test.html',
    'timeline_view_test.html',
    'timeline_viewport_test.html',
    'timeline_analysis_test.html',
    'ui_test.html',
    'settings_test.html',
    'tracks/timeline_async_slice_group_track_test.html',
    'tracks/timeline_cpu_track_test.html',
    'tracks/timeline_counter_track_test.html',
    'tracks/timeline_slice_group_track_test.html',
    'tracks/timeline_slice_track_test.html',
    'tracks/timeline_thread_track_test.html',
    'tracks/timeline_viewport_track_test.html',
  ];
</script>
<style>
  h1 {
      font-family: sans-serif;
      font-size: 18pt;
  }
</style>
<script src="base.js"></script>
<script>
  base.require('unittest');
</script>
</head>
<body>
  <h1>Trace-Viewer Tests</h3>

  <div class="unittest">Interactive tests: <a href="interactive_tests.html" class="unittest-error-link">Run manually</a></div>
  <br>

  <script>
  function runTest(runner, testCaseEl, test) {
    testCaseEl.status = 'RUNNING'

    var iframe = document.createElement('iframe');
    iframe.src = test;
    iframe.style.position = 'fixed';
    iframe.style.visibility = 'hidden';
    document.body.appendChild(iframe);
    iframe.contentWindow.addEventListener('error', function(msg, url, lineNumber) {
      if (iframe.contentWindow.G_testRunner)
        return false;

      if (iframe.contentWindow.errorsCaughtByTestHarness)
        return false;

      iframe.contentWindow.errorsCaughtByTestHarness = [
          {msg: msg, url: url, lineNumber: lineNumber}];
      return false;
    });

    function checkForDone() {
      if (!iframe.contentWindow) {
        setTimeout(checkForDone, 100);
        return;
      }

      if (iframe.contentWindow.errorsCaughtByTestHarness &&
        iframe.contentWindow.errorsCaughtByTestHarness.length) {
        testCaseEl.status = 'FAILED'
        return;
      }

      if (!iframe.contentWindow.G_testRunner) {
        setTimeout(checkForDone, 100);
        return;
      }

      var runner = iframe.contentWindow.G_testRunner;
      if (!runner.done) {
        setTimeout(checkForDone, 100);
        return;
      }

      var stats = runner.computeResultStats();
      if (stats.numTestsRun && !stats.numTestsWithErrors)
        testCaseEl.status = 'PASSED'
      else
        testCaseEl.status = 'FAILED'
    }
    setTimeout(checkForDone, 0);
  }

  function run() {
    var resultsEl = document.createElement('div');
    resultsEl.className = 'unittest';
    document.body.appendChild(resultsEl);

    var numPassed = 0;
    var numFailures = 0;
    var runner = {
      addFailedTest: function() {
        numFailures++;
      },
      addPassedTest: function() {
        numPassed++;
      }
    };
    function begin() {
      for (var i = 0; i < tests.length; i++) {
        (function() {
          var testCaseEl = unittest.createTestCaseDiv_(tests[i], tests[i], true);
          resultsEl.appendChild(testCaseEl);
          runTest(runner, testCaseEl, tests[i]);
        })();
      }
    }
    begin();
  }
  document.addEventListener('DOMContentLoaded', run);
  </script>
</body>
</html>