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

Side by Side Diff: ppapi/tests/test_tcp_socket_private.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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/c/dev/ppb_url_util_dev.h" 9 #include "ppapi/c/dev/ppb_url_util_dev.h"
10 #include "ppapi/cpp/dev/url_util_dev.h" 10 #include "ppapi/cpp/dev/url_util_dev.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 // Get port (it's optional). 69 // Get port (it's optional).
70 port_ = 80; // Default value. 70 port_ = 80; // Default value.
71 if (components.port.len > 0) { 71 if (components.port.len > 0) {
72 int i = atoi(url.substr(components.port.begin, 72 int i = atoi(url.substr(components.port.begin,
73 components.port.len).c_str()); 73 components.port.len).c_str());
74 if (i < 0 || i > 65535) 74 if (i < 0 || i > 65535)
75 return false; 75 return false;
76 port_ = static_cast<uint16_t>(i); 76 port_ = static_cast<uint16_t>(i);
77 } 77 }
78 78
79 // Get the port for the SSL server.
80 ssl_port_ = instance_->ssl_server_port();
81
79 return true; 82 return true;
80 } 83 }
81 84
82 void TestTCPSocketPrivate::RunTests(const std::string& filter) { 85 void TestTCPSocketPrivate::RunTests(const std::string& filter) {
83 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); 86 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter);
84 RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter); 87 RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter);
88 RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSSL, filter);
85 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter); 89 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter);
86 } 90 }
87 91
88 std::string TestTCPSocketPrivate::TestBasic() { 92 std::string TestTCPSocketPrivate::TestBasic() {
89 pp::TCPSocketPrivate socket(instance_); 93 pp::TCPSocketPrivate socket(instance_);
90 TestCompletionCallback cb(instance_->pp_instance(), force_async_); 94 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
91 95
92 int32_t rv = socket.Connect(host_.c_str(), port_, cb); 96 int32_t rv = socket.Connect(host_.c_str(), port_, cb);
93 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); 97 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
94 if (rv == PP_OK_COMPLETIONPENDING) 98 if (rv == PP_OK_COMPLETIONPENDING)
(...skipping 25 matching lines...) Expand all
120 // Read up to the first \n and check that it looks like valid HTTP response. 124 // Read up to the first \n and check that it looks like valid HTTP response.
121 std::string s; 125 std::string s;
122 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); 126 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s));
123 ASSERT_TRUE(ValidateHttpResponse(s)); 127 ASSERT_TRUE(ValidateHttpResponse(s));
124 128
125 socket.Disconnect(); 129 socket.Disconnect();
126 130
127 PASS(); 131 PASS();
128 } 132 }
129 133
134 std::string TestTCPSocketPrivate::TestReadWriteSSL() {
135 pp::TCPSocketPrivate socket(instance_);
136 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
137
138 int32_t rv = socket.Connect(host_.c_str(), ssl_port_, cb);
139 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
140 if (rv == PP_OK_COMPLETIONPENDING)
141 rv = cb.WaitForResult();
142 ASSERT_EQ(PP_OK, rv);
143
144 rv = socket.SSLHandshake(host_.c_str(), ssl_port_, cb);
145 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
146 if (rv == PP_OK_COMPLETIONPENDING)
147 rv = cb.WaitForResult();
148 ASSERT_EQ(PP_OK, rv);
149
150 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n"));
151
152 // Read up to the first \n and check that it looks like valid HTTP response.
153 std::string s;
154 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s));
155 ASSERT_TRUE(ValidateHttpResponse(s));
156
157 socket.Disconnect();
158
159 PASS();
160 }
161
130 std::string TestTCPSocketPrivate::TestConnectAddress() { 162 std::string TestTCPSocketPrivate::TestConnectAddress() {
131 PP_NetAddress_Private address; 163 PP_NetAddress_Private address;
132 164
133 // First, bring up a connection and grab the address. 165 // First, bring up a connection and grab the address.
134 { 166 {
135 pp::TCPSocketPrivate socket(instance_); 167 pp::TCPSocketPrivate socket(instance_);
136 TestCompletionCallback cb(instance_->pp_instance(), force_async_); 168 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
137 int32_t rv = socket.Connect(host_.c_str(), port_, cb); 169 int32_t rv = socket.Connect(host_.c_str(), port_, cb);
138 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); 170 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING);
139 if (rv == PP_OK_COMPLETIONPENDING) 171 if (rv == PP_OK_COMPLETIONPENDING)
(...skipping 17 matching lines...) Expand all
157 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n")); 189 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n"));
158 std::string s; 190 std::string s;
159 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); 191 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s));
160 ASSERT_TRUE(ValidateHttpResponse(s)); 192 ASSERT_TRUE(ValidateHttpResponse(s));
161 193
162 socket.Disconnect(); 194 socket.Disconnect();
163 195
164 PASS(); 196 PASS();
165 } 197 }
166 198
167 // TODO(viettrungluu): Try testing SSL somehow.
168
169 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( 199 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket(
170 pp::TCPSocketPrivate* socket, 200 pp::TCPSocketPrivate* socket,
171 std::string* s) { 201 std::string* s) {
172 char buffer[10000]; 202 char buffer[10000];
173 203
174 s->clear(); 204 s->clear();
175 // Make sure we don't just hang if |Read()| spews. 205 // Make sure we don't just hang if |Read()| spews.
176 while (s->size() < 1000000) { 206 while (s->size() < 1000000) {
177 TestCompletionCallback cb(instance_->pp_instance(), force_async_); 207 TestCompletionCallback cb(instance_->pp_instance(), force_async_);
178 int32_t rv = socket->Read(buffer, sizeof(buffer), cb); 208 int32_t rv = socket->Read(buffer, sizeof(buffer), cb);
(...skipping 29 matching lines...) Expand all
208 if (rv < 0) 238 if (rv < 0)
209 return rv; 239 return rv;
210 if (rv == 0) 240 if (rv == 0)
211 return PP_ERROR_FAILED; 241 return PP_ERROR_FAILED;
212 written += rv; 242 written += rv;
213 } 243 }
214 if (written != s.size()) 244 if (written != s.size())
215 return PP_ERROR_FAILED; 245 return PP_ERROR_FAILED;
216 return PP_OK; 246 return PP_OK;
217 } 247 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698