| 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 #include "content/child/url_response_body_consumer.h" | 5 #include "content/child/url_response_body_consumer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 data_pipe.producer_handle.reset(); | 258 data_pipe.producer_handle.reset(); |
| 259 consumer->OnComplete(status); | 259 consumer->OnComplete(status); |
| 260 | 260 |
| 261 Run(&context); | 261 Run(&context); |
| 262 | 262 |
| 263 EXPECT_TRUE(context.complete); | 263 EXPECT_TRUE(context.complete); |
| 264 EXPECT_EQ(net::ERR_FAILED, context.error_code); | 264 EXPECT_EQ(net::ERR_FAILED, context.error_code); |
| 265 EXPECT_EQ("", context.data); | 265 EXPECT_EQ("", context.data); |
| 266 } | 266 } |
| 267 | 267 |
| 268 TEST_F(URLResponseBodyConsumerTest, TooBigChunkShouldBeSplit) { |
| 269 constexpr auto kMaxNumConsumedBytesInTask = |
| 270 URLResponseBodyConsumer::kMaxNumConsumedBytesInTask; |
| 271 TestRequestPeer::Context context; |
| 272 std::unique_ptr<ResourceRequest> request(CreateResourceRequest()); |
| 273 int request_id = SetUpRequestPeer(std::move(request), &context); |
| 274 auto options = CreateDataPipeOptions(); |
| 275 options.capacity_num_bytes = 2 * kMaxNumConsumedBytesInTask; |
| 276 mojo::DataPipe data_pipe(options); |
| 277 |
| 278 mojo::ScopedDataPipeProducerHandle writer = |
| 279 std::move(data_pipe.producer_handle); |
| 280 void* buffer = nullptr; |
| 281 uint32_t size = 0; |
| 282 MojoResult result = |
| 283 mojo::BeginWriteDataRaw(writer.get(), &buffer, &size, kNone); |
| 284 |
| 285 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 286 ASSERT_EQ(options.capacity_num_bytes, size); |
| 287 |
| 288 memset(buffer, 'a', kMaxNumConsumedBytesInTask); |
| 289 memset(static_cast<char*>(buffer) + kMaxNumConsumedBytesInTask, 'b', |
| 290 kMaxNumConsumedBytesInTask); |
| 291 |
| 292 result = mojo::EndWriteDataRaw(writer.get(), size); |
| 293 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 294 |
| 295 scoped_refptr<URLResponseBodyConsumer> consumer(new URLResponseBodyConsumer( |
| 296 request_id, dispatcher_.get(), std::move(data_pipe.consumer_handle), |
| 297 message_loop_.task_runner())); |
| 298 |
| 299 Run(&context); |
| 300 EXPECT_EQ(std::string(kMaxNumConsumedBytesInTask, 'a'), context.data); |
| 301 context.data.clear(); |
| 302 |
| 303 Run(&context); |
| 304 EXPECT_EQ(std::string(kMaxNumConsumedBytesInTask, 'b'), context.data); |
| 305 } |
| 306 |
| 268 } // namespace | 307 } // namespace |
| 269 | 308 |
| 270 } // namespace content | 309 } // namespace content |
| OLD | NEW |