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

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

Issue 22923014: TCPSockets are switched to the new Pepper proxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync. Created 7 years, 3 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) 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 <new>
10
9 #include "ppapi/cpp/private/tcp_socket_private.h" 11 #include "ppapi/cpp/private/tcp_socket_private.h"
12 #include "ppapi/tests/test_utils.h"
10 #include "ppapi/tests/testing_instance.h" 13 #include "ppapi/tests/testing_instance.h"
11 #include "ppapi/tests/test_utils.h"
12 14
13 namespace { 15 namespace {
14 16
15 // Validates the first line of an HTTP response. 17 // Validates the first line of an HTTP response.
16 bool ValidateHttpResponse(const std::string& s) { 18 bool ValidateHttpResponse(const std::string& s) {
17 // Just check that it begins with "HTTP/" and ends with a "\r\n". 19 // Just check that it begins with "HTTP/" and ends with a "\r\n".
18 return s.size() >= 5 && 20 return s.size() >= 5 &&
19 s.substr(0, 5) == "HTTP/" && 21 s.substr(0, 5) == "HTTP/" &&
20 s.substr(s.size() - 2) == "\r\n"; 22 s.substr(s.size() - 2) == "\r\n";
21 } 23 }
(...skipping 23 matching lines...) Expand all
45 47
46 return true; 48 return true;
47 } 49 }
48 50
49 void TestTCPSocketPrivate::RunTests(const std::string& filter) { 51 void TestTCPSocketPrivate::RunTests(const std::string& filter) {
50 RUN_CALLBACK_TEST(TestTCPSocketPrivate, Basic, filter); 52 RUN_CALLBACK_TEST(TestTCPSocketPrivate, Basic, filter);
51 RUN_CALLBACK_TEST(TestTCPSocketPrivate, ReadWrite, filter); 53 RUN_CALLBACK_TEST(TestTCPSocketPrivate, ReadWrite, filter);
52 RUN_CALLBACK_TEST(TestTCPSocketPrivate, ReadWriteSSL, filter); 54 RUN_CALLBACK_TEST(TestTCPSocketPrivate, ReadWriteSSL, filter);
53 RUN_CALLBACK_TEST(TestTCPSocketPrivate, ConnectAddress, filter); 55 RUN_CALLBACK_TEST(TestTCPSocketPrivate, ConnectAddress, filter);
54 RUN_CALLBACK_TEST(TestTCPSocketPrivate, SetOption, filter); 56 RUN_CALLBACK_TEST(TestTCPSocketPrivate, SetOption, filter);
57 RUN_CALLBACK_TEST(TestTCPSocketPrivate, LargeRead, filter);
55 } 58 }
56 59
57 std::string TestTCPSocketPrivate::TestBasic() { 60 std::string TestTCPSocketPrivate::TestBasic() {
58 pp::TCPSocketPrivate socket(instance_); 61 pp::TCPSocketPrivate socket(instance_);
59 TestCompletionCallback cb(instance_->pp_instance(), callback_type()); 62 TestCompletionCallback cb(instance_->pp_instance(), callback_type());
60 63
61 cb.WaitForResult(socket.Connect(host_.c_str(), port_, cb.GetCallback())); 64 cb.WaitForResult(socket.Connect(host_.c_str(), port_, cb.GetCallback()));
62 CHECK_CALLBACK_BEHAVIOR(cb); 65 CHECK_CALLBACK_BEHAVIOR(cb);
63 ASSERT_EQ(PP_OK, cb.result()); 66 ASSERT_EQ(PP_OK, cb.result());
64 67
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 socket.SetOption(PP_TCPSOCKETOPTION_PRIVATE_INVALID, true, 177 socket.SetOption(PP_TCPSOCKETOPTION_PRIVATE_INVALID, true,
175 cb.GetCallback())); 178 cb.GetCallback()));
176 CHECK_CALLBACK_BEHAVIOR(cb); 179 CHECK_CALLBACK_BEHAVIOR(cb);
177 ASSERT_EQ(PP_ERROR_BADARGUMENT, cb.result()); 180 ASSERT_EQ(PP_ERROR_BADARGUMENT, cb.result());
178 181
179 socket.Disconnect(); 182 socket.Disconnect();
180 183
181 PASS(); 184 PASS();
182 } 185 }
183 186
187 std::string TestTCPSocketPrivate::TestLargeRead() {
188 pp::TCPSocketPrivate socket(instance_);
189 {
190 TestCompletionCallback cb(instance_->pp_instance(), callback_type());
191
192 cb.WaitForResult(socket.Connect(host_.c_str(), port_, cb.GetCallback()));
193 CHECK_CALLBACK_BEHAVIOR(cb);
194 ASSERT_EQ(PP_OK, cb.result());
195 }
196
197 ASSERT_EQ(PP_OK, WriteStringToSocket(&socket, "GET / HTTP/1.0\r\n\r\n"));
198
199 const size_t kReadSize = 1024 * 1024 + 32;
200 // Create large buffer in heap to prevent run-time errors related to
201 // limits on stack size.
202 char* buffer = new (std::nothrow) char[kReadSize];
203 ASSERT_TRUE(buffer != NULL);
204
205 TestCompletionCallback cb(instance_->pp_instance(), callback_type());
206 cb.WaitForResult(socket.Read(buffer, kReadSize * sizeof(*buffer),
207 cb.GetCallback()));
208 CHECK_CALLBACK_BEHAVIOR(cb);
209 ASSERT_LE(0, cb.result());
210
211 delete [] buffer;
212
213 PASS();
214 }
215
184 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket( 216 int32_t TestTCPSocketPrivate::ReadFirstLineFromSocket(
185 pp::TCPSocketPrivate* socket, 217 pp::TCPSocketPrivate* socket,
186 std::string* s) { 218 std::string* s) {
187 char buffer[10000]; 219 char buffer[10000];
188 220
189 s->clear(); 221 s->clear();
190 // Make sure we don't just hang if |Read()| spews. 222 // Make sure we don't just hang if |Read()| spews.
191 while (s->size() < 1000000) { 223 while (s->size() < 1000000) {
192 TestCompletionCallback cb(instance_->pp_instance(), callback_type()); 224 TestCompletionCallback cb(instance_->pp_instance(), callback_type());
193 int32_t rv = socket->Read(buffer, sizeof(buffer), cb.GetCallback()); 225 int32_t rv = socket->Read(buffer, sizeof(buffer), cb.GetCallback());
(...skipping 28 matching lines...) Expand all
222 if (cb.result() < 0) 254 if (cb.result() < 0)
223 return cb.result(); 255 return cb.result();
224 if (cb.result() == 0) 256 if (cb.result() == 0)
225 return PP_ERROR_FAILED; 257 return PP_ERROR_FAILED;
226 written += cb.result(); 258 written += cb.result();
227 } 259 }
228 if (written != s.size()) 260 if (written != s.size())
229 return PP_ERROR_FAILED; 261 return PP_ERROR_FAILED;
230 return PP_OK; 262 return PP_OK;
231 } 263 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_tcp_socket_private.h ('k') | ppapi/thunk/interfaces_ppb_private_no_permissions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698