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 "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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 ssl_port_ = instance_->ssl_server_port(); | 44 ssl_port_ = instance_->ssl_server_port(); |
45 | 45 |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 void TestTCPSocketPrivate::RunTests(const std::string& filter) { | 49 void TestTCPSocketPrivate::RunTests(const std::string& filter) { |
50 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); | 50 RUN_TEST_FORCEASYNC_AND_NOT(Basic, filter); |
51 RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter); | 51 RUN_TEST_FORCEASYNC_AND_NOT(ReadWrite, filter); |
52 RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSSL, filter); | 52 RUN_TEST_FORCEASYNC_AND_NOT(ReadWriteSSL, filter); |
53 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter); | 53 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAddress, filter); |
| 54 RUN_TEST_FORCEASYNC_AND_NOT(SetOption, filter); |
54 } | 55 } |
55 | 56 |
56 std::string TestTCPSocketPrivate::TestBasic() { | 57 std::string TestTCPSocketPrivate::TestBasic() { |
57 pp::TCPSocketPrivate socket(instance_); | 58 pp::TCPSocketPrivate socket(instance_); |
58 TestCompletionCallback cb(instance_->pp_instance(), force_async_); | 59 TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
59 | 60 |
60 int32_t rv = socket.Connect(host_.c_str(), port_, cb); | 61 int32_t rv = socket.Connect(host_.c_str(), port_, cb); |
61 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); | 62 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
62 if (rv == PP_OK_COMPLETIONPENDING) | 63 if (rv == PP_OK_COMPLETIONPENDING) |
63 rv = cb.WaitForResult(); | 64 rv = cb.WaitForResult(); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n")); | 154 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n")); |
154 std::string s; | 155 std::string s; |
155 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); | 156 ASSERT_EQ(PP_OK, ReadFirstLineFromSocket(&socket, &s)); |
156 ASSERT_TRUE(ValidateHttpResponse(s)); | 157 ASSERT_TRUE(ValidateHttpResponse(s)); |
157 | 158 |
158 socket.Disconnect(); | 159 socket.Disconnect(); |
159 | 160 |
160 PASS(); | 161 PASS(); |
161 } | 162 } |
162 | 163 |
| 164 std::string TestTCPSocketPrivate::TestSetOption() { |
| 165 pp::TCPSocketPrivate socket(instance_); |
| 166 TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
| 167 |
| 168 int32_t rv = socket.SetOption(PP_TCPSOCKETOPTION_NO_DELAY, true, cb); |
| 169 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 170 if (rv == PP_OK_COMPLETIONPENDING) |
| 171 rv = cb.WaitForResult(); |
| 172 ASSERT_EQ(PP_ERROR_FAILED, rv); |
| 173 |
| 174 rv = socket.Connect(host_.c_str(), port_, cb); |
| 175 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 176 if (rv == PP_OK_COMPLETIONPENDING) |
| 177 rv = cb.WaitForResult(); |
| 178 ASSERT_EQ(PP_OK, rv); |
| 179 |
| 180 rv = socket.SetOption(PP_TCPSOCKETOPTION_NO_DELAY, true, cb); |
| 181 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 182 if (rv == PP_OK_COMPLETIONPENDING) |
| 183 rv = cb.WaitForResult(); |
| 184 ASSERT_EQ(PP_OK, rv); |
| 185 |
| 186 rv = socket.SetOption(PP_TCPSOCKETOPTION_INVALID, true, cb); |
| 187 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 188 if (rv == PP_OK_COMPLETIONPENDING) |
| 189 rv = cb.WaitForResult(); |
| 190 ASSERT_EQ(PP_ERROR_BADARGUMENT, rv); |
| 191 |
| 192 socket.Disconnect(); |
| 193 |
| 194 PASS(); |
| 195 } |
| 196 |
163 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( | 197 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( |
164 pp::TCPSocketPrivate* socket, | 198 pp::TCPSocketPrivate* socket, |
165 std::string* s) { | 199 std::string* s) { |
166 char buffer[10000]; | 200 char buffer[10000]; |
167 | 201 |
168 s->clear(); | 202 s->clear(); |
169 // Make sure we don't just hang if |Read()| spews. | 203 // Make sure we don't just hang if |Read()| spews. |
170 while (s->size() < 1000000) { | 204 while (s->size() < 1000000) { |
171 TestCompletionCallback cb(instance_->pp_instance(), force_async_); | 205 TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
172 int32_t rv = socket->Read(buffer, sizeof(buffer), cb); | 206 int32_t rv = socket->Read(buffer, sizeof(buffer), cb); |
(...skipping 29 matching lines...) Expand all Loading... |
202 if (rv < 0) | 236 if (rv < 0) |
203 return rv; | 237 return rv; |
204 if (rv == 0) | 238 if (rv == 0) |
205 return PP_ERROR_FAILED; | 239 return PP_ERROR_FAILED; |
206 written += rv; | 240 written += rv; |
207 } | 241 } |
208 if (written != s.size()) | 242 if (written != s.size()) |
209 return PP_ERROR_FAILED; | 243 return PP_ERROR_FAILED; |
210 return PP_OK; | 244 return PP_OK; |
211 } | 245 } |
OLD | NEW |