Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: chrome/test/data/webui/net_internals/test_view.js

Issue 7553009: Add some browser tests for net-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix comments Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 /**
6 * Navigates to the test tab, runs the test suite |totalIterations| times, using
7 * |url|, and expects to see |expectedResult| from each iteration. Checks the
8 * order and several fields of the events received.
9 */
10 netInternalsTest.test('NetInternalsTestView',
11 function(url, expectedResult, totalIterations) {
12 // IDs for special HTML elements in test_view.html
13 var URL_INPUT_ID = 'test-view-url-input';
14 var SUBMIT_BUTTON_ID = 'test-view-connection-tests-submit';
15 var SUMMARY_DIV_ID = 'test-view-summary';
16
17 /**
18 * @param {string} url URL to run the test suite on.
19 * @param {number} expectedResult Expected result of the first test.
20 * @param {number} totalIterations Number of times to run the test suite.
21 * @constructor
22 */
23 function TestObserver(url, expectedResult, totalIterations) {
24 this.url_ = url;
25 this.totalIterations_ = totalIterations;
26 this.expectedResult_ = expectedResult;
27 this.completedIterations_ = 0;
28 }
29
30 TestObserver.prototype = {
31 /**
32 * Starts running the test suite.
33 */
34 startTestSuite: function() {
35 // Initialize state used to track test suite progress.
36 this.seenStartSuite_ = false;
37 this.seenStartExperiment_ = false;
38 this.experimentsRun_ = 0;
39
40 // Simulate entering the url and submitting the form.
41 $(URL_INPUT_ID).value = this.url_;
42 $(SUBMIT_BUTTON_ID).click();
43 },
44
45 /**
46 * Checks that the table was created/cleared, and that no experiment is
47 * currently running.
48 */
49 onStartedConnectionTestSuite: function() {
50 expectFalse(this.seenStartSuite_, 'Suite started more than once.');
51 checkTestTableRows(0);
52 expectEquals(this.experimentsRun_, 0);
53 expectFalse(this.seenStartExperiment_, 0);
54
55 this.seenStartSuite_ = true;
56 },
57
58 /**
59 * Checks that the table has one row per started experiment, and the events
60 * occur in the proper order.
61 * @param {Object} experiment Experiment that was just started.
62 */
63 onStartedConnectionTestExperiment: function(experiment) {
64 console.log('Experiment: ' + this.experimentsRun_);
65 expectEquals(this.url_, experiment.url, 'Test run on wrong URL');
66 expectTrue(this.seenStartSuite_, 'Experiment started before suite.');
67 expectFalse(this.seenStartExperiment_,
68 'Two experiments running at once.');
69 checkTestTableRows(this.experimentsRun_ + 1);
70
71 this.seenStartExperiment_ = true;
72 },
73
74 /**
75 * Checks that the table has one row per started experiment, and the events
76 * occur in the proper order.
77 * @param {Object} experiment Experiment that finished.
78 * @param {number} result Code indicating success or reason for failure.
79 */
80 onCompletedConnectionTestExperiment: function(experiment, result) {
81 expectEquals(this.url_, experiment.url, 'Test run on wrong URL');
82 // Can only rely on the error code of the first test.
83 if (this.experimentsRun_ == 0)
84 expectEquals(this.expectedResult_, result);
85 // If the first expected result is an error, all tests should return some
86 // error.
87 if (this.expectedResult_ < 0)
88 expectLT(result, 0);
89
90 expectTrue(this.seenStartExperiment_,
91 'Experiment stopped without starting.');
92 checkTestTableRows(this.experimentsRun_ + 1);
93
94 this.seenStartExperiment_ = false;
95 ++this.experimentsRun_;
96 },
97
98 /**
99 * Checks that we've received all 12 sets of results, and either runs the
100 * next test iteration, or ends the test, depending on the total number of
101 * iterations.
102 */
103 onCompletedConnectionTestSuite: function() {
104 expectTrue(this.seenStartSuite_, 'Suite stopped without being started.');
105 expectFalse(this.seenStartExperiment_,
106 'Suite stopped while experiment was still running.');
107 expectEquals(12, this.experimentsRun_,
108 'Incorrect number of experiments run.');
109 checkTestTableRows(this.experimentsRun_);
110
111 ++this.completedIterations_;
112 if (this.completedIterations_ < this.totalIterations_) {
113 this.startTestSuite();
114 } else {
115 netInternalsTest.testDone();
116 }
117 }
118 };
119
120 /**
121 * Checks that there are |expected| rows in the test table.
122 * @param {expectedRows} expectedRows Expected number of rows in the table.
Sheridan Rawlins 2011/08/03 22:21:16 s/{expectedRows}/{number}/
mmenke 2011/08/04 00:21:15 Done.
123 */
124 function checkTestTableRows(expectedRows) {
125 netInternalsTest.checkStyledTableRows(SUMMARY_DIV_ID, expectedRows);
126 }
127
128 netInternalsTest.switchToView('tests');
129
130 // Create observer and start the test.
131 var testObserver = new TestObserver(url, expectedResult, totalIterations);
132 g_browser.addConnectionTestsObserver(testObserver);
133 testObserver.startTestSuite();
134 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698