summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/net_internals/testview.js
blob: 4ca3b1768569be2d35f8871e1f8707dacc82a518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright (c) 2010 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.

/**
 * This view displays the progress and results from the "connection tester".
 *
 *   - Has an input box to specify the URL.
 *   - Has a button to start running the tests.
 *   - Shows the set of experiments that have been run so far, and their
 *     result.
 *
 *  @constructor
 */
function TestView(mainBoxId, urlInputId, formId, summaryDivId) {
  DivView.call(this, mainBoxId);

  this.urlInput_ = document.getElementById(urlInputId);
  this.summaryDiv_ = document.getElementById(summaryDivId);

  var form = document.getElementById(formId);
  form.addEventListener('submit', this.onSubmitForm_.bind(this), false);

  g_browser.addConnectionTestsObserver(this);
}

inherits(TestView, DivView);

TestView.prototype.onSubmitForm_ = function(event) {
  g_browser.sendStartConnectionTests(this.urlInput_.value);
  event.preventDefault();
};

/**
 * Callback for when the connection tests have begun.
 */
TestView.prototype.onStartedConnectionTestSuite = function() {
  this.summaryDiv_.innerHTML = '';

  var p = addNode(this.summaryDiv_, 'p');
  addTextNode(p, 'Started connection test suite suite on ' +
                 (new Date()).toLocaleString());

  // Add a table that will hold the individual test results.
  var table = addNode(this.summaryDiv_, 'table');
  table.className = 'styledTable';
  var thead = addNode(table, 'thead');
  thead.innerHTML = '<tr><th>Result</th><th>Experiment</th>' +
                    '<th>Error</th><th>Time (ms)</th></tr>';

  this.tbody_ = addNode(table, 'tbody');
};

/**
 * Callback for when an individual test in the suite has begun.
 */
TestView.prototype.onStartedConnectionTestExperiment = function(experiment) {
  var tr = addNode(this.tbody_, 'tr');

  var passFailCell = addNode(tr, 'td');

  var experimentCell = addNode(tr, 'td');

  var resultCell = addNode(tr, 'td');
  addTextNode(resultCell, '?');

  var dtCell = addNode(tr, 'td');
  addTextNode(dtCell, '?');

  // We will fill in result cells with actual values (to replace the
  // placeholder '?') once the test has completed. For now we just
  // save references to these cells.
  this.currentExperimentRow_ = {
    experimentCell: experimentCell,
    dtCell: dtCell,
    resultCell: resultCell,
    passFailCell: passFailCell,
    startTime: (new Date()).getTime()
  };

  addTextNode(experimentCell, 'Fetch ' + experiment.url);

  if (experiment.proxy_settings_experiment ||
      experiment.host_resolver_experiment) {
    var ul = addNode(experimentCell, 'ul');

    if (experiment.proxy_settings_experiment) {
      var li = addNode(ul, 'li');
      addTextNode(li, experiment.proxy_settings_experiment);
    }

    if (experiment.host_resolver_experiment) {
      var li = addNode(ul, 'li');
      addTextNode(li, experiment.host_resolver_experiment);
    }
  }
};

/**
 * Callback for when an individual test in the suite has finished.
 */
TestView.prototype.onCompletedConnectionTestExperiment = function(
    experiment, result) {
  var r = this.currentExperimentRow_;

  var endTime = (new Date()).getTime();

  r.dtCell.innerHTML = '';
  addTextNode(r.dtCell, (endTime - r.startTime));

  r.resultCell.innerHTML = '';

  if (result == 0) {
    r.passFailCell.style.color = 'green';
    addTextNode(r.passFailCell, 'PASS');
  } else {
    // TODO(eroman): stringize the error code.
    addTextNode(r.resultCell, result);
    r.passFailCell.style.color = 'red';
    addTextNode(r.passFailCell, 'FAIL');
  }

  this.currentExperimentRow_ = null;
};

/**
 * Callback for when the last test in the suite has finished.
 */
TestView.prototype.onCompletedConnectionTestSuite = function() {
  var p = addNode(this.summaryDiv_, 'p');
  addTextNode(p, 'Completed connection test suite suite');
};