Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: chrome/test/ui/ppapi_uitest.cc

Issue 9791003: Added pepper test for SSLHandshake (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/ui/ppapi_uitest.h ('k') | ppapi/tests/test_case.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 } 152 }
153 153
154 void PPAPITestBase::RunTestAndReload(const std::string& test_case) { 154 void PPAPITestBase::RunTestAndReload(const std::string& test_case) {
155 GURL url = GetTestFileUrl(test_case); 155 GURL url = GetTestFileUrl(test_case);
156 RunTestURL(url); 156 RunTestURL(url);
157 // If that passed, we simply run the test again, which navigates again. 157 // If that passed, we simply run the test again, which navigates again.
158 RunTestURL(url); 158 RunTestURL(url);
159 } 159 }
160 160
161 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) { 161 void PPAPITestBase::RunTestViaHTTP(const std::string& test_case) {
162 // For HTTP tests, we use the output DIR to grab the generated files such
163 // as the NEXEs.
164 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName();
165 FilePath src_dir;
166 ASSERT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &src_dir));
167
168 // TestServer expects a path relative to source. So we must first
169 // generate absolute paths to SRC and EXE and from there generate
170 // a relative path.
171 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir);
172 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir);
173 ASSERT_TRUE(exe_dir.IsAbsolute());
174 ASSERT_TRUE(src_dir.IsAbsolute());
175
176 size_t match, exe_size, src_size;
177 std::vector<FilePath::StringType> src_parts, exe_parts;
178
179 // Determine point at which src and exe diverge, and create a relative path.
180 exe_dir.GetComponents(&exe_parts);
181 src_dir.GetComponents(&src_parts);
182 exe_size = exe_parts.size();
183 src_size = src_parts.size();
184 for (match = 0; match < exe_size && match < src_size; ++match) {
185 if (exe_parts[match] != src_parts[match])
186 break;
187 }
188 FilePath web_dir; 162 FilePath web_dir;
189 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) { 163 ASSERT_TRUE(GetHTTPDocumentRoot(&web_dir));
190 web_dir = web_dir.Append(FILE_PATH_LITERAL(".."));
191 }
192 for (; match < exe_size; ++match) {
193 web_dir = web_dir.Append(exe_parts[match]);
194 }
195
196 net::TestServer test_server(net::TestServer::TYPE_HTTP, 164 net::TestServer test_server(net::TestServer::TYPE_HTTP,
197 net::TestServer::kLocalhost, 165 net::TestServer::kLocalhost,
198 web_dir); 166 web_dir);
199 ASSERT_TRUE(test_server.Start()); 167 ASSERT_TRUE(test_server.Start());
200 std::string query = BuildQuery("files/test_case.html?", test_case); 168 std::string query = BuildQuery("files/test_case.html?", test_case);
201 169
202 GURL url = test_server.GetURL(query); 170 GURL url = test_server.GetURL(query);
203 RunTestURL(url); 171 RunTestURL(url);
204 } 172 }
205 173
174 void PPAPITestBase::RunTestWithSSLServer(const std::string& test_case) {
175 FilePath web_dir;
176 ASSERT_TRUE(GetHTTPDocumentRoot(&web_dir));
177 net::TestServer test_server(net::BaseTestServer::HTTPSOptions(), web_dir);
178 ASSERT_TRUE(test_server.Start());
179
180 uint16_t port = test_server.host_port_pair().port();
181 std::string url = StringPrintf("%s&ssl_server_port=%d",
182 test_case.c_str(), port);
183 RunTestViaHTTP(url);
yzshen1 2012/03/21 22:37:58 nit: It might be better to have a private method n
raymes 2012/03/21 23:33:07 Hmm, I'm not sure exactly what you mean here. Can
yzshen1 2012/03/21 23:42:12 The current code calls RunTestViaHTTP() directly,
184 }
185
206 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) { 186 void PPAPITestBase::RunTestWithWebSocketServer(const std::string& test_case) {
207 FilePath websocket_root_dir; 187 FilePath websocket_root_dir;
208 ASSERT_TRUE( 188 ASSERT_TRUE(
209 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir)); 189 PathService::Get(chrome::DIR_LAYOUT_TESTS, &websocket_root_dir));
210 190
211 ui_test_utils::TestWebSocketServer server; 191 ui_test_utils::TestWebSocketServer server;
212 int port = server.UseRandomPort(); 192 int port = server.UseRandomPort();
213 ASSERT_TRUE(server.Start(websocket_root_dir)); 193 ASSERT_TRUE(server.Start(websocket_root_dir));
214 std::string url = StringPrintf("%s&websocket_port=%d", 194 std::string url = StringPrintf("%s&websocket_port=%d",
215 test_case.c_str(), port); 195 test_case.c_str(), port);
(...skipping 18 matching lines...) Expand all
234 TestFinishObserver observer( 214 TestFinishObserver observer(
235 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs); 215 browser()->GetSelectedWebContents()->GetRenderViewHost(), kTimeoutMs);
236 216
237 ui_test_utils::NavigateToURL(browser(), test_url); 217 ui_test_utils::NavigateToURL(browser(), test_url);
238 218
239 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out."; 219 ASSERT_TRUE(observer.WaitForFinish()) << "Test timed out.";
240 220
241 EXPECT_STREQ("PASS", observer.result().c_str()); 221 EXPECT_STREQ("PASS", observer.result().c_str());
242 } 222 }
243 223
224 bool PPAPITestBase::GetHTTPDocumentRoot(FilePath* web_dir) {
225 // For HTTP tests, we use the output DIR to grab the generated files such
226 // as the NEXEs.
227 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName();
228 FilePath src_dir;
229 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir))
230 return false;
231
232 // TestServer expects a path relative to source. So we must first
233 // generate absolute paths to SRC and EXE and from there generate
234 // a relative path.
235 if (!exe_dir.IsAbsolute()) file_util::AbsolutePath(&exe_dir);
236 if (!src_dir.IsAbsolute()) file_util::AbsolutePath(&src_dir);
237 if (!exe_dir.IsAbsolute())
238 return false;
239 if (!src_dir.IsAbsolute())
240 return false;
241
242 size_t match, exe_size, src_size;
243 std::vector<FilePath::StringType> src_parts, exe_parts;
244
245 // Determine point at which src and exe diverge, and create a relative path.
246 exe_dir.GetComponents(&exe_parts);
247 src_dir.GetComponents(&src_parts);
248 exe_size = exe_parts.size();
249 src_size = src_parts.size();
250 for (match = 0; match < exe_size && match < src_size; ++match) {
251 if (exe_parts[match] != src_parts[match])
252 break;
253 }
254 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) {
255 *web_dir = web_dir->Append(FILE_PATH_LITERAL(".."));
256 }
257 for (; match < exe_size; ++match) {
258 *web_dir = web_dir->Append(exe_parts[match]);
259 }
260 return true;
261 }
262
244 PPAPITest::PPAPITest() { 263 PPAPITest::PPAPITest() {
245 } 264 }
246 265
247 void PPAPITest::SetUpCommandLine(CommandLine* command_line) { 266 void PPAPITest::SetUpCommandLine(CommandLine* command_line) {
248 PPAPITestBase::SetUpCommandLine(command_line); 267 PPAPITestBase::SetUpCommandLine(command_line);
249 268
250 // Append the switch to register the pepper plugin. 269 // Append the switch to register the pepper plugin.
251 // library name = <out dir>/<test_name>.<library_extension> 270 // library name = <out dir>/<test_name>.<library_extension>
252 // MIME type = application/x-ppapi-<test_name> 271 // MIME type = application/x-ppapi-<test_name>
253 FilePath plugin_dir; 272 FilePath plugin_dir;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 // Similar macros that test over HTTP. 358 // Similar macros that test over HTTP.
340 #define TEST_PPAPI_IN_PROCESS_VIA_HTTP(test_name) \ 359 #define TEST_PPAPI_IN_PROCESS_VIA_HTTP(test_name) \
341 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ 360 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \
342 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ 361 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
343 } 362 }
344 #define TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(test_name) \ 363 #define TEST_PPAPI_OUT_OF_PROCESS_VIA_HTTP(test_name) \
345 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ 364 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
346 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \ 365 RunTestViaHTTP(STRIP_PREFIXES(test_name)); \
347 } 366 }
348 367
368 // Similar macros that test with an SSL server.
369 #define TEST_PPAPI_IN_PROCESS_WITH_SSL_SERVER(test_name) \
370 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \
371 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \
372 }
373 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(test_name) \
374 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
375 RunTestWithSSLServer(STRIP_PREFIXES(test_name)); \
376 }
377
349 // Similar macros that test with WebSocket server 378 // Similar macros that test with WebSocket server
350 #define TEST_PPAPI_IN_PROCESS_WITH_WS(test_name) \ 379 #define TEST_PPAPI_IN_PROCESS_WITH_WS(test_name) \
351 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \ 380 IN_PROC_BROWSER_TEST_F(PPAPITest, test_name) { \
352 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ 381 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \
353 } 382 }
354 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_WS(test_name) \ 383 #define TEST_PPAPI_OUT_OF_PROCESS_WITH_WS(test_name) \
355 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \ 384 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, test_name) { \
356 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \ 385 RunTestWithWebSocketServer(STRIP_PREFIXES(test_name)); \
357 } 386 }
358 387
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 TEST_PPAPI_NACL_VIA_HTTP(MAYBE_NetAddressPrivateUntrusted_ReplacePort) 825 TEST_PPAPI_NACL_VIA_HTTP(MAYBE_NetAddressPrivateUntrusted_ReplacePort)
797 TEST_PPAPI_NACL_VIA_HTTP(NetAddressPrivateUntrusted_GetAnyAddress) 826 TEST_PPAPI_NACL_VIA_HTTP(NetAddressPrivateUntrusted_GetAnyAddress)
798 TEST_PPAPI_NACL_VIA_HTTP(NetAddressPrivateUntrusted_GetFamily) 827 TEST_PPAPI_NACL_VIA_HTTP(NetAddressPrivateUntrusted_GetFamily)
799 TEST_PPAPI_NACL_VIA_HTTP(MAYBE_NetAddressPrivateUntrusted_GetPort) 828 TEST_PPAPI_NACL_VIA_HTTP(MAYBE_NetAddressPrivateUntrusted_GetPort)
800 TEST_PPAPI_NACL_VIA_HTTP(NetAddressPrivateUntrusted_GetAddress) 829 TEST_PPAPI_NACL_VIA_HTTP(NetAddressPrivateUntrusted_GetAddress)
801 830
802 TEST_PPAPI_IN_PROCESS(NetworkMonitorPrivate_Basic) 831 TEST_PPAPI_IN_PROCESS(NetworkMonitorPrivate_Basic)
803 TEST_PPAPI_IN_PROCESS(NetworkMonitorPrivate_2Monitors) 832 TEST_PPAPI_IN_PROCESS(NetworkMonitorPrivate_2Monitors)
804 833
805 // PPB_TCPSocket_Private currently isn't supported in-process. 834 // PPB_TCPSocket_Private currently isn't supported in-process.
806 IN_PROC_BROWSER_TEST_F(OutOfProcessPPAPITest, TCPSocketPrivate) { 835 TEST_PPAPI_OUT_OF_PROCESS_WITH_SSL_SERVER(TCPSocketPrivate);
yzshen1 2012/03/21 22:37:58 Please update this accordingly once you check in t
raymes 2012/03/21 23:33:07 Done.
807 RunTestViaHTTP("TCPSocketPrivate");
808 }
809 836
810 TEST_PPAPI_IN_PROCESS(Flash_SetInstanceAlwaysOnTop) 837 TEST_PPAPI_IN_PROCESS(Flash_SetInstanceAlwaysOnTop)
811 TEST_PPAPI_IN_PROCESS(Flash_GetProxyForURL) 838 TEST_PPAPI_IN_PROCESS(Flash_GetProxyForURL)
812 TEST_PPAPI_IN_PROCESS(Flash_MessageLoop) 839 TEST_PPAPI_IN_PROCESS(Flash_MessageLoop)
813 TEST_PPAPI_IN_PROCESS(Flash_GetLocalTimeZoneOffset) 840 TEST_PPAPI_IN_PROCESS(Flash_GetLocalTimeZoneOffset)
814 TEST_PPAPI_IN_PROCESS(Flash_GetCommandLineArgs) 841 TEST_PPAPI_IN_PROCESS(Flash_GetCommandLineArgs)
815 TEST_PPAPI_OUT_OF_PROCESS(Flash_SetInstanceAlwaysOnTop) 842 TEST_PPAPI_OUT_OF_PROCESS(Flash_SetInstanceAlwaysOnTop)
816 TEST_PPAPI_OUT_OF_PROCESS(Flash_GetProxyForURL) 843 TEST_PPAPI_OUT_OF_PROCESS(Flash_GetProxyForURL)
817 TEST_PPAPI_OUT_OF_PROCESS(Flash_MessageLoop) 844 TEST_PPAPI_OUT_OF_PROCESS(Flash_MessageLoop)
818 TEST_PPAPI_OUT_OF_PROCESS(Flash_GetLocalTimeZoneOffset) 845 TEST_PPAPI_OUT_OF_PROCESS(Flash_GetLocalTimeZoneOffset)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess) 984 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_OutOfRangeAccess)
958 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray) 985 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_EmptyArray)
959 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement) 986 TEST_PPAPI_OUT_OF_PROCESS(ResourceArray_InvalidElement)
960 987
961 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics) 988 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_Basics)
962 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit) 989 TEST_PPAPI_IN_PROCESS(FlashMessageLoop_RunWithoutQuit)
963 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics) 990 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_Basics)
964 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit) 991 TEST_PPAPI_OUT_OF_PROCESS(FlashMessageLoop_RunWithoutQuit)
965 992
966 #endif // ADDRESS_SANITIZER 993 #endif // ADDRESS_SANITIZER
OLDNEW
« no previous file with comments | « chrome/test/ui/ppapi_uitest.h ('k') | ppapi/tests/test_case.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698