OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/test/ui/ppapi_uitest.h" | 5 #include "chrome/test/ui/ppapi_uitest.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } | 153 } |
154 | 154 |
155 void PPAPITestBase::RunTestAndReload(const std::string& test_case) { | 155 void PPAPITestBase::RunTestAndReload(const std::string& test_case) { |
156 GURL url = GetTestFileUrl(test_case); | 156 GURL url = GetTestFileUrl(test_case); |
157 RunTestURL(url); | 157 RunTestURL(url); |
158 // If that passed, we simply run the test again, which navigates again. | 158 // If that passed, we simply run the test again, which navigates again. |
159 RunTestURL(url); | 159 RunTestURL(url); |
160 } | 160 } |
161 | 161 |
162 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { | 162 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { |
163 FilePath document_root; | 163 // For HTTP tests, we use the output DIR to grab the generated files such |
164 ASSERT_TRUE(GetHTTPDocumentRoot(&document_root)); | 164 // as the NEXEs. |
165 RunHTTPTestServer(document_root, test_case, ""); | 165 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); |
166 } | 166 FilePath src_dir; |
| 167 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)); |
167 | 168 |
168 void PPAPITestBase::RunTestWithSSLServer(const std::string& test_case) { | 169 // TestServer expects a path relative to source. So we must first |
169 FilePath document_root; | 170 // generate absolute paths to SRC and EXE and from there generate |
170 ASSERT_TRUE(GetHTTPDocumentRoot(&document_root)); | 171 // a relative path. |
171 net::TestServer test_server(net::BaseTestServer::HTTPSOptions(), | 172 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); |
172 document_root); | 173 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); |
| 174 ASSERT_TRUE(exe_dir.IsAbsolute()); |
| 175 ASSERT_TRUE(src_dir.IsAbsolute()); |
| 176 |
| 177 size_t match, exe_size, src_size; |
| 178 std::vector<FilePath::StringType> src_parts, exe_parts; |
| 179 |
| 180 // Determine point at which src and exe diverge, and create a relative path. |
| 181 exe_dir.GetComponents(&exe_parts); |
| 182 src_dir.GetComponents(&src_parts); |
| 183 exe_size = exe_parts.size(); |
| 184 src_size = src_parts.size(); |
| 185 for (match = 0; match < exe_size && match < src_size; ++match) { |
| 186 if (exe_parts[match] != src_parts[match]) |
| 187 break; |
| 188 } |
| 189 FilePath web_dir; |
| 190 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { |
| 191 web_dir = web_dir.Append(FILE_PATH_LITERAL("..")); |
| 192 } |
| 193 for (; match < exe_size; ++match) { |
| 194 web_dir = web_dir.Append(exe_parts[match]); |
| 195 } |
| 196 |
| 197 net::TestServer test_server(net::TestServer::TYPE_HTTP, |
| 198 net::TestServer::kLocalhost, |
| 199 web_dir); |
173 ASSERT_TRUE(test_server.Start()); | 200 ASSERT_TRUE(test_server.Start()); |
174 uint16_t port = test_server.host_port_pair().port(); | 201 std::string query = BuildQuery("files/test_case.html?", test_case); |
175 RunHTTPTestServer(document_root, test_case, | 202 |
176 StringPrintf("ssl_server_port=%d", port)); | 203 GURL url = test_server.GetURL(query); |
| 204 RunTestURL(url); |
177 } | 205 } |
178 | 206 |
179 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { | 207 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { |
180 FilePath websocket_root_dir; | 208 FilePath websocket_root_dir; |
181 ASSERT_TRUE( | 209 ASSERT_TRUE( |
182 PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_root_dir)); | 210 PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_root_dir)); |
| 211 |
183 ui_test_utils::TestWebSocketServer server; | 212 ui_test_utils::TestWebSocketServer server; |
184 int port = server.UseRandomPort(); | 213 int port = server.UseRandomPort(); |
185 ASSERT_TRUE(server.Start(websocket_root_dir)); | 214 ASSERT_TRUE(server.Start(websocket_root_dir)); |
186 FilePath http_document_root; | 215 std::string url = StringPrintf("%s&websocket_port=%d", |
187 ASSERT_TRUE(GetHTTPDocumentRoot(&http_document_root)); | 216 test_case.c_str(), port); |
188 RunHTTPTestServer(http_document_root, test_case, | 217 RunTestViaHTTP(url); |
189 StringPrintf("websocket_port=%d", port)); | |
190 } | 218 } |
191 | 219 |
192 std::string PPAPITestBase::StripPrefixes(const std::string& test_name) { | 220 std::string PPAPITestBase::StripPrefixes(const std::string& test_name) { |
193 const char* const prefixes[] = { | 221 const char* const prefixes[] = { |
194 "FAILS_", "FLAKY_", "DISABLED_", "SLOW_" }; | 222 "FAILS_", "FLAKY_", "DISABLED_", "SLOW_" }; |
195 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) | 223 for (size_t i = 0; i < sizeof(prefixes)/sizeof(prefixes[0]); ++i) |
196 if (test_name.find(prefixes[i]) == 0) | 224 if (test_name.find(prefixes[i]) == 0) |
197 return test_name.substr(strlen(prefixes[i])); | 225 return test_name.substr(strlen(prefixes[i])); |
198 return test_name; | 226 return test_name; |
199 } | 227 } |
200 | 228 |
201 void PPAPITestBase::RunTestURL(const GURL& test_url) { | 229 void PPAPITestBase::RunTestURL(const GURL& test_url) { |
202 // See comment above TestingInstance in ppapi/test/testing_instance.h. | 230 // See comment above TestingInstance in ppapi/test/testing_instance.h. |
203 // Basically it sends messages using the DOM automation controller. The | 231 // Basically it sends messages using the DOM automation controller. The |
204 // value of "..." means it's still working and we should continue to wait, | 232 // value of "..." means it's still working and we should continue to wait, |
205 // any other value indicates completion (in this case it will start with | 233 // any other value indicates completion (in this case it will start with |
206 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. | 234 // "PASS" or "FAIL"). This keeps us from timing out on waits for long tests. |
207 TestFinishObserver observer( | 235 TestFinishObserver observer( |
208 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); | 236 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); |
209 | 237 |
210 ui_test_utils::NavigateToURL(browser(), test_url); | 238 ui_test_utils::NavigateToURL(browser(), test_url); |
211 | 239 |
212 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; | 240 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; |
213 | 241 |
214 EXPECT_STREQ("PASS", observer.result().c_str()); | 242 EXPECT_STREQ("PASS", observer.result().c_str()); |
215 } | 243 } |
216 | 244 |
217 void PPAPITestBase::RunHTTPTestServer( | |
218 const FilePath& document_root, | |
219 const std::string& test_case, | |
220 const std::string& extra_params) { | |
221 net::TestServer test_server(net::TestServer::TYPE_HTTP, | |
222 net::TestServer::kLocalhost, | |
223 document_root); | |
224 ASSERT_TRUE(test_server.Start()); | |
225 std::string query = BuildQuery("files/test_case.html?", test_case); | |
226 if (!extra_params.empty()) | |
227 query = StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); | |
228 | |
229 GURL url = test_server.GetURL(query); | |
230 RunTestURL(url); | |
231 } | |
232 | |
233 bool PPAPITestBase::GetHTTPDocumentRoot(FilePath* document_root) { | |
234 // For HTTP tests, we use the output DIR to grab the generated files such | |
235 // as the NEXEs. | |
236 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); | |
237 FilePath src_dir; | |
238 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) | |
239 return false; | |
240 | |
241 // TestServer expects a path relative to source. So we must first | |
242 // generate absolute paths to SRC and EXE and from there generate | |
243 // a relative path. | |
244 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); | |
245 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); | |
246 if (!exe_dir.IsAbsolute()) | |
247 return false; | |
248 if (!src_dir.IsAbsolute()) | |
249 return false; | |
250 | |
251 size_t match, exe_size, src_size; | |
252 std::vector<FilePath::StringType> src_parts, exe_parts; | |
253 | |
254 // Determine point at which src and exe diverge, and create a relative path. | |
255 exe_dir.GetComponents(&exe_parts); | |
256 src_dir.GetComponents(&src_parts); | |
257 exe_size = exe_parts.size(); | |
258 src_size = src_parts.size(); | |
259 for (match = 0; match < exe_size && match < src_size; ++match) { | |
260 if (exe_parts[match] != src_parts[match]) | |
261 break; | |
262 } | |
263 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { | |
264 *document_root = document_root->Append(FILE_PATH_LITERAL("..")); | |
265 } | |
266 for (; match < exe_size; ++match) { | |
267 *document_root = document_root->Append(exe_parts[match]); | |
268 } | |
269 return true; | |
270 } | |
271 | |
272 PPAPITest::PPAPITest() { | 245 PPAPITest::PPAPITest() { |
273 } | 246 } |
274 | 247 |
275 void PPAPITest::SetUpCommandLine(CommandLine* command_line) { | 248 void PPAPITest::SetUpCommandLine(CommandLine* command_line) { |
276 PPAPITestBase::SetUpCommandLine(command_line); | 249 PPAPITestBase::SetUpCommandLine(command_line); |
277 | 250 |
278 // Append the switch to register the pepper plugin. | 251 // Append the switch to register the pepper plugin. |
279 // library name = <out dir>/<test_name>.<library_extension> | 252 // library name = <out dir>/<test_name>.<library_extension> |
280 // MIME type = application/x-ppapi-<test_name> | 253 // MIME type = application/x-ppapi-<test_name> |
281 FilePath plugin_dir; | 254 FilePath plugin_dir; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // Similar macros that test over HTTP. | 340 // Similar macros that test over HTTP. |
368 #define TEST_PPAPI_IN_PROCESS_VIA_HTTP(test_name) \ | 341 #define TEST_PPAPI_IN_PROCESS_VIA_HTTP(test_name) \ |
369 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ | 342 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ |
370 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ | 343 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ |
371 } | 344 } |
372 #define TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(test_name) \ | 345 #define TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(test_name) \ |
373 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ | 346 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ |
374 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ | 347 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ |
375 } | 348 } |
376 | 349 |
377 // Similar macros that test with an SSL server. | |
378 #define TEST_PPAPI_IN_PROCESS_WITH_SSL_SERVER(test_name) \ | |
379 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ | |
380 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \ | |
381 } | |
382 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(test_name) \ | |
383 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ | |
384 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \ | |
385 } | |
386 | |
387 // Similar macros that test with WebSocket server | 350 // Similar macros that test with WebSocket server |
388 #define TEST_PPAPI_IN_PROCESS_WITH_WS(test_name) \ | 351 #define TEST_PPAPI_IN_PROCESS_WITH_WS(test_name) \ |
389 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ | 352 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ |
390 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ | 353 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ |
391 } | 354 } |
392 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_WS(test_name) \ | 355 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_WS(test_name) \ |
393 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ | 356 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ |
394 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ | 357 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ |
395 } | 358 } |
396 | 359 |
397 | 360 |
398 #if defined(DISABLE_NACL) | 361 #if defined(DISABLE_NACL) |
399 #define TEST_PPAPI_NACL_VIA_HTTP(test_name) | 362 #define TEST_PPAPI_NACL_VIA_HTTP(test_name) |
400 #define TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(test_name) | 363 #define TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(test_name) |
401 #define TEST_PPAPI_NACL_VIA_HTTP_WITH_WS(test_name) | 364 #define TEST_PPAPI_NACL_VIA_HTTP_WITH_WS(test_name) |
402 #else | 365 #else |
403 | 366 |
404 // NaCl based PPAPI tests | 367 // NaCl based PPAPI tests |
405 #define TEST_PPAPI_NACL_VIA_HTTP(test_name) \ | 368 #define TEST_PPAPI_NACL_VIA_HTTP(test_name) \ |
406 IN_PROC_BROWSER_TEST_F(PPAPINaClTest, test_name) { \ | 369 IN_PROC_BROWSER_TEST_F(PPAPINaClTest, test_name) { \ |
407 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ | 370 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ |
408 } | 371 } |
409 | 372 |
410 // NaCl based PPAPI tests with disallowed socket API | 373 // NaCl based PPAPI tests with disallowed socket API |
411 #define TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(test_name) \ | 374 #define TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(test_name) \ |
412 IN_PROC_BROWSER_TEST_F(PPAPINaClTestDisallowedSockets, test_name) { \ | 375 IN_PROC_BROWSER_TEST_F(PPAPINaClTestDisallowedSockets, test_name) { \ |
413 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ | 376 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ |
414 } | 377 } |
415 | 378 |
416 // NaCl based PPAPI tests with SSL server | |
417 #define TEST_PPAPI_NACL_VIA_HTTP_WITH_SSL_SERVER(test_name) \ | |
418 IN_PROC_BROWSER_TEST_F(PPAPINaClTest, test_name) { \ | |
419 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \ | |
420 } | |
421 | |
422 // NaCl based PPAPI tests with WebSocket server | 379 // NaCl based PPAPI tests with WebSocket server |
423 #define TEST_PPAPI_NACL_VIA_HTTP_WITH_WS(test_name) \ | 380 #define TEST_PPAPI_NACL_VIA_HTTP_WITH_WS(test_name) \ |
424 IN_PROC_BROWSER_TEST_F(PPAPINaClTest, test_name) { \ | 381 IN_PROC_BROWSER_TEST_F(PPAPINaClTest, test_name) { \ |
425 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ | 382 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ |
426 } | 383 } |
427 #endif | 384 #endif |
428 | 385 |
429 | 386 |
430 // | 387 // |
431 // Interface tests. | 388 // Interface tests. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 TEST_PPAPI_IN_PROCESS(ImageData) | 453 TEST_PPAPI_IN_PROCESS(ImageData) |
497 TEST_PPAPI_OUT_OF_PROCESS(ImageData) | 454 TEST_PPAPI_OUT_OF_PROCESS(ImageData) |
498 TEST_PPAPI_NACL_VIA_HTTP(ImageData) | 455 TEST_PPAPI_NACL_VIA_HTTP(ImageData) |
499 | 456 |
500 TEST_PPAPI_IN_PROCESS(BrowserFont) | 457 TEST_PPAPI_IN_PROCESS(BrowserFont) |
501 TEST_PPAPI_OUT_OF_PROCESS(BrowserFont) | 458 TEST_PPAPI_OUT_OF_PROCESS(BrowserFont) |
502 | 459 |
503 TEST_PPAPI_IN_PROCESS(Buffer) | 460 TEST_PPAPI_IN_PROCESS(Buffer) |
504 TEST_PPAPI_OUT_OF_PROCESS(Buffer) | 461 TEST_PPAPI_OUT_OF_PROCESS(Buffer) |
505 | 462 |
506 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate) | 463 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(TCPSocketPrivate) |
507 TEST_PPAPI_IN_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate) | 464 TEST_PPAPI_IN_PROCESS_VIA_HTTP(TCPSocketPrivate) |
508 TEST_PPAPI_NACL_VIA_HTTP_WITH_SSL_SERVER(TCPSocketPrivate) | 465 TEST_PPAPI_NACL_VIA_HTTP(TCPSocketPrivate) |
509 | 466 |
510 TEST_PPAPI_IN_PROCESS_VIA_HTTP(UDPSocketPrivate) | 467 TEST_PPAPI_IN_PROCESS_VIA_HTTP(UDPSocketPrivate) |
511 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(UDPSocketPrivate) | 468 TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(UDPSocketPrivate) |
512 TEST_PPAPI_NACL_VIA_HTTP(UDPSocketPrivate) | 469 TEST_PPAPI_NACL_VIA_HTTP(UDPSocketPrivate) |
513 | 470 |
514 TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(TCPServerSocketPrivateDisallowed) | 471 TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(TCPServerSocketPrivateDisallowed) |
515 TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(TCPSocketPrivateDisallowed) | 472 TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(TCPSocketPrivateDisallowed) |
516 TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(UDPSocketPrivateDisallowed) | 473 TEST_PPAPI_NACL_VIA_HTTP_DISALLOWED_SOCKETS(UDPSocketPrivateDisallowed) |
517 | 474 |
518 TEST_PPAPI_IN_PROCESS_VIA_HTTP(TCPServerSocketPrivate) | 475 TEST_PPAPI_IN_PROCESS_VIA_HTTP(TCPServerSocketPrivate) |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) | 974 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) |
1018 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) | 975 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) |
1019 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) | 976 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) |
1020 | 977 |
1021 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics) | 978 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics) |
1022 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit) | 979 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit) |
1023 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics) | 980 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics) |
1024 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit) | 981 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit) |
1025 | 982 |
1026 #endif // ADDRESS_SANITIZER | 983 #endif // ADDRESS_SANITIZER |
OLD | NEW |