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

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: Just test result of first test 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('NetInternalsTestView',
11 function(url, expectedResult, totalIterations) {
12 // IDs for special HTML elements in test_view.html
13 const URL_INPUT_ID = 'test-view-url-input';
14 const SUBMIT_BUTTON_ID = 'test-view-connection-tests-submit';
15 const SUMMARY_DIV_ID = 'test-view-summary';
16
17 function TestObserver(url, expectedResult, totalIterations) {
18 this.url_ = url;
19 this.totalIterations_ = totalIterations;
20 this.expectedResult_ = expectedResult;
21 this.completedIterations_ = 0;
22 };
eroman 2011/08/03 00:32:24 nit: remove for consistency
mmenke 2011/08/03 15:44:17 Done.
23
24 TestObserver.prototype = {
25 /**
26 * Starts running the test suite.
27 */
28 startTestSuite: function() {
29 // Initialize state used to track test suite progress.
30 this.seenStartSuite_ = false;
31 this.seenStartExperiment_ = false;
32 this.experimentsRun_ = 0;
33
34 // Simulate entering the url and submitting the form.
35 $(URL_INPUT_ID).value = this.url_;
36 $(SUBMIT_BUTTON_ID).click();
37 },
38
39 /**
40 * Checks that the table was created/cleared, and that no experiment is
41 * currently running.
42 */
43 onStartedConnectionTestSuite: function() {
44 expectFalse(this.seenStartSuite_, 'Suite started more than once.');
45 checkTestTableRows(0);
46 expectEquals(this.experimentsRun_, 0);
47 expectFalse(this.seenStartExperiment_, 0);
48
49 this.seenStartSuite_ = true;
50 },
51
52 /**
53 * Checks that the table has one row per started experiment, and the events
54 * occur in the proper order.
55 */
56 onStartedConnectionTestExperiment: function(experiment) {
57 console.log('Experiment: ' + this.experimentsRun_);
58 expectEquals(this.url_, experiment.url, 'Test run on wrong URL');
59 expectTrue(this.seenStartSuite_, 'Experiment started before suite.');
60 expectFalse(this.seenStartExperiment_,
61 'Two experiments running at once.');
62 checkTestTableRows(this.experimentsRun_ + 1);
63
64 this.seenStartExperiment_ = true;
65 },
66
67 /**
68 * Checks that the table has one row per started experiment, and the events
69 * occur in the proper order.
70 */
71 onCompletedConnectionTestExperiment: function(experiment, result) {
72 expectEquals(this.url_, experiment.url, 'Test run on wrong URL');
73 // Can only rely on the error code of the first test.
74 if (this.experimentsRun_ == 0)
75 expectEquals(this.expectedResult_, result);
76 // If the first expected result is an error, all tests should return some
77 // error.
78 if (this.expectedResult_ < 0)
79 expectLT(result, 0);
80
81 expectTrue(this.seenStartExperiment_,
82 'Experiment stopped without starting.');
83 checkTestTableRows(this.experimentsRun_ + 1);
84
85 this.seenStartExperiment_ = false;
86 ++this.experimentsRun_;
87 },
88
89 /**
90 * Checks that we've received all 12 sets of results, and either runs the
91 * next test iteration, or ends the test, depending on the total number of
92 * iterations.
93 */
94 onCompletedConnectionTestSuite: function() {
95 expectTrue(this.seenStartSuite_, 'Suite stopped without being started.');
96 expectFalse(this.seenStartExperiment_,
97 'Suite stopped while experiment was still running.');
98 expectEquals(12, this.experimentsRun_,
99 'Incorrect number of experiments run.');
100 checkTestTableRows(this.experimentsRun_);
101
102 ++this.completedIterations_;
103 if (this.completedIterations_ < this.totalIterations_) {
104 this.startTestSuite();
105 } else {
106 testDone();
107 }
108 }
109 };
110
111 /**
112 * Checks that there are |expected| rows in the test table.
113 */
114 function checkTestTableRows(expected) {
115 checkStyledTableRows(SUMMARY_DIV_ID, expected);
116 }
117
118 switchToView('tests');
119
120 // Create observer and start the test.
121 var testObserver = new TestObserver(url, expectedResult, totalIterations);
122 g_browser.addConnectionTestsObserver(testObserver);
123 testObserver.startTestSuite();
124 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698