| 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(), | |
| 193 http_document_root); | |
| 194 // Start the servers in parallel. | 192 // Start the servers in parallel. |
| 195 ASSERT_TRUE(http_server.StartInBackground()); | 193 ASSERT_TRUE(http_server.Start()); |
| 196 ASSERT_TRUE(ssl_server.StartInBackground()); | 194 ASSERT_TRUE(ssl_server.Start()); |
| 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 // Start the servers in parallel. |
| 217 ASSERT_TRUE(http_server.StartInBackground()); | 211 ASSERT_TRUE(http_server.Start()); |
| 218 ASSERT_TRUE(ws_server.StartInBackground()); | 212 ASSERT_TRUE(ws_server.StartInBackground()); |
| 219 // Wait until they are both finished before continuing. | 213 // Wait until they are both finished before continuing. |
| 220 ASSERT_TRUE(http_server.BlockUntilStarted()); | |
| 221 ASSERT_TRUE(ws_server.BlockUntilStarted()); | 214 ASSERT_TRUE(ws_server.BlockUntilStarted()); |
| 222 | 215 |
| 223 std::string host = ws_server.host_port_pair().HostForURL(); | 216 std::string host = ws_server.host_port_pair().HostForURL(); |
| 224 uint16_t port = ws_server.host_port_pair().port(); | 217 uint16_t port = ws_server.host_port_pair().port(); |
| 225 RunTestURL(GetTestURL(http_server, | 218 RunTestURL(GetTestURL(http_server, |
| 226 test_case, | 219 test_case, |
| 227 base::StringPrintf( | 220 base::StringPrintf( |
| 228 "websocket_host=%s&websocket_port=%d", | 221 "websocket_host=%s&websocket_port=%d", |
| 229 host.c_str(), | 222 host.c_str(), |
| 230 port))); | 223 port))); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 259 content::JavascriptTestObserver observer( | 252 content::JavascriptTestObserver observer( |
| 260 browser()->tab_strip_model()->GetActiveWebContents(), | 253 browser()->tab_strip_model()->GetActiveWebContents(), |
| 261 &handler); | 254 &handler); |
| 262 | 255 |
| 263 ui_test_utils::NavigateToURL(browser(), test_url); | 256 ui_test_utils::NavigateToURL(browser(), test_url); |
| 264 | 257 |
| 265 ASSERT_TRUE(observer.Run()) << handler.error_message(); | 258 ASSERT_TRUE(observer.Run()) << handler.error_message(); |
| 266 EXPECT_STREQ("PASS", handler.message().c_str()); | 259 EXPECT_STREQ("PASS", handler.message().c_str()); |
| 267 } | 260 } |
| 268 | 261 |
| 269 GURL PPAPITestBase::GetTestURL( | 262 GURL PPAPITestBase::GetTestURL(const net::EmbeddedTestServer& http_server, |
| 270 const net::SpawnedTestServer& http_server, | 263 const std::string& test_case, |
| 271 const std::string& test_case, | 264 const std::string& extra_params) { |
| 272 const std::string& extra_params) { | 265 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()) | 266 if (!extra_params.empty()) |
| 275 query = base::StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); | 267 query = base::StringPrintf("%s&%s", query.c_str(), extra_params.c_str()); |
| 276 | 268 |
| 277 return http_server.GetURL(query); | 269 return http_server.GetURL(query); |
| 278 } | 270 } |
| 279 | 271 |
| 280 PPAPITest::PPAPITest() : in_process_(true) { | 272 PPAPITest::PPAPITest() : in_process_(true) { |
| 281 } | 273 } |
| 282 | 274 |
| 283 void PPAPITest::SetUpCommandLine(base::CommandLine* command_line) { | 275 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, | 440 const std::string& base, |
| 449 const std::string& test_case) { | 441 const std::string& test_case) { |
| 450 return base::StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), | 442 return base::StringPrintf("%smode=nacl_newlib&testcase=%s", base.c_str(), |
| 451 test_case.c_str()); | 443 test_case.c_str()); |
| 452 } | 444 } |
| 453 | 445 |
| 454 void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { | 446 void PPAPIBrokerInfoBarTest::SetUpOnMainThread() { |
| 455 // The default content setting for the PPAPI broker is ASK. We purposefully | 447 // The default content setting for the PPAPI broker is ASK. We purposefully |
| 456 // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. | 448 // don't call PPAPITestBase::SetUpOnMainThread() to keep it that way. |
| 457 } | 449 } |
| OLD | NEW |