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