Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / net / socket / deterministic_socket_data_unittest.cc
blobaea81603f9bce77f9032c5a270fdf567b9b630ae
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
3 // found in the LICENSE file.
5 #include "net/socket/socket_test_util.h"
7 #include <string.h>
9 #include "base/memory/ref_counted.h"
10 #include "testing/platform_test.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 //-----------------------------------------------------------------------------
15 namespace {
17 static const char kMsg1[] = "\0hello!\xff";
18 static const int kLen1 = arraysize(kMsg1);
19 static const char kMsg2[] = "\012345678\0";
20 static const int kLen2 = arraysize(kMsg2);
21 static const char kMsg3[] = "bye!";
22 static const int kLen3 = arraysize(kMsg3);
24 } // anonymous namespace
26 namespace net {
28 class DeterministicSocketDataTest : public PlatformTest {
29 public:
30 DeterministicSocketDataTest();
32 virtual void TearDown();
34 void ReentrantReadCallback(int len, int rv);
35 void ReentrantWriteCallback(const char* data, int len, int rv);
37 protected:
38 void Initialize(MockRead* reads, size_t reads_count, MockWrite* writes,
39 size_t writes_count);
41 void AssertSyncReadEquals(const char* data, int len);
42 void AssertAsyncReadEquals(const char* data, int len);
43 void AssertReadReturns(const char* data, int len, int rv);
44 void AssertReadBufferEquals(const char* data, int len);
46 void AssertSyncWriteEquals(const char* data, int len);
47 void AssertAsyncWriteEquals(const char* data, int len);
48 void AssertWriteReturns(const char* data, int len, int rv);
50 TestCompletionCallback read_callback_;
51 TestCompletionCallback write_callback_;
52 StreamSocket* sock_;
53 scoped_ptr<DeterministicSocketData> data_;
55 private:
56 scoped_refptr<IOBuffer> read_buf_;
57 MockConnect connect_data_;
59 HostPortPair endpoint_;
60 scoped_refptr<TransportSocketParams> tcp_params_;
61 ClientSocketPoolHistograms histograms_;
62 DeterministicMockClientSocketFactory socket_factory_;
63 MockTransportClientSocketPool socket_pool_;
64 ClientSocketHandle connection_;
66 DISALLOW_COPY_AND_ASSIGN(DeterministicSocketDataTest);
69 DeterministicSocketDataTest::DeterministicSocketDataTest()
70 : sock_(NULL),
71 data_(NULL),
72 read_buf_(NULL),
73 connect_data_(SYNCHRONOUS, OK),
74 endpoint_("www.google.com", 443),
75 tcp_params_(new TransportSocketParams(endpoint_,
76 LOWEST,
77 false,
78 false,
79 OnHostResolutionCallback())),
80 histograms_(std::string()),
81 socket_pool_(10, 10, &histograms_, &socket_factory_) {}
83 void DeterministicSocketDataTest::TearDown() {
84 // Empty the current queue.
85 MessageLoop::current()->RunUntilIdle();
86 PlatformTest::TearDown();
89 void DeterministicSocketDataTest::Initialize(MockRead* reads,
90 size_t reads_count,
91 MockWrite* writes,
92 size_t writes_count) {
93 data_.reset(new DeterministicSocketData(reads, reads_count,
94 writes, writes_count));
95 data_->set_connect_data(connect_data_);
96 socket_factory_.AddSocketDataProvider(data_.get());
98 // Perform the TCP connect
99 EXPECT_EQ(OK,
100 connection_.Init(endpoint_.ToString(),
101 tcp_params_,
102 LOWEST,
103 CompletionCallback(),
104 reinterpret_cast<TransportClientSocketPool*>(&socket_pool_),
105 BoundNetLog()));
106 sock_ = connection_.socket();
109 void DeterministicSocketDataTest::AssertSyncReadEquals(const char* data,
110 int len) {
111 // Issue the read, which will complete immediately
112 AssertReadReturns(data, len, len);
113 AssertReadBufferEquals(data, len);
116 void DeterministicSocketDataTest::AssertAsyncReadEquals(const char* data,
117 int len) {
118 // Issue the read, which will be completed asynchronously
119 AssertReadReturns(data, len, ERR_IO_PENDING);
121 EXPECT_FALSE(read_callback_.have_result());
122 EXPECT_TRUE(sock_->IsConnected());
123 data_->RunFor(1); // Runs 1 step, to cause the callbacks to be invoked
125 // Now the read should complete
126 ASSERT_EQ(len, read_callback_.WaitForResult());
127 AssertReadBufferEquals(data, len);
130 void DeterministicSocketDataTest::AssertReadReturns(const char* data,
131 int len, int rv) {
132 read_buf_ = new IOBuffer(len);
133 ASSERT_EQ(rv, sock_->Read(read_buf_, len, read_callback_.callback()));
136 void DeterministicSocketDataTest::AssertReadBufferEquals(const char* data,
137 int len) {
138 ASSERT_EQ(std::string(data, len), std::string(read_buf_->data(), len));
141 void DeterministicSocketDataTest::AssertSyncWriteEquals(const char* data,
142 int len) {
143 scoped_refptr<IOBuffer> buf(new IOBuffer(len));
144 memcpy(buf->data(), data, len);
146 // Issue the write, which will complete immediately
147 ASSERT_EQ(len, sock_->Write(buf, len, write_callback_.callback()));
150 void DeterministicSocketDataTest::AssertAsyncWriteEquals(const char* data,
151 int len) {
152 // Issue the read, which will be completed asynchronously
153 AssertWriteReturns(data, len, ERR_IO_PENDING);
155 EXPECT_FALSE(read_callback_.have_result());
156 EXPECT_TRUE(sock_->IsConnected());
157 data_->RunFor(1); // Runs 1 step, to cause the callbacks to be invoked
159 ASSERT_EQ(len, write_callback_.WaitForResult());
162 void DeterministicSocketDataTest::AssertWriteReturns(const char* data,
163 int len, int rv) {
164 scoped_refptr<IOBuffer> buf(new IOBuffer(len));
165 memcpy(buf->data(), data, len);
167 // Issue the read, which will complete asynchronously
168 ASSERT_EQ(rv, sock_->Write(buf, len, write_callback_.callback()));
171 void DeterministicSocketDataTest::ReentrantReadCallback(int len, int rv) {
172 scoped_refptr<IOBuffer> read_buf(new IOBuffer(len));
173 EXPECT_EQ(len, sock_->Read(read_buf, len,
174 base::Bind(&DeterministicSocketDataTest::ReentrantReadCallback,
175 base::Unretained(this), len)));
178 void DeterministicSocketDataTest::ReentrantWriteCallback(
179 const char* data, int len, int rv) {
180 scoped_refptr<IOBuffer> write_buf(new IOBuffer(len));
181 memcpy(write_buf->data(), data, len);
182 EXPECT_EQ(len, sock_->Write(write_buf, len,
183 base::Bind(&DeterministicSocketDataTest::ReentrantWriteCallback,
184 base::Unretained(this), data, len)));
187 // ----------- Read
189 TEST_F(DeterministicSocketDataTest, SingleSyncReadWhileStopped) {
190 MockRead reads[] = {
191 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
192 MockRead(SYNCHRONOUS, 0, 1), // EOF
195 Initialize(reads, arraysize(reads), NULL, 0);
197 data_->SetStopped(true);
198 AssertReadReturns(kMsg1, kLen1, ERR_UNEXPECTED);
201 TEST_F(DeterministicSocketDataTest, SingleSyncReadTooEarly) {
202 MockRead reads[] = {
203 MockRead(SYNCHRONOUS, kMsg1, kLen1, 1), // Sync Read
204 MockRead(SYNCHRONOUS, 0, 2), // EOF
207 MockWrite writes[] = {
208 MockWrite(SYNCHRONOUS, 0, 0)
211 Initialize(reads, arraysize(reads), writes, arraysize(writes));
213 data_->StopAfter(2);
214 ASSERT_FALSE(data_->stopped());
215 AssertReadReturns(kMsg1, kLen1, ERR_UNEXPECTED);
218 TEST_F(DeterministicSocketDataTest, SingleSyncRead) {
219 MockRead reads[] = {
220 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
221 MockRead(SYNCHRONOUS, 0, 1), // EOF
224 Initialize(reads, arraysize(reads), NULL, 0);
225 // Make sure we don't stop before we've read all the data
226 data_->StopAfter(1);
227 AssertSyncReadEquals(kMsg1, kLen1);
230 TEST_F(DeterministicSocketDataTest, MultipleSyncReads) {
231 MockRead reads[] = {
232 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
233 MockRead(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Read
234 MockRead(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Read
235 MockRead(SYNCHRONOUS, kMsg3, kLen3, 3), // Sync Read
236 MockRead(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Read
237 MockRead(SYNCHRONOUS, kMsg3, kLen3, 5), // Sync Read
238 MockRead(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Read
239 MockRead(SYNCHRONOUS, 0, 7), // EOF
242 Initialize(reads, arraysize(reads), NULL, 0);
244 // Make sure we don't stop before we've read all the data
245 data_->StopAfter(10);
246 AssertSyncReadEquals(kMsg1, kLen1);
247 AssertSyncReadEquals(kMsg2, kLen2);
248 AssertSyncReadEquals(kMsg3, kLen3);
249 AssertSyncReadEquals(kMsg3, kLen3);
250 AssertSyncReadEquals(kMsg2, kLen2);
251 AssertSyncReadEquals(kMsg3, kLen3);
252 AssertSyncReadEquals(kMsg1, kLen1);
255 TEST_F(DeterministicSocketDataTest, SingleAsyncRead) {
256 MockRead reads[] = {
257 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
258 MockRead(SYNCHRONOUS, 0, 1), // EOF
261 Initialize(reads, arraysize(reads), NULL, 0);
263 AssertAsyncReadEquals(kMsg1, kLen1);
266 TEST_F(DeterministicSocketDataTest, MultipleAsyncReads) {
267 MockRead reads[] = {
268 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
269 MockRead(ASYNC, kMsg2, kLen2, 1), // Async Read
270 MockRead(ASYNC, kMsg3, kLen3, 2), // Async Read
271 MockRead(ASYNC, kMsg3, kLen3, 3), // Async Read
272 MockRead(ASYNC, kMsg2, kLen2, 4), // Async Read
273 MockRead(ASYNC, kMsg3, kLen3, 5), // Async Read
274 MockRead(ASYNC, kMsg1, kLen1, 6), // Async Read
275 MockRead(SYNCHRONOUS, 0, 7), // EOF
278 Initialize(reads, arraysize(reads), NULL, 0);
280 AssertAsyncReadEquals(kMsg1, kLen1);
281 AssertAsyncReadEquals(kMsg2, kLen2);
282 AssertAsyncReadEquals(kMsg3, kLen3);
283 AssertAsyncReadEquals(kMsg3, kLen3);
284 AssertAsyncReadEquals(kMsg2, kLen2);
285 AssertAsyncReadEquals(kMsg3, kLen3);
286 AssertAsyncReadEquals(kMsg1, kLen1);
289 TEST_F(DeterministicSocketDataTest, MixedReads) {
290 MockRead reads[] = {
291 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
292 MockRead(ASYNC, kMsg2, kLen2, 1), // Async Read
293 MockRead(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Read
294 MockRead(ASYNC, kMsg3, kLen3, 3), // Async Read
295 MockRead(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Read
296 MockRead(ASYNC, kMsg3, kLen3, 5), // Async Read
297 MockRead(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Read
298 MockRead(SYNCHRONOUS, 0, 7), // EOF
301 Initialize(reads, arraysize(reads), NULL, 0);
303 data_->StopAfter(1);
304 AssertSyncReadEquals(kMsg1, kLen1);
305 AssertAsyncReadEquals(kMsg2, kLen2);
306 data_->StopAfter(1);
307 AssertSyncReadEquals(kMsg3, kLen3);
308 AssertAsyncReadEquals(kMsg3, kLen3);
309 data_->StopAfter(1);
310 AssertSyncReadEquals(kMsg2, kLen2);
311 AssertAsyncReadEquals(kMsg3, kLen3);
312 data_->StopAfter(1);
313 AssertSyncReadEquals(kMsg1, kLen1);
316 TEST_F(DeterministicSocketDataTest, SyncReadFromCompletionCallback) {
317 MockRead reads[] = {
318 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
319 MockRead(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Read
322 Initialize(reads, arraysize(reads), NULL, 0);
324 data_->StopAfter(2);
326 scoped_refptr<IOBuffer> read_buf(new IOBuffer(kLen1));
327 ASSERT_EQ(ERR_IO_PENDING, sock_->Read(read_buf, kLen1,
328 base::Bind(&DeterministicSocketDataTest::ReentrantReadCallback,
329 base::Unretained(this), kLen2)));
330 data_->Run();
333 // ----------- Write
335 TEST_F(DeterministicSocketDataTest, SingleSyncWriteWhileStopped) {
336 MockWrite writes[] = {
337 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
340 Initialize(NULL, 0, writes, arraysize(writes));
342 data_->SetStopped(true);
343 AssertWriteReturns(kMsg1, kLen1, ERR_UNEXPECTED);
346 TEST_F(DeterministicSocketDataTest, SingleSyncWriteTooEarly) {
347 MockWrite writes[] = {
348 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 1), // Sync Write
351 MockRead reads[] = {
352 MockRead(SYNCHRONOUS, 0, 0)
355 Initialize(reads, arraysize(reads), writes, arraysize(writes));
357 data_->StopAfter(2);
358 ASSERT_FALSE(data_->stopped());
359 AssertWriteReturns(kMsg1, kLen1, ERR_UNEXPECTED);
362 TEST_F(DeterministicSocketDataTest, SingleSyncWrite) {
363 MockWrite writes[] = {
364 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Write
367 Initialize(NULL, 0, writes, arraysize(writes));
369 // Make sure we don't stop before we've read all the data
370 data_->StopAfter(1);
371 AssertSyncWriteEquals(kMsg1, kLen1);
374 TEST_F(DeterministicSocketDataTest, MultipleSyncWrites) {
375 MockWrite writes[] = {
376 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Write
377 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Write
378 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
379 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 3), // Sync Write
380 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Write
381 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 5), // Sync Write
382 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Write
385 Initialize(NULL, 0, writes, arraysize(writes));
387 // Make sure we don't stop before we've read all the data
388 data_->StopAfter(10);
389 AssertSyncWriteEquals(kMsg1, kLen1);
390 AssertSyncWriteEquals(kMsg2, kLen2);
391 AssertSyncWriteEquals(kMsg3, kLen3);
392 AssertSyncWriteEquals(kMsg3, kLen3);
393 AssertSyncWriteEquals(kMsg2, kLen2);
394 AssertSyncWriteEquals(kMsg3, kLen3);
395 AssertSyncWriteEquals(kMsg1, kLen1);
398 TEST_F(DeterministicSocketDataTest, SingleAsyncWrite) {
399 MockWrite writes[] = {
400 MockWrite(ASYNC, kMsg1, kLen1, 0), // Async Write
403 Initialize(NULL, 0, writes, arraysize(writes));
405 AssertAsyncWriteEquals(kMsg1, kLen1);
408 TEST_F(DeterministicSocketDataTest, MultipleAsyncWrites) {
409 MockWrite writes[] = {
410 MockWrite(ASYNC, kMsg1, kLen1, 0), // Async Write
411 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
412 MockWrite(ASYNC, kMsg3, kLen3, 2), // Async Write
413 MockWrite(ASYNC, kMsg3, kLen3, 3), // Async Write
414 MockWrite(ASYNC, kMsg2, kLen2, 4), // Async Write
415 MockWrite(ASYNC, kMsg3, kLen3, 5), // Async Write
416 MockWrite(ASYNC, kMsg1, kLen1, 6), // Async Write
419 Initialize(NULL, 0, writes, arraysize(writes));
421 AssertAsyncWriteEquals(kMsg1, kLen1);
422 AssertAsyncWriteEquals(kMsg2, kLen2);
423 AssertAsyncWriteEquals(kMsg3, kLen3);
424 AssertAsyncWriteEquals(kMsg3, kLen3);
425 AssertAsyncWriteEquals(kMsg2, kLen2);
426 AssertAsyncWriteEquals(kMsg3, kLen3);
427 AssertAsyncWriteEquals(kMsg1, kLen1);
430 TEST_F(DeterministicSocketDataTest, MixedWrites) {
431 MockWrite writes[] = {
432 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Write
433 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
434 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
435 MockWrite(ASYNC, kMsg3, kLen3, 3), // Async Write
436 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 4), // Sync Write
437 MockWrite(ASYNC, kMsg3, kLen3, 5), // Async Write
438 MockWrite(SYNCHRONOUS, kMsg1, kLen1, 6), // Sync Write
441 Initialize(NULL, 0, writes, arraysize(writes));
443 data_->StopAfter(1);
444 AssertSyncWriteEquals(kMsg1, kLen1);
445 AssertAsyncWriteEquals(kMsg2, kLen2);
446 data_->StopAfter(1);
447 AssertSyncWriteEquals(kMsg3, kLen3);
448 AssertAsyncWriteEquals(kMsg3, kLen3);
449 data_->StopAfter(1);
450 AssertSyncWriteEquals(kMsg2, kLen2);
451 AssertAsyncWriteEquals(kMsg3, kLen3);
452 data_->StopAfter(1);
453 AssertSyncWriteEquals(kMsg1, kLen1);
456 TEST_F(DeterministicSocketDataTest, SyncWriteFromCompletionCallback) {
457 MockWrite writes[] = {
458 MockWrite(ASYNC, kMsg1, kLen1, 0), // Async Write
459 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Write
462 Initialize(NULL, 0, writes, arraysize(writes));
464 data_->StopAfter(2);
466 scoped_refptr<IOBuffer> write_buf(new IOBuffer(kLen1));
467 memcpy(write_buf->data(), kMsg1, kLen1);
468 ASSERT_EQ(ERR_IO_PENDING, sock_->Write(write_buf, kLen1,
469 base::Bind(&DeterministicSocketDataTest::ReentrantWriteCallback,
470 base::Unretained(this), kMsg2, kLen2)));
471 data_->Run();
474 // ----------- Mixed Reads and Writes
476 TEST_F(DeterministicSocketDataTest, MixedSyncOperations) {
477 MockRead reads[] = {
478 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
479 MockRead(SYNCHRONOUS, kMsg2, kLen2, 3), // Sync Read
480 MockRead(SYNCHRONOUS, 0, 4), // EOF
483 MockWrite writes[] = {
484 MockWrite(SYNCHRONOUS, kMsg2, kLen2, 1), // Sync Write
485 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
488 Initialize(reads, arraysize(reads), writes, arraysize(writes));
490 // Make sure we don't stop before we've read/written everything
491 data_->StopAfter(10);
492 AssertSyncReadEquals(kMsg1, kLen1);
493 AssertSyncWriteEquals(kMsg2, kLen2);
494 AssertSyncWriteEquals(kMsg3, kLen3);
495 AssertSyncReadEquals(kMsg2, kLen2);
498 TEST_F(DeterministicSocketDataTest, MixedAsyncOperations) {
499 MockRead reads[] = {
500 MockRead(ASYNC, kMsg1, kLen1, 0), // Sync Read
501 MockRead(ASYNC, kMsg2, kLen2, 3), // Sync Read
502 MockRead(ASYNC, 0, 4), // EOF
505 MockWrite writes[] = {
506 MockWrite(ASYNC, kMsg2, kLen2, 1), // Sync Write
507 MockWrite(ASYNC, kMsg3, kLen3, 2), // Sync Write
510 Initialize(reads, arraysize(reads), writes, arraysize(writes));
512 AssertAsyncReadEquals(kMsg1, kLen1);
513 AssertAsyncWriteEquals(kMsg2, kLen2);
514 AssertAsyncWriteEquals(kMsg3, kLen3);
515 AssertAsyncReadEquals(kMsg2, kLen2);
518 TEST_F(DeterministicSocketDataTest, InterleavedAsyncOperations) {
519 // Order of completion is read, write, write, read
520 MockRead reads[] = {
521 MockRead(ASYNC, kMsg1, kLen1, 0), // Async Read
522 MockRead(ASYNC, kMsg2, kLen2, 3), // Async Read
523 MockRead(ASYNC, 0, 4), // EOF
526 MockWrite writes[] = {
527 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
528 MockWrite(ASYNC, kMsg3, kLen3, 2), // Async Write
531 Initialize(reads, arraysize(reads), writes, arraysize(writes));
533 // Issue the write, which will block until the read completes
534 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING);
536 // Issue the read which will return first
537 AssertReadReturns(kMsg1, kLen1, ERR_IO_PENDING);
539 data_->RunFor(1);
540 ASSERT_TRUE(read_callback_.have_result());
541 ASSERT_EQ(kLen1, read_callback_.WaitForResult());
542 AssertReadBufferEquals(kMsg1, kLen1);
544 data_->RunFor(1);
545 ASSERT_TRUE(write_callback_.have_result());
546 ASSERT_EQ(kLen2, write_callback_.WaitForResult());
548 data_->StopAfter(1);
549 // Issue the read, which will block until the write completes
550 AssertReadReturns(kMsg2, kLen2, ERR_IO_PENDING);
552 // Issue the writes which will return first
553 AssertWriteReturns(kMsg3, kLen3, ERR_IO_PENDING);
555 data_->RunFor(1);
556 ASSERT_TRUE(write_callback_.have_result());
557 ASSERT_EQ(kLen3, write_callback_.WaitForResult());
559 data_->RunFor(1);
560 ASSERT_TRUE(read_callback_.have_result());
561 ASSERT_EQ(kLen2, read_callback_.WaitForResult());
562 AssertReadBufferEquals(kMsg2, kLen2);
565 TEST_F(DeterministicSocketDataTest, InterleavedMixedOperations) {
566 // Order of completion is read, write, write, read
567 MockRead reads[] = {
568 MockRead(SYNCHRONOUS, kMsg1, kLen1, 0), // Sync Read
569 MockRead(ASYNC, kMsg2, kLen2, 3), // Async Read
570 MockRead(SYNCHRONOUS, 0, 4), // EOF
573 MockWrite writes[] = {
574 MockWrite(ASYNC, kMsg2, kLen2, 1), // Async Write
575 MockWrite(SYNCHRONOUS, kMsg3, kLen3, 2), // Sync Write
578 Initialize(reads, arraysize(reads), writes, arraysize(writes));
580 // Issue the write, which will block until the read completes
581 AssertWriteReturns(kMsg2, kLen2, ERR_IO_PENDING);
583 // Issue the writes which will complete immediately
584 data_->StopAfter(1);
585 AssertSyncReadEquals(kMsg1, kLen1);
587 data_->RunFor(1);
588 ASSERT_TRUE(write_callback_.have_result());
589 ASSERT_EQ(kLen2, write_callback_.WaitForResult());
591 // Issue the read, which will block until the write completes
592 AssertReadReturns(kMsg2, kLen2, ERR_IO_PENDING);
594 // Issue the writes which will complete immediately
595 data_->StopAfter(1);
596 AssertSyncWriteEquals(kMsg3, kLen3);
598 data_->RunFor(1);
599 ASSERT_TRUE(read_callback_.have_result());
600 ASSERT_EQ(kLen2, read_callback_.WaitForResult());
601 AssertReadBufferEquals(kMsg2, kLen2);
604 } // namespace net