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(SetSocketFeature, 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 |
| 165 std::string TestTCPSocketPrivate::TestSetSocketFeature() { |
| 166 pp::TCPSocketPrivate socket(instance_); |
| 167 TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
| 168 |
| 169 int32_t rv = socket.SetSocketFeature(PP_TCPSOCKETFEATURE_NO_DELAY, true, cb); |
| 170 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 171 if (rv == PP_OK_COMPLETIONPENDING) |
| 172 rv = cb.WaitForResult(); |
| 173 ASSERT_EQ(PP_OK, rv); |
| 174 |
| 175 rv = socket.SetSocketFeature(PP_TCPSOCKETFEATURE_INVALID, true, cb); |
| 176 ASSERT_TRUE(!force_async_ || rv == PP_OK_COMPLETIONPENDING); |
| 177 if (rv == PP_OK_COMPLETIONPENDING) |
| 178 rv = cb.WaitForResult(); |
| 179 ASSERT_EQ(PP_ERROR_FAILED, rv); |
| 180 |
| 181 PASS(); |
| 182 } |
| 183 |
163 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( | 184 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( |
164 pp::TCPSocketPrivate* socket, | 185 pp::TCPSocketPrivate* socket, |
165 std::string* s) { | 186 std::string* s) { |
166 char buffer[10000]; | 187 char buffer[10000]; |
167 | 188 |
168 s->clear(); | 189 s->clear(); |
169 // Make sure we don't just hang if |Read()| spews. | 190 // Make sure we don't just hang if |Read()| spews. |
170 while (s->size() < 1000000) { | 191 while (s->size() < 1000000) { |
171 TestCompletionCallback cb(instance_->pp_instance(), force_async_); | 192 TestCompletionCallback cb(instance_->pp_instance(), force_async_); |
172 int32_t rv = socket->Read(buffer, sizeof(buffer), cb); | 193 int32_t rv = socket->Read(buffer, sizeof(buffer), cb); |
(...skipping 29 matching lines...) Expand all Loading... |
202 if (rv < 0) | 223 if (rv < 0) |
203 return rv; | 224 return rv; |
204 if (rv == 0) | 225 if (rv == 0) |
205 return PP_ERROR_FAILED; | 226 return PP_ERROR_FAILED; |
206 written += rv; | 227 written += rv; |
207 } | 228 } |
208 if (written != s.size()) | 229 if (written != s.size()) |
209 return PP_ERROR_FAILED; | 230 return PP_ERROR_FAILED; |
210 return PP_OK; | 231 return PP_OK; |
211 } | 232 } |
OLD | NEW |