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/ppapi/ppapi_test.h" | 5 #include "chrome/test/ppapi/ppapi_test.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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 159 |
160 void PPAPITestBase::RunTestAndReload(const std::string& test_case) { | 160 void PPAPITestBase::RunTestAndReload(const std::string& test_case) { |
161 GURL url = GetTestFileUrl(test_case); | 161 GURL url = GetTestFileUrl(test_case); |
162 RunTestURL(url); | 162 RunTestURL(url); |
163 // If that passed, we simply run the test again, which navigates again. | 163 // If that passed, we simply run the test again, which navigates again. |
164 RunTestURL(url); | 164 RunTestURL(url); |
165 } | 165 } |
166 | 166 |
167 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { | 167 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { |
168 FilePath document_root; | 168 FilePath document_root; |
169 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&document_root)); | 169 ASSERT_TRUE(GetHTTPDocumentRoot(&document_root)); |
170 RunHTTPTestServer(document_root, test_case, ""); | 170 RunHTTPTestServer(document_root, test_case, ""); |
171 } | 171 } |
172 | 172 |
173 void PPAPITestBase::RunTestWithSSLServer(const std::string& test_case) { | 173 void PPAPITestBase::RunTestWithSSLServer(const std::string& test_case) { |
174 FilePath document_root; | 174 FilePath document_root; |
175 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&document_root)); | 175 ASSERT_TRUE(GetHTTPDocumentRoot(&document_root)); |
176 net::TestServer test_server(net::BaseTestServer::HTTPSOptions(), | 176 net::TestServer test_server(net::BaseTestServer::HTTPSOptions(), |
177 document_root); | 177 document_root); |
178 ASSERT_TRUE(test_server.Start()); | 178 ASSERT_TRUE(test_server.Start()); |
179 uint16_t port = test_server.host_port_pair().port(); | 179 uint16_t port = test_server.host_port_pair().port(); |
180 RunHTTPTestServer(document_root, test_case, | 180 RunHTTPTestServer(document_root, test_case, |
181 StringPrintf("ssl_server_port=%d", port)); | 181 StringPrintf("ssl_server_port=%d", port)); |
182 } | 182 } |
183 | 183 |
184 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { | 184 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { |
185 FilePath websocket_root_dir; | 185 FilePath websocket_root_dir; |
186 ASSERT_TRUE( | 186 ASSERT_TRUE( |
187 PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_root_dir)); | 187 PathService::Get(content::DIR_LAYOUT_TESTS, &websocket_root_dir)); |
188 content::TestWebSocketServer server; | 188 content::TestWebSocketServer server; |
189 int port = server.UseRandomPort(); | 189 int port = server.UseRandomPort(); |
190 ASSERT_TRUE(server.Start(websocket_root_dir)); | 190 ASSERT_TRUE(server.Start(websocket_root_dir)); |
191 FilePath http_document_root; | 191 FilePath http_document_root; |
192 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&http_document_root)); | 192 ASSERT_TRUE(GetHTTPDocumentRoot(&http_document_root)); |
193 RunHTTPTestServer(http_document_root, test_case, | 193 RunHTTPTestServer(http_document_root, test_case, |
194 StringPrintf("websocket_port=%d", port)); | 194 StringPrintf("websocket_port=%d", port)); |
195 } | 195 } |
196 | 196 |
197 void PPAPITestBase::RunTestIfAudioOutputAvailable( | 197 void PPAPITestBase::RunTestIfAudioOutputAvailable( |
198 const std::string& test_case) { | 198 const std::string& test_case) { |
199 if (IsAudioOutputAvailable()) { | 199 if (IsAudioOutputAvailable()) { |
200 RunTest(test_case); | 200 RunTest(test_case); |
201 } else { | 201 } else { |
202 LOG(WARNING) << "PPAPITest: " << test_case << | 202 LOG(WARNING) << "PPAPITest: " << test_case << |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 document_root); | 249 document_root); |
250 ASSERT_TRUE(test_server.Start()); | 250 ASSERT_TRUE(test_server.Start()); |
251 std::string query = BuildQuery("files/test_case.html?", test_case); | 251 std::string query = BuildQuery("files/test_case.html?", test_case); |
252 if (!extra_params.empty()) | 252 if (!extra_params.empty()) |
253 query = StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); | 253 query = StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); |
254 | 254 |
255 GURL url = test_server.GetURL(query); | 255 GURL url = test_server.GetURL(query); |
256 RunTestURL(url); | 256 RunTestURL(url); |
257 } | 257 } |
258 | 258 |
| 259 bool PPAPITestBase::GetHTTPDocumentRoot(FilePath* document_root) { |
| 260 // For HTTP tests, we use the output DIR to grab the generated files such |
| 261 // as the NEXEs. |
| 262 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); |
| 263 FilePath src_dir; |
| 264 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
| 265 return false; |
| 266 |
| 267 // TestServer expects a path relative to source. So we must first |
| 268 // generate absolute paths to SRC and EXE and from there generate |
| 269 // a relative path. |
| 270 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir); |
| 271 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir); |
| 272 if (!exe_dir.IsAbsolute()) |
| 273 return false; |
| 274 if (!src_dir.IsAbsolute()) |
| 275 return false; |
| 276 |
| 277 size_t match, exe_size, src_size; |
| 278 std::vector<FilePath::StringType> src_parts, exe_parts; |
| 279 |
| 280 // Determine point at which src and exe diverge, and create a relative path. |
| 281 exe_dir.GetComponents(&exe_parts); |
| 282 src_dir.GetComponents(&src_parts); |
| 283 exe_size = exe_parts.size(); |
| 284 src_size = src_parts.size(); |
| 285 for (match = 0; match < exe_size && match < src_size; ++match) { |
| 286 if (exe_parts[match] != src_parts[match]) |
| 287 break; |
| 288 } |
| 289 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { |
| 290 *document_root = document_root->Append(FILE_PATH_LITERAL("..")); |
| 291 } |
| 292 for (; match < exe_size; ++match) { |
| 293 *document_root = document_root->Append(exe_parts[match]); |
| 294 } |
| 295 return true; |
| 296 } |
| 297 |
259 PPAPITest::PPAPITest() { | 298 PPAPITest::PPAPITest() { |
260 } | 299 } |
261 | 300 |
262 void PPAPITest::SetUpCommandLine(CommandLine* command_line) { | 301 void PPAPITest::SetUpCommandLine(CommandLine* command_line) { |
263 PPAPITestBase::SetUpCommandLine(command_line); | 302 PPAPITestBase::SetUpCommandLine(command_line); |
264 | 303 |
265 // Append the switch to register the pepper plugin. | 304 // Append the switch to register the pepper plugin. |
266 // library name = <out dir>/<test_name>.<library_extension> | 305 // library name = <out dir>/<test_name>.<library_extension> |
267 // MIME type = application/x-ppapi-<test_name> | 306 // MIME type = application/x-ppapi-<test_name> |
268 FilePath plugin_dir; | 307 FilePath plugin_dir; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 } | 370 } |
332 | 371 |
333 // Append the correct mode and testcase string | 372 // Append the correct mode and testcase string |
334 std::string PPAPINaClTestDisallowedSockets::BuildQuery( | 373 std::string PPAPINaClTestDisallowedSockets::BuildQuery( |
335 const std::string& base, | 374 const std::string& base, |
336 const std::string& test_case) { | 375 const std::string& test_case) { |
337 return StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), | 376 return StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), |
338 test_case.c_str()); | 377 test_case.c_str()); |
339 } | 378 } |
340 | 379 |
OLD | NEW |