1 // Copyright (c) 2012 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.
6 * This view displays the progress and results from the "connection tester".
8 * - Has an input box to specify the URL.
9 * - Has a button to start running the tests.
10 * - Shows the set of experiments that have been run so far, and their
13 var TestView
= (function() {
16 // We inherit from DivView.
17 var superClass
= DivView
;
23 assertFirstConstructorCall(TestView
);
25 // Call superclass's constructor.
26 superClass
.call(this, TestView
.MAIN_BOX_ID
);
28 this.urlInput_
= $(TestView
.URL_INPUT_ID
);
29 this.summaryDiv_
= $(TestView
.SUMMARY_DIV_ID
);
31 var form
= $(TestView
.FORM_ID
);
32 form
.addEventListener('submit', this.onSubmitForm_
.bind(this), false);
34 // Register to test information as it's received.
35 g_browser
.addConnectionTestsObserver(this);
38 TestView
.TAB_ID
= 'tab-handle-tests';
39 TestView
.TAB_NAME
= 'Tests';
40 TestView
.TAB_HASH
= '#tests';
42 // IDs for special HTML elements in test_view.html
43 TestView
.MAIN_BOX_ID
= 'test-view-tab-content';
44 TestView
.FORM_ID
= 'test-view-connection-tests-form';
45 TestView
.URL_INPUT_ID
= 'test-view-url-input';
46 TestView
.SUMMARY_DIV_ID
= 'test-view-summary';
48 TestView
.SUBMIT_BUTTON_ID
= 'test-view-connection-tests-submit';
51 cr
.addSingletonGetter(TestView
);
53 TestView
.prototype = {
54 // Inherit the superclass's methods.
55 __proto__
: superClass
.prototype,
57 onSubmitForm_: function(event
) {
58 g_browser
.sendStartConnectionTests(this.urlInput_
.value
);
59 event
.preventDefault();
63 * Callback for when the connection tests have begun.
65 onStartedConnectionTestSuite: function() {
66 this.summaryDiv_
.innerHTML
= '';
68 var p
= addNode(this.summaryDiv_
, 'p');
69 addTextNode(p
, 'Started connection test suite suite on ');
70 timeutil
.addNodeWithDate(p
, new Date());
72 // Add a table that will hold the individual test results.
73 var table
= addNode(this.summaryDiv_
, 'table');
74 table
.className
= 'styled-table';
75 var thead
= addNode(table
, 'thead');
76 thead
.innerHTML
= '<tr><th>Result</th><th>Experiment</th>' +
77 '<th>Error</th><th>Time (ms)</th></tr>';
79 this.tbody_
= addNode(table
, 'tbody');
83 * Callback for when an individual test in the suite has begun.
85 onStartedConnectionTestExperiment: function(experiment
) {
86 var tr
= addNode(this.tbody_
, 'tr');
88 var passFailCell
= addNode(tr
, 'td');
90 var experimentCell
= addNode(tr
, 'td');
92 var resultCell
= addNode(tr
, 'td');
93 addTextNode(resultCell
, '?');
95 var dtCell
= addNode(tr
, 'td');
96 addTextNode(dtCell
, '?');
98 // We will fill in result cells with actual values (to replace the
99 // placeholder '?') once the test has completed. For now we just
100 // save references to these cells.
101 this.currentExperimentRow_
= {
102 experimentCell
: experimentCell
,
104 resultCell
: resultCell
,
105 passFailCell
: passFailCell
,
106 startTime
: timeutil
.getCurrentTime()
109 addTextNode(experimentCell
, 'Fetch ' + experiment
.url
);
111 if (experiment
.proxy_settings_experiment
||
112 experiment
.host_resolver_experiment
) {
113 var ul
= addNode(experimentCell
, 'ul');
115 if (experiment
.proxy_settings_experiment
) {
116 var li
= addNode(ul
, 'li');
117 addTextNode(li
, experiment
.proxy_settings_experiment
);
120 if (experiment
.host_resolver_experiment
) {
121 var li
= addNode(ul
, 'li');
122 addTextNode(li
, experiment
.host_resolver_experiment
);
128 * Callback for when an individual test in the suite has finished.
130 onCompletedConnectionTestExperiment: function(experiment
, result
) {
131 var r
= this.currentExperimentRow_
;
133 var endTime
= timeutil
.getCurrentTime();
135 r
.dtCell
.innerHTML
= '';
136 addTextNode(r
.dtCell
, (endTime
- r
.startTime
));
138 r
.resultCell
.innerHTML
= '';
141 r
.passFailCell
.style
.color
= 'green';
142 addTextNode(r
.passFailCell
, 'PASS');
144 addTextNode(r
.resultCell
,
145 netErrorToString(result
) + ' (' + result
+ ')');
146 r
.passFailCell
.style
.color
= '#e00';
147 addTextNode(r
.passFailCell
, 'FAIL');
150 this.currentExperimentRow_
= null;
154 * Callback for when the last test in the suite has finished.
156 onCompletedConnectionTestSuite: function() {
157 var p
= addNode(this.summaryDiv_
, 'p');
158 addTextNode(p
, 'Completed connection test suite suite');