| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import <Foundation/Foundation.h> | 5 #import <Foundation/Foundation.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 #include <list> | 7 #include <list> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 test.response_headers[kHelloHeaderName]); | 431 test.response_headers[kHelloHeaderName]); |
| 432 ASSERT_EQ(TestBidirectionalStreamCallback::ON_SUCCEEDED, test.response_step); | 432 ASSERT_EQ(TestBidirectionalStreamCallback::ON_SUCCEEDED, test.response_step); |
| 433 ASSERT_EQ(std::string(kHelloBodyValue), base::JoinString(test.read_data, "")); | 433 ASSERT_EQ(std::string(kHelloBodyValue), base::JoinString(test.read_data, "")); |
| 434 ASSERT_EQ(std::string(kHelloTrailerValue), | 434 ASSERT_EQ(std::string(kHelloTrailerValue), |
| 435 test.response_trailers[kHelloTrailerName]); | 435 test.response_trailers[kHelloTrailerName]); |
| 436 // Flush after done is ignored. | 436 // Flush after done is ignored. |
| 437 cronet_bidirectional_stream_flush(test.stream); | 437 cronet_bidirectional_stream_flush(test.stream); |
| 438 cronet_bidirectional_stream_destroy(test.stream); | 438 cronet_bidirectional_stream_destroy(test.stream); |
| 439 } | 439 } |
| 440 | 440 |
| 441 TEST_P(CronetBidirectionalStreamTest, TestDelayedFlush) { |
| 442 class CustomTestBidirectionalStreamCallback |
| 443 : public TestBidirectionalStreamCallback { |
| 444 void MaybeWriteNextData(cronet_bidirectional_stream* stream) override { |
| 445 DCHECK_EQ(stream, this->stream); |
| 446 if (write_data.empty()) |
| 447 return; |
| 448 // Write all buffers when stream is ready. |
| 449 // Flush after "3" and "5". |
| 450 // EndOfStream is set with "6" but not flushed, so it is not sent. |
| 451 if (write_data.front()->buffer == "1") { |
| 452 for (const auto& data : write_data) { |
| 453 cronet_bidirectional_stream_write(stream, data->buffer.c_str(), |
| 454 data->buffer.size(), |
| 455 data == write_data.back()); |
| 456 if (data->flush) { |
| 457 cronet_bidirectional_stream_flush(stream); |
| 458 } |
| 459 } |
| 460 } |
| 461 // Flush the final buffer with endOfStream flag. |
| 462 if (write_data.front()->buffer == "6") |
| 463 cronet_bidirectional_stream_flush(stream); |
| 464 } |
| 465 }; |
| 466 |
| 467 CustomTestBidirectionalStreamCallback test; |
| 468 test.AddWriteData("1", false); |
| 469 test.AddWriteData("2", false); |
| 470 test.AddWriteData("3", true); |
| 471 test.AddWriteData("4", false); |
| 472 test.AddWriteData("5", true); |
| 473 test.AddWriteData("6", false); |
| 474 test.stream = |
| 475 cronet_bidirectional_stream_create(engine(), &test, test.callback()); |
| 476 DCHECK(test.stream); |
| 477 cronet_bidirectional_stream_disable_auto_flush(test.stream, true); |
| 478 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, |
| 479 GetParam()); |
| 480 // Flush before start is ignored. |
| 481 cronet_bidirectional_stream_flush(test.stream); |
| 482 cronet_bidirectional_stream_start(test.stream, kTestServerUrl, 0, "POST", |
| 483 &kTestHeadersArray, false); |
| 484 test.BlockForDone(); |
| 485 // Flush after done is ignored. |
| 486 cronet_bidirectional_stream_flush(test.stream); |
| 487 cronet_bidirectional_stream_destroy(test.stream); |
| 488 } |
| 489 |
| 441 TEST_P(CronetBidirectionalStreamTest, CancelOnRead) { | 490 TEST_P(CronetBidirectionalStreamTest, CancelOnRead) { |
| 442 TestBidirectionalStreamCallback test; | 491 TestBidirectionalStreamCallback test; |
| 443 test.stream = | 492 test.stream = |
| 444 cronet_bidirectional_stream_create(engine(), &test, test.callback()); | 493 cronet_bidirectional_stream_create(engine(), &test, test.callback()); |
| 445 DCHECK(test.stream); | 494 DCHECK(test.stream); |
| 446 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, | 495 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, |
| 447 GetParam()); | 496 GetParam()); |
| 448 test.cancel_from_step = TestBidirectionalStreamCallback::ON_READ_COMPLETED; | 497 test.cancel_from_step = TestBidirectionalStreamCallback::ON_READ_COMPLETED; |
| 449 cronet_bidirectional_stream_start(test.stream, kTestServerUrl, 0, "POST", | 498 cronet_bidirectional_stream_start(test.stream, kTestServerUrl, 0, "POST", |
| 450 &kTestHeadersArray, true); | 499 &kTestHeadersArray, true); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 ASSERT_EQ(TestBidirectionalStreamCallback::ON_FAILED, test.response_step); | 650 ASSERT_EQ(TestBidirectionalStreamCallback::ON_FAILED, test.response_step); |
| 602 ASSERT_EQ(net::ERR_NAME_NOT_RESOLVED, test.net_error); | 651 ASSERT_EQ(net::ERR_NAME_NOT_RESOLVED, test.net_error); |
| 603 cronet_bidirectional_stream_destroy(test.stream); | 652 cronet_bidirectional_stream_destroy(test.stream); |
| 604 } | 653 } |
| 605 | 654 |
| 606 INSTANTIATE_TEST_CASE_P(CronetBidirectionalStreamDelayRequestHeadersUntilFlush, | 655 INSTANTIATE_TEST_CASE_P(CronetBidirectionalStreamDelayRequestHeadersUntilFlush, |
| 607 CronetBidirectionalStreamTest, | 656 CronetBidirectionalStreamTest, |
| 608 ::testing::Values(true, false)); | 657 ::testing::Values(true, false)); |
| 609 | 658 |
| 610 } // namespace cronet | 659 } // namespace cronet |
| OLD | NEW |