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

Side by Side Diff: chrome/browser/ui/webui/net_internals_ui_browsertest.cc

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 #include "base/command_line.h"
6 #include "base/file_path.h"
7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/webui/web_ui_browsertest.h"
10 #include "chrome/common/chrome_switches.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "googleurl/src/gurl.h"
14 #include "net/base/net_errors.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16
17 namespace {
18
19 const string16 kPassTitle = ASCIIToUTF16("Test Passed");
20 const string16 kFailTitle = ASCIIToUTF16("Test Failed");
21
22 // Each test involves calls a single Javascript function and then waits for the
23 // title to be changed to "Test Passed" or "Test Failed" when done.
24 class NetInternalsTest : public WebUIBrowserTest {
25 public:
26 NetInternalsTest();
27 virtual ~NetInternalsTest();
28
29 // InProcessBrowserTest overrides.
30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
31 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
32 virtual void SetUpOnMainThread() OVERRIDE;
33
eroman 2011/08/03 00:32:24 nit: can you remove this blank line?
mmenke 2011/08/03 15:44:17 Done
34
35 // Runs the specified Javascript test function with the specified arguments
36 // and waits for the title to change to "Test Passed" or "Test Failed".
37 void RunTestAndWaitForTitle(const std::string& function_name,
38 const ListValue& function_arguments);
39
40 // Same as above, with constant number of arguments for easy use. Will also
41 // free arguments.
42 void RunTestAndWaitForTitle(const std::string& function_name);
43 void RunTestAndWaitForTitle(const std::string& function_name, Value* arg);
44 void RunTestAndWaitForTitle(const std::string& function_name,
45 Value* arg1, Value* arg2);
46 void RunTestAndWaitForTitle(const std::string& function_name,
47 Value* arg1, Value* arg2, Value* arg3);
48
49 void set_expected_title_(string16 value) { expected_title_ = value; }
eroman 2011/08/03 00:32:24 nit: |const string16&|
mmenke 2011/08/03 15:44:17 Done.
50
51 private:
52 // The expected title at the end of the test. Defaults to kPassTitle.
53 string16 expected_title_;
eroman 2011/08/03 00:32:24 nit: DISABLE_COPY_AN_ASSIGN(NetInternalsTest);
mmenke 2011/08/03 15:44:17 Done.
54 };
55
56 NetInternalsTest::NetInternalsTest() : expected_title_(kPassTitle) {
eroman 2011/08/03 00:32:24 I believe the constructor is run once for each of
mmenke 2011/08/03 00:53:22 The constructor is indeed called once for each *_T
57 }
58
59 NetInternalsTest::~NetInternalsTest() {
60 }
61
62 void NetInternalsTest::SetUpCommandLine(CommandLine* command_line) {
63 WebUIBrowserTest::SetUpCommandLine(command_line);
64 // Needed to test the prerender view.
65 command_line->AppendSwitchASCII(switches::kPrerender,
66 switches::kPrerenderSwitchValueEnabled);
67 }
68
69 void NetInternalsTest::SetUpInProcessBrowserTestFixture() {
70 WebUIBrowserTest::SetUpInProcessBrowserTestFixture();
71
72 // Add Javascript files needed for the tests. Must be added after
73 // WebUIBrowserTest adds its files.
74 AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/framework.js")));
75
76 AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/log_view_painter.js")));
77 AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/prerender_view.js")));
78 AddLibrary(FilePath(FILE_PATH_LITERAL("net_internals/test_view.js")));
79 }
80
81 void NetInternalsTest::SetUpOnMainThread() {
82 // Navigate to the net-internals page.
83 ui_test_utils::NavigateToURL(browser(),
84 GURL(chrome::kChromeUINetInternalsURL));
85 }
86
87 void NetInternalsTest::RunTestAndWaitForTitle(
88 const std::string& function_name,
89 const ListValue& function_arguments) {
90 ui_test_utils::TitleWatcher title_watcher(browser()->GetTabContentsAt(0),
91 kPassTitle);
92 title_watcher.AddTitle(kFailTitle);
93
94 ConstValueVector arguments;
95 StringValue function_name_arg(function_name);
96 arguments.push_back(&function_name_arg);
97 arguments.push_back(&function_arguments);
98
99 ASSERT_TRUE(RunJavascriptFunction("runNetInternalsTest", arguments));
100 ASSERT_EQ(expected_title_, title_watcher.Wait());
101 }
102
103 void NetInternalsTest::RunTestAndWaitForTitle(
104 const std::string& function_name) {
105 ListValue test_arguments;
106 RunTestAndWaitForTitle(function_name, test_arguments);
107 }
108
109 void NetInternalsTest::RunTestAndWaitForTitle(const std::string& function_name,
110 Value* arg) {
111 ListValue test_arguments;
112 test_arguments.Append(arg);
113 RunTestAndWaitForTitle(function_name, test_arguments);
114 }
115
116 void NetInternalsTest::RunTestAndWaitForTitle(const std::string& function_name,
117 Value* arg1, Value* arg2) {
118 ListValue test_arguments;
119 test_arguments.Append(arg1);
120 test_arguments.Append(arg2);
121 RunTestAndWaitForTitle(function_name, test_arguments);
122 }
123
124 void NetInternalsTest::RunTestAndWaitForTitle(const std::string& function_name,
125 Value* arg1, Value* arg2,
126 Value* arg3) {
127 ListValue test_arguments;
128 test_arguments.Append(arg1);
129 test_arguments.Append(arg2);
130 test_arguments.Append(arg3);
131 RunTestAndWaitForTitle(function_name, test_arguments);
132 }
133
134 ////////////////////////////////////////////////////////////////////////////////
135 // framework.js
136 ////////////////////////////////////////////////////////////////////////////////
137
138 // Checks testDone.
139 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsDone) {
140 RunTestAndWaitForTitle("NetInternalsDone");
141 }
142
143 // Checks a failed expect statement.
144 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsExpectFail) {
145 set_expected_title_(kFailTitle);
146 RunTestAndWaitForTitle("NetInternalsExpectFail");
147 }
148
149 // Checks a failed assert statement.
150 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsAssertFail) {
151 set_expected_title_(kFailTitle);
152 RunTestAndWaitForTitle("NetInternalsAssertFail");
153 }
154
155 // Checks that testDone works when called by an observer in response to an
156 // event.
157 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsObserverDone) {
158 RunTestAndWaitForTitle("NetInternalsObserverDone");
159 }
160
161 // Checks that a failed expect works when called by an observer in response
162 // to an event.
163 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsObserverExpectFail) {
164 set_expected_title_(kFailTitle);
165 RunTestAndWaitForTitle("NetInternalsObserverExpectFail");
166 }
167
168 // Checks that a failed assertion works when called by an observer in response
169 // to an event.
170 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsObserverAssertFail) {
171 set_expected_title_(kFailTitle);
172 RunTestAndWaitForTitle("NetInternalsObserverAssertFail");
173 }
174
175 ////////////////////////////////////////////////////////////////////////////////
176 // test_view.js
177 ////////////////////////////////////////////////////////////////////////////////
178
179 // Runs the test suite twice, expecting a passing result the first time. Checks
180 // the firstresult, the order of events that occur, and the number of rows in
eroman 2011/08/03 00:32:24 nit: firstresult --> first result.
mmenke 2011/08/03 15:44:17 Done.
181 // the table.
182 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsTestViewPassTwice) {
183 ASSERT_TRUE(test_server()->Start());
184 RunTestAndWaitForTitle(
185 "NetInternalsTestView",
186 // URL that results in success.
187 Value::CreateStringValue(
188 test_server()->GetURL("files/title1.html").spec()),
189 // Resulting error code.
190 Value::CreateIntegerValue(net::OK),
191 // Number of times to run the test.
192 Value::CreateIntegerValue(2));
193 }
194
195 // Runs the test suite twice, expecting a failing result the first time. Checks
196 // the first result, the order of events that occur, and the number of rows in
197 // the table.
198 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsTestViewFailTwice) {
199 RunTestAndWaitForTitle(
200 "NetInternalsTestView",
201 // URL that results in an error, due to the port.
202 Value::CreateStringValue("http://127.0.0.1:7/"),
203 // Resulting error code.
204 Value::CreateIntegerValue(net::ERR_UNSAFE_PORT),
205 // Number of times to run the test.
206 Value::CreateIntegerValue(2));
207 }
208
209 ////////////////////////////////////////////////////////////////////////////////
210 // prerender_view.js
211 ////////////////////////////////////////////////////////////////////////////////
212
213 // Prerender two pages and check PrerenderView behavior. The first is expected
214 // to fail, the second is expected to succeed.
215 IN_PROC_BROWSER_TEST_F(NetInternalsTest, NetInternalsPrerenderView) {
216 ASSERT_TRUE(test_server()->Start());
217 RunTestAndWaitForTitle(
218 "NetInternalsPrerenderView",
219 // URL that can't be prerendered, since it triggers a download.
220 Value::CreateStringValue(
221 test_server()->GetURL("files/download-test1.lib").spec()),
222 // URL that can be prerendered.
223 Value::CreateStringValue(
224 test_server()->GetURL("files/title1.html").spec()));
225 }
226
227 ////////////////////////////////////////////////////////////////////////////////
228 // log_view_painter.js
229 ////////////////////////////////////////////////////////////////////////////////
230
231 // Check that we correctly remove cookies and login information.
232 IN_PROC_BROWSER_TEST_F(NetInternalsTest,
233 NetInternalsLogViewPainterStripInfo) {
234 RunTestAndWaitForTitle("NetInternalsLogViewPainterStripInfo");
235 }
236
237 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698