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.
5 // Include test fixture.
6 GEN_INCLUDE(['net_internals_test.js']);
12 * Navigates to the test tab, runs the test suite once, using a URL
13 * either passed to the constructor or passed in from the previous task, and
14 * expects to see |expectedResult| from the first experiment. If
15 * |expectedResult| indicates failure, all experiments are expected to fail.
16 * Otherwise, results of all experiments but the first are ignored.
17 * Checks the order of events and several fields of the events received.
19 * Note that it is not safe for one RunTestSuiteTasks to run right after
20 * another. Otherwise, the second Task would receive the final observer
21 * message from the first task.
23 * @param {int} expectedResult Expected result of first test.
24 * @param {string} url URL to test. If null, will use parameter passed to
26 * @extends {NetInternalsTest.Task}
29 function RunTestSuiteTask(expectedResult
, url
) {
30 NetInternalsTest
.Task
.call(this);
31 // Complete asynchronously, so two RunTestSuiteTask can be run in a row.
32 this.setCompleteAsync(true);
35 this.expectedResult_
= expectedResult
;
36 this.seenStartSuite_
= false;
37 this.seenStartExperiment_
= false;
38 this.experimentsRun_
= 0;
41 RunTestSuiteTask
.prototype = {
42 __proto__
: NetInternalsTest
.Task
.prototype,
45 * Switches to the test view, and simulates entering |url| and submitting the
46 * form. Also adds the task as a ConnectionTestObserver.
47 * @param {string} url URL to run the test suite on.
49 start: function(url
) {
50 NetInternalsTest
.switchToView('tests');
51 if (this.url_
=== null) {
52 assertEquals('string', typeof(url
));
56 g_browser
.addConnectionTestsObserver(this);
58 $(TestView
.URL_INPUT_ID
).value
= this.url_
;
59 $(TestView
.SUBMIT_BUTTON_ID
).click();
63 * Checks that the table was created/cleared, and that no experiment is
66 onStartedConnectionTestSuite: function() {
69 expectFalse(this.seenStartSuite_
, 'Suite started more than once.');
70 checkTestTableRows(0);
71 expectEquals(this.experimentsRun_
, 0);
72 expectFalse(this.seenStartSuite_
);
74 this.seenStartSuite_
= true;
78 * Checks that the table has one row per started experiment, and the events
79 * occur in the proper order.
80 * @param {object} experiment Experiment that was just started.
82 onStartedConnectionTestExperiment: function(experiment
) {
85 console
.log('Experiment: ' + this.experimentsRun_
);
86 expectEquals(this.url_
, experiment
.url
, 'Test run on wrong URL');
87 expectTrue(this.seenStartSuite_
, 'Experiment started before suite.');
88 expectFalse(this.seenStartExperiment_
,
89 'Two experiments running at once.');
90 checkTestTableRows(this.experimentsRun_
+ 1);
92 this.seenStartExperiment_
= true;
96 * Checks that the table has one row per started experiment, and the events
97 * occur in the proper order.
98 * @param {object} experiment Experiment that finished.
99 * @param {number} result Code indicating success or reason for failure.
101 onCompletedConnectionTestExperiment: function(experiment
, result
) {
104 expectEquals(this.url_
, experiment
.url
, 'Test run on wrong URL');
105 // Can only rely on the error code of the first test.
106 if (this.experimentsRun_
== 0)
107 expectEquals(this.expectedResult_
, result
);
108 // If the first expected result is an error, all tests should return some
110 if (this.expectedResult_
< 0)
113 expectTrue(this.seenStartExperiment_
,
114 'Experiment stopped without starting.');
115 checkTestTableRows(this.experimentsRun_
+ 1);
117 this.seenStartExperiment_
= false;
118 ++this.experimentsRun_
;
122 * Checks that we've received all 12 sets of results, and either runs the
123 * next test iteration, or ends the test, depending on the total number of
126 onCompletedConnectionTestSuite: function() {
129 expectTrue(this.seenStartSuite_
, 'Suite stopped without being started.');
130 expectFalse(this.seenStartExperiment_
,
131 'Suite stopped while experiment was still running.');
132 expectEquals(12, this.experimentsRun_
,
133 'Incorrect number of experiments run.');
134 checkTestTableRows(this.experimentsRun_
);
141 * Checks that there are |expected| rows in the test table.
142 * @param {number} expectedRows Expected number of rows in the table.
144 function checkTestTableRows(expectedRows
) {
145 NetInternalsTest
.checkTbodyRows(TestView
.SUMMARY_DIV_ID
, expectedRows
);
149 * Runs the test suite twice, expecting a passing result the first time. Checks
150 * the first result, the order of events that occur, and the number of rows in
151 * the table. Uses the TestServer.
153 TEST_F('NetInternalsTest', 'netInternalsTestViewPassTwice', function() {
154 var taskQueue
= new NetInternalsTest
.TaskQueue(true);
156 new NetInternalsTest
.GetTestServerURLTask('files/title1.html'));
157 // 0 indicates success, the null means we'll use the URL resulting from the
159 taskQueue
.addTask(new RunTestSuiteTask(0, null));
162 new NetInternalsTest
.GetTestServerURLTask('files/title2.html'));
163 // 0 indicates success, the null means we'll use the URL resulting from the
165 taskQueue
.addTask(new RunTestSuiteTask(0, null));
170 * Runs the test suite twice. Checks the exact error code of the first result,
171 * the order of events that occur, and the number of rows in the HTML table.
172 * Does not use the TestServer.
174 TEST_F('NetInternalsTest', 'netInternalsTestViewFailTwice', function() {
175 var taskQueue
= new NetInternalsTest
.TaskQueue(true);
176 taskQueue
.addTask(new RunTestSuiteTask(NetError
.ERR_UNSAFE_PORT
,
177 'http://127.0.0.1:7/'));
178 taskQueue
.addTask(new RunTestSuiteTask(NetError
.ERR_UNSAFE_PORT
,
179 'http://127.0.0.1:7/'));
183 })(); // Anonymous namespace