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

Side by Side Diff: ppapi/tests/test_tcp_socket_private.cc

Issue 9836015: Revert 128266 - Added a pepper test for SSLHandshake. This starts an SSL server which the test can … (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 | « ppapi/tests/test_tcp_socket_private.h ('k') | ppapi/tests/testing_instance.h » ('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 "ppapi/tests/test_tcp_socket_private.h" 5 #include "ppapi/tests/test_tcp_socket_private.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include "ppapi/cpp/private/tcp_socket_private.h" 9 #include "ppapi/cpp/private/tcp_socket_private.h"
10 #include "ppapi/tests/testing_instance.h" 10 #include "ppapi/tests/testing_instance.h"
(...skipping 22 matching lines...) Expand all
33 return false; 33 return false;
34 34
35 // We need something to connect to, so we connect to the HTTP server whence we 35 // We need something to connect to, so we connect to the HTTP server whence we
36 // came. Grab the host and port. 36 // came. Grab the host and port.
37 if (!EnsureRunningOverHTTP()) 37 if (!EnsureRunningOverHTTP())
38 return false; 38 return false;
39 39
40 if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_)) 40 if (!GetLocalHostPort(instance_->pp_instance(), &host_, &port_))
41 return false; 41 return false;
42 42
43 // Get the port for the SSL server.
44 ssl_port_ = instance_->ssl_server_port();
45
46 return true; 43 return true;
47 } 44 }
48 45
49 void TestTCPSocketPrivate::RunTests(const std::string& filter) { 46 void TestTCPSocketPrivate::RunTests(const std::string& filter) {
50 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); 47 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter);
51 RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter); 48 RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter);
52 RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSSL, filter);
53 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter); 49 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter);
54 } 50 }
55 51
56 std::string TestTCPSocketPrivate::TestBasic() { 52 std::string TestTCPSocketPrivate::TestBasic() {
57 pp::TCPSocketPrivate socket(instance_); 53 pp::TCPSocketPrivate socket(instance_);
58 TestCompletionCallback cb(instance_->pp_instance(), force_async_); 54 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
59 55
60 int32_t rv = socket.Connect(host_.c_str(), port_, cb); 56 int32_t rv = socket.Connect(host_.c_str(), port_, cb);
61 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); 57 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
62 if (rv == PP_OK_COMPLETIONPENDING) 58 if (rv == PP_OK_COMPLETIONPENDING)
(...skipping 25 matching lines...) Expand all
88 // Read up to the first \n and check that it looks like valid HTTP response. 84 // Read up to the first \n and check that it looks like valid HTTP response.
89 std::string s; 85 std::string s;
90 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); 86 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s));
91 ASSERT_TRUE(ValidateHttpResponse(s)); 87 ASSERT_TRUE(ValidateHttpResponse(s));
92 88
93 socket.Disconnect(); 89 socket.Disconnect();
94 90
95 PASS(); 91 PASS();
96 } 92 }
97 93
98 std::string TestTCPSocketPrivate::TestReadWriteSSL() {
99 pp::TCPSocketPrivate socket(instance_);
100 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
101
102 int32_t rv = socket.Connect(host_.c_str(), ssl_port_, cb);
103 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
104 if (rv == PP_OK_COMPLETIONPENDING)
105 rv = cb.WaitForResult();
106 ASSERT_EQ(PP_OK, rv);
107
108 rv = socket.SSLHandshake(host_.c_str(), ssl_port_, cb);
109 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
110 if (rv == PP_OK_COMPLETIONPENDING)
111 rv = cb.WaitForResult();
112 ASSERT_EQ(PP_OK, rv);
113
114 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n"));
115
116 // Read up to the first \n and check that it looks like valid HTTP response.
117 std::string s;
118 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s));
119 ASSERT_TRUE(ValidateHttpResponse(s));
120
121 socket.Disconnect();
122
123 PASS();
124 }
125
126 std::string TestTCPSocketPrivate::TestConnectAddress() { 94 std::string TestTCPSocketPrivate::TestConnectAddress() {
127 PP_NetAddress_Private address; 95 PP_NetAddress_Private address;
128 96
129 // First, bring up a connection and grab the address. 97 // First, bring up a connection and grab the address.
130 { 98 {
131 pp::TCPSocketPrivate socket(instance_); 99 pp::TCPSocketPrivate socket(instance_);
132 TestCompletionCallback cb(instance_->pp_instance(), force_async_); 100 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
133 int32_t rv = socket.Connect(host_.c_str(), port_, cb); 101 int32_t rv = socket.Connect(host_.c_str(), port_, cb);
134 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); 102 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
135 if (rv == PP_OK_COMPLETIONPENDING) 103 if (rv == PP_OK_COMPLETIONPENDING)
(...skipping 17 matching lines...) Expand all
153 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n")); 121 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n"));
154 std::string s; 122 std::string s;
155 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); 123 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s));
156 ASSERT_TRUE(ValidateHttpResponse(s)); 124 ASSERT_TRUE(ValidateHttpResponse(s));
157 125
158 socket.Disconnect(); 126 socket.Disconnect();
159 127
160 PASS(); 128 PASS();
161 } 129 }
162 130
131 // TODO(viettrungluu): Try testing SSL somehow.
132
163 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( 133 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket(
164 pp::TCPSocketPrivate* socket, 134 pp::TCPSocketPrivate* socket,
165 std::string* s) { 135 std::string* s) {
166 char buffer[10000]; 136 char buffer[10000];
167 137
168 s->clear(); 138 s->clear();
169 // Make sure we don't just hang if |Read()| spews. 139 // Make sure we don't just hang if |Read()| spews.
170 while (s->size() < 1000000) { 140 while (s->size() < 1000000) {
171 TestCompletionCallback cb(instance_->pp_instance(), force_async_); 141 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
172 int32_t rv = socket->Read(buffer, sizeof(buffer), cb); 142 int32_t rv = socket->Read(buffer, sizeof(buffer), cb);
(...skipping 29 matching lines...) Expand all
202 if (rv < 0) 172 if (rv < 0)
203 return rv; 173 return rv;
204 if (rv == 0) 174 if (rv == 0)
205 return PP_ERROR_FAILED; 175 return PP_ERROR_FAILED;
206 written += rv; 176 written += rv;
207 } 177 }
208 if (written != s.size()) 178 if (written != s.size())
209 return PP_ERROR_FAILED; 179 return PP_ERROR_FAILED;
210 return PP_OK; 180 return PP_OK;
211 } 181 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_tcp_socket_private.h ('k') | ppapi/tests/testing_instance.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698