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