OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "net/base/chunked_upload_data_stream.h" | 5 #include "net/base/chunked_upload_data_stream.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 stream.AppendData(kTestData, kTestDataSize, true); | 298 stream.AppendData(kTestData, kTestDataSize, true); |
299 EXPECT_FALSE(callback.have_result()); | 299 EXPECT_FALSE(callback.have_result()); |
300 | 300 |
301 std::string data = ReadSync(&stream, kTestBufferSize); | 301 std::string data = ReadSync(&stream, kTestBufferSize); |
302 EXPECT_EQ(kTestData, data); | 302 EXPECT_EQ(kTestData, data); |
303 EXPECT_EQ(kTestDataSize, stream.position()); | 303 EXPECT_EQ(kTestDataSize, stream.position()); |
304 ASSERT_TRUE(stream.IsEOF()); | 304 ASSERT_TRUE(stream.IsEOF()); |
305 EXPECT_FALSE(callback.have_result()); | 305 EXPECT_FALSE(callback.have_result()); |
306 } | 306 } |
307 | 307 |
| 308 // Check the behavior of ChunkedUploadDataStream::Writer. |
| 309 TEST(ChunkedUploadDataStreamTest, ChunkedUploadDataStreamWriter) { |
| 310 scoped_ptr<ChunkedUploadDataStream> stream(new ChunkedUploadDataStream(0)); |
| 311 scoped_ptr<ChunkedUploadDataStream::Writer> writer(stream->CreateWriter()); |
| 312 |
| 313 // Write before Init. |
| 314 ASSERT_TRUE(writer->AppendData(kTestData, 1, false)); |
| 315 ASSERT_EQ(OK, stream->Init(TestCompletionCallback().callback())); |
| 316 |
| 317 // Write after Init. |
| 318 ASSERT_TRUE(writer->AppendData(kTestData + 1, kTestDataSize - 1, false)); |
| 319 |
| 320 TestCompletionCallback callback; |
| 321 std::string data = ReadSync(stream.get(), kTestBufferSize); |
| 322 EXPECT_EQ(kTestData, data); |
| 323 |
| 324 // Writing data should gracefully fail if the stream is deleted while still |
| 325 // appending data to it. |
| 326 stream.reset(); |
| 327 EXPECT_FALSE(writer->AppendData(kTestData, kTestDataSize, true)); |
| 328 } |
| 329 |
308 } // namespace net | 330 } // namespace net |
OLD | NEW |