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/files/file_util.h" | 8 #include "base/files/file_util.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "components/infobars/core/confirm_infobar_delegate.h" | 26 #include "components/infobars/core/confirm_infobar_delegate.h" |
27 #include "components/infobars/core/infobar.h" | 27 #include "components/infobars/core/infobar.h" |
28 #include "components/nacl/common/nacl_switches.h" | 28 #include "components/nacl/common/nacl_switches.h" |
29 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
31 #include "content/public/common/content_switches.h" | 31 #include "content/public/common/content_switches.h" |
32 #include "content/public/test/ppapi_test_utils.h" | 32 #include "content/public/test/ppapi_test_utils.h" |
33 #include "media/base/media_switches.h" | 33 #include "media/base/media_switches.h" |
34 #include "net/base/filename_util.h" | 34 #include "net/base/filename_util.h" |
35 #include "net/base/test_data_directory.h" | 35 #include "net/base/test_data_directory.h" |
| 36 #include "net/test/spawned_test_server/spawned_test_server.h" |
36 #include "ppapi/shared_impl/ppapi_switches.h" | 37 #include "ppapi/shared_impl/ppapi_switches.h" |
37 #include "ui/gl/gl_switches.h" | 38 #include "ui/gl/gl_switches.h" |
38 | 39 |
39 using content::RenderViewHost; | 40 using content::RenderViewHost; |
40 using content::TestMessageHandler; | 41 using content::TestMessageHandler; |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 void AddPrivateSwitches(base::CommandLine* command_line) { | 45 void AddPrivateSwitches(base::CommandLine* command_line) { |
45 // For TestRequestOSFileHandle. | 46 // For TestRequestOSFileHandle. |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 169 } |
169 | 170 |
170 void PPAPITestBase::RunTest(const std::string& test_case) { | 171 void PPAPITestBase::RunTest(const std::string& test_case) { |
171 GURL url = GetTestFileUrl(test_case); | 172 GURL url = GetTestFileUrl(test_case); |
172 RunTestURL(url); | 173 RunTestURL(url); |
173 } | 174 } |
174 | 175 |
175 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { | 176 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { |
176 base::FilePath document_root; | 177 base::FilePath document_root; |
177 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&document_root)); | 178 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&document_root)); |
178 net::SpawnedTestServer http_server(net::SpawnedTestServer::TYPE_HTTP, | 179 net::EmbeddedTestServer http_server; |
179 net::SpawnedTestServer::kLocalhost, | 180 http_server.AddDefaultHandlers(document_root); |
180 document_root); | |
181 ASSERT_TRUE(http_server.Start()); | 181 ASSERT_TRUE(http_server.Start()); |
182 RunTestURL(GetTestURL(http_server, test_case, std::string())); | 182 RunTestURL(GetTestURL(http_server, test_case, std::string())); |
183 } | 183 } |
184 | 184 |
185 void PPAPITestBase::RunTestWithSSLServer(const std::string& test_case) { | 185 void PPAPITestBase::RunTestWithSSLServer(const std::string& test_case) { |
186 base::FilePath http_document_root; | 186 base::FilePath http_document_root; |
187 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&http_document_root)); | 187 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&http_document_root)); |
188 net::SpawnedTestServer http_server(net::SpawnedTestServer::TYPE_HTTP, | 188 net::EmbeddedTestServer http_server; |
189 net::SpawnedTestServer::kLocalhost, | 189 http_server.AddDefaultHandlers(http_document_root); |
190 http_document_root); | 190 net::EmbeddedTestServer ssl_server(net::EmbeddedTestServer::TYPE_HTTPS); |
191 net::SpawnedTestServer ssl_server(net::SpawnedTestServer::TYPE_HTTPS, | 191 ssl_server.AddDefaultHandlers(http_document_root); |
192 net::BaseTestServer::SSLOptions(), | 192 |
193 http_document_root); | 193 ASSERT_TRUE(http_server.Start()); |
194 // Start the servers in parallel. | 194 ASSERT_TRUE(ssl_server.Start()); |
195 ASSERT_TRUE(http_server.StartInBackground()); | |
196 ASSERT_TRUE(ssl_server.StartInBackground()); | |
197 // Wait until they are both finished before continuing. | |
198 ASSERT_TRUE(http_server.BlockUntilStarted()); | |
199 ASSERT_TRUE(ssl_server.BlockUntilStarted()); | |
200 | 195 |
201 uint16_t port = ssl_server.host_port_pair().port(); | 196 uint16_t port = ssl_server.host_port_pair().port(); |
202 RunTestURL(GetTestURL(http_server, | 197 RunTestURL(GetTestURL(http_server, |
203 test_case, | 198 test_case, |
204 base::StringPrintf("ssl_server_port=%d", port))); | 199 base::StringPrintf("ssl_server_port=%d", port))); |
205 } | 200 } |
206 | 201 |
207 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { | 202 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { |
208 base::FilePath http_document_root; | 203 base::FilePath http_document_root; |
209 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&http_document_root)); | 204 ASSERT_TRUE(ui_test_utils::GetRelativeBuildDirectory(&http_document_root)); |
210 net::SpawnedTestServer http_server(net::SpawnedTestServer::TYPE_HTTP, | 205 net::EmbeddedTestServer http_server; |
211 net::SpawnedTestServer::kLocalhost, | 206 http_server.AddDefaultHandlers(http_document_root); |
212 http_document_root); | |
213 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, | 207 net::SpawnedTestServer ws_server(net::SpawnedTestServer::TYPE_WS, |
214 net::SpawnedTestServer::kLocalhost, | 208 net::SpawnedTestServer::kLocalhost, |
215 net::GetWebSocketTestDataDirectory()); | 209 net::GetWebSocketTestDataDirectory()); |
216 // Start the servers in parallel. | 210 ASSERT_TRUE(http_server.Start()); |
217 ASSERT_TRUE(http_server.StartInBackground()); | 211 ASSERT_TRUE(ws_server.Start()); |
218 ASSERT_TRUE(ws_server.StartInBackground()); | |
219 // Wait until they are both finished before continuing. | |
220 ASSERT_TRUE(http_server.BlockUntilStarted()); | |
221 ASSERT_TRUE(ws_server.BlockUntilStarted()); | |
222 | 212 |
223 std::string host = ws_server.host_port_pair().HostForURL(); | 213 std::string host = ws_server.host_port_pair().HostForURL(); |
224 uint16_t port = ws_server.host_port_pair().port(); | 214 uint16_t port = ws_server.host_port_pair().port(); |
225 RunTestURL(GetTestURL(http_server, | 215 RunTestURL(GetTestURL(http_server, |
226 test_case, | 216 test_case, |
227 base::StringPrintf( | 217 base::StringPrintf( |
228 "websocket_host=%s&websocket_port=%d", | 218 "websocket_host=%s&websocket_port=%d", |
229 host.c_str(), | 219 host.c_str(), |
230 port))); | 220 port))); |
231 } | 221 } |
(...skipping 27 matching lines...) Expand all Loading... |
259 content::JavascriptTestObserver observer( | 249 content::JavascriptTestObserver observer( |
260 browser()->tab_strip_model()->GetActiveWebContents(), | 250 browser()->tab_strip_model()->GetActiveWebContents(), |
261 &handler); | 251 &handler); |
262 | 252 |
263 ui_test_utils::NavigateToURL(browser(), test_url); | 253 ui_test_utils::NavigateToURL(browser(), test_url); |
264 | 254 |
265 ASSERT_TRUE(observer.Run()) << handler.error_message(); | 255 ASSERT_TRUE(observer.Run()) << handler.error_message(); |
266 EXPECT_STREQ("PASS", handler.message().c_str()); | 256 EXPECT_STREQ("PASS", handler.message().c_str()); |
267 } | 257 } |
268 | 258 |
269 GURL PPAPITestBase::GetTestURL( | 259 GURL PPAPITestBase::GetTestURL(const net::EmbeddedTestServer& http_server, |
270 const net::SpawnedTestServer& http_server, | 260 const std::string& test_case, |
271 const std::string& test_case, | 261 const std::string& extra_params) { |
272 const std::string& extra_params) { | 262 std::string query = BuildQuery("/test_case.html?", test_case); |
273 std::string query = BuildQuery("files/test_case.html?", test_case); | |
274 if (!extra_params.empty()) | 263 if (!extra_params.empty()) |
275 query = base::StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); | 264 query = base::StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); |
276 | 265 |
277 return http_server.GetURL(query); | 266 return http_server.GetURL(query); |
278 } | 267 } |
279 | 268 |
280 PPAPITest::PPAPITest() : in_process_(true) { | 269 PPAPITest::PPAPITest() : in_process_(true) { |
281 } | 270 } |
282 | 271 |
283 void PPAPITest::SetUpCommandLine(base::CommandLine* command_line) { | 272 void PPAPITest::SetUpCommandLine(base::CommandLine* command_line) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 const std::string& base, | 437 const std::string& base, |
449 const std::string& test_case) { | 438 const std::string& test_case) { |
450 return base::StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), | 439 return base::StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), |
451 test_case.c_str()); | 440 test_case.c_str()); |
452 } | 441 } |
453 | 442 |
454 void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { | 443 void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { |
455 // The default content setting for the PPAPI broker is ASK. We purposefully | 444 // The default content setting for the PPAPI broker is ASK. We purposefully |
456 // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. | 445 // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. |
457 } | 446 } |
OLD | NEW |