| 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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 TestBidirectionalStreamCallback::WriteData::WriteData(const std::string& data, | 299 TestBidirectionalStreamCallback::WriteData::WriteData(const std::string& data, |
| 300 bool flush_after) | 300 bool flush_after) |
| 301 : buffer(data), flush(flush_after) {} | 301 : buffer(data), flush(flush_after) {} |
| 302 | 302 |
| 303 TestBidirectionalStreamCallback::WriteData::~WriteData() {} | 303 TestBidirectionalStreamCallback::WriteData::~WriteData() {} |
| 304 | 304 |
| 305 TEST_P(CronetBidirectionalStreamTest, StartExampleBidiStream) { | 305 TEST_P(CronetBidirectionalStreamTest, StartExampleBidiStream) { |
| 306 TestBidirectionalStreamCallback test; | 306 TestBidirectionalStreamCallback test; |
| 307 test.AddWriteData("Hello, "); | 307 test.AddWriteData("Hello, "); |
| 308 test.AddWriteData("world!"); | 308 test.AddWriteData("world!"); |
| 309 // Use small read buffer size to test that response is split properly. |
| 309 test.read_buffer_size = 2; | 310 test.read_buffer_size = 2; |
| 310 test.stream = | 311 test.stream = |
| 311 cronet_bidirectional_stream_create(engine(), &test, test.callback()); | 312 cronet_bidirectional_stream_create(engine(), &test, test.callback()); |
| 312 DCHECK(test.stream); | 313 DCHECK(test.stream); |
| 313 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, | 314 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, |
| 314 GetParam()); | 315 GetParam()); |
| 315 cronet_bidirectional_stream_start(test.stream, kTestServerUrl, 0, "POST", | 316 cronet_bidirectional_stream_start(test.stream, kTestServerUrl, 0, "POST", |
| 316 &kTestHeadersArray, false); | 317 &kTestHeadersArray, false); |
| 317 test.BlockForDone(); | 318 test.BlockForDone(); |
| 318 ASSERT_EQ(std::string(kHelloStatus), test.response_headers[kStatusHeader]); | 319 ASSERT_EQ(std::string(kHelloStatus), test.response_headers[kStatusHeader]); |
| 319 ASSERT_EQ(std::string(kHelloHeaderValue), | 320 ASSERT_EQ(std::string(kHelloHeaderValue), |
| 320 test.response_headers[kHelloHeaderName]); | 321 test.response_headers[kHelloHeaderName]); |
| 321 ASSERT_EQ(TestBidirectionalStreamCallback::ON_SUCCEEDED, test.response_step); | 322 ASSERT_EQ(TestBidirectionalStreamCallback::ON_SUCCEEDED, test.response_step); |
| 322 ASSERT_EQ(std::string(kHelloBodyValue, 2), test.read_data.front()); | 323 ASSERT_EQ(std::string(kHelloBodyValue, 2), test.read_data.front()); |
| 324 // Verify that individual read data joined using empty separator match |
| 325 // expected body. |
| 323 ASSERT_EQ(std::string(kHelloBodyValue), base::JoinString(test.read_data, "")); | 326 ASSERT_EQ(std::string(kHelloBodyValue), base::JoinString(test.read_data, "")); |
| 324 ASSERT_EQ(std::string(kHelloTrailerValue), | 327 ASSERT_EQ(std::string(kHelloTrailerValue), |
| 325 test.response_trailers[kHelloTrailerName]); | 328 test.response_trailers[kHelloTrailerName]); |
| 326 cronet_bidirectional_stream_destroy(test.stream); | 329 cronet_bidirectional_stream_destroy(test.stream); |
| 327 } | 330 } |
| 328 | 331 |
| 332 TEST_P(CronetBidirectionalStreamTest, SimplePutWithEmptyWriteDataAtTheEnd) { |
| 333 TestBidirectionalStreamCallback test; |
| 334 test.AddWriteData("Hello, "); |
| 335 test.AddWriteData("world!"); |
| 336 test.AddWriteData(""); |
| 337 test.stream = |
| 338 cronet_bidirectional_stream_create(engine(), &test, test.callback()); |
| 339 DCHECK(test.stream); |
| 340 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, |
| 341 GetParam()); |
| 342 cronet_bidirectional_stream_start(test.stream, kTestServerUrl, 0, "PUT", |
| 343 &kTestHeadersArray, false); |
| 344 test.BlockForDone(); |
| 345 ASSERT_EQ(std::string(kHelloStatus), test.response_headers[kStatusHeader]); |
| 346 ASSERT_EQ(std::string(kHelloHeaderValue), |
| 347 test.response_headers[kHelloHeaderName]); |
| 348 ASSERT_EQ(TestBidirectionalStreamCallback::ON_SUCCEEDED, test.response_step); |
| 349 ASSERT_EQ(std::string(kHelloBodyValue), test.read_data.front()); |
| 350 ASSERT_EQ(std::string(kHelloTrailerValue), |
| 351 test.response_trailers[kHelloTrailerName]); |
| 352 cronet_bidirectional_stream_destroy(test.stream); |
| 353 } |
| 354 |
| 329 TEST_P(CronetBidirectionalStreamTest, SimpleGetWithFlush) { | 355 TEST_P(CronetBidirectionalStreamTest, SimpleGetWithFlush) { |
| 330 TestBidirectionalStreamCallback test; | 356 TestBidirectionalStreamCallback test; |
| 331 test.stream = | 357 test.stream = |
| 332 cronet_bidirectional_stream_create(engine(), &test, test.callback()); | 358 cronet_bidirectional_stream_create(engine(), &test, test.callback()); |
| 333 DCHECK(test.stream); | 359 DCHECK(test.stream); |
| 334 cronet_bidirectional_stream_disable_auto_flush(test.stream, true); | 360 cronet_bidirectional_stream_disable_auto_flush(test.stream, true); |
| 335 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, | 361 cronet_bidirectional_stream_delay_request_headers_until_flush(test.stream, |
| 336 GetParam()); | 362 GetParam()); |
| 337 // Flush before start is ignored. | 363 // Flush before start is ignored. |
| 338 cronet_bidirectional_stream_flush(test.stream); | 364 cronet_bidirectional_stream_flush(test.stream); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 ASSERT_EQ(TestBidirectionalStreamCallback::ON_FAILED, test.response_step); | 676 ASSERT_EQ(TestBidirectionalStreamCallback::ON_FAILED, test.response_step); |
| 651 ASSERT_EQ(net::ERR_NAME_NOT_RESOLVED, test.net_error); | 677 ASSERT_EQ(net::ERR_NAME_NOT_RESOLVED, test.net_error); |
| 652 cronet_bidirectional_stream_destroy(test.stream); | 678 cronet_bidirectional_stream_destroy(test.stream); |
| 653 } | 679 } |
| 654 | 680 |
| 655 INSTANTIATE_TEST_CASE_P(CronetBidirectionalStreamDelayRequestHeadersUntilFlush, | 681 INSTANTIATE_TEST_CASE_P(CronetBidirectionalStreamDelayRequestHeadersUntilFlush, |
| 656 CronetBidirectionalStreamTest, | 682 CronetBidirectionalStreamTest, |
| 657 ::testing::Values(true, false)); | 683 ::testing::Values(true, false)); |
| 658 | 684 |
| 659 } // namespace cronet | 685 } // namespace cronet |
| OLD | NEW |