| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/loader/upload_data_stream_builder.h" | 5 #include "content/browser/loader/upload_data_stream_builder.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 request_body->AppendBlob(blob_id); | 129 request_body->AppendBlob(blob_id); |
| 130 | 130 |
| 131 upload = UploadDataStreamBuilder::Build( | 131 upload = UploadDataStreamBuilder::Build( |
| 132 request_body.get(), &blob_storage_context, NULL, | 132 request_body.get(), &blob_storage_context, NULL, |
| 133 base::ThreadTaskRunnerHandle::Get().get()); | 133 base::ThreadTaskRunnerHandle::Get().get()); |
| 134 ASSERT_TRUE(upload->GetElementReaders()); | 134 ASSERT_TRUE(upload->GetElementReaders()); |
| 135 const auto& readers = *upload->GetElementReaders(); | 135 const auto& readers = *upload->GetElementReaders(); |
| 136 ASSERT_EQ(3U, readers.size()); | 136 ASSERT_EQ(3U, readers.size()); |
| 137 | 137 |
| 138 net::TestCompletionCallback init_callback; | 138 net::TestCompletionCallback init_callback; |
| 139 ASSERT_EQ(net::ERR_IO_PENDING, upload->Init(init_callback.callback())); | 139 ASSERT_EQ(net::ERR_IO_PENDING, |
| 140 upload->Init(init_callback.callback(), net::BoundNetLog())); |
| 140 EXPECT_EQ(net::OK, init_callback.WaitForResult()); | 141 EXPECT_EQ(net::OK, init_callback.WaitForResult()); |
| 141 | 142 |
| 142 EXPECT_EQ(kZeroLength, upload->size()); | 143 EXPECT_EQ(kZeroLength, upload->size()); |
| 143 | 144 |
| 144 // Purposely (try to) read more than what is in the stream. If we try to | 145 // Purposely (try to) read more than what is in the stream. If we try to |
| 145 // read zero bytes then UploadDataStream::Read will fail a DCHECK. | 146 // read zero bytes then UploadDataStream::Read will fail a DCHECK. |
| 146 int kBufferLength = kZeroLength + 1; | 147 int kBufferLength = kZeroLength + 1; |
| 147 std::unique_ptr<char[]> buffer(new char[kBufferLength]); | 148 std::unique_ptr<char[]> buffer(new char[kBufferLength]); |
| 148 scoped_refptr<net::IOBuffer> io_buffer = | 149 scoped_refptr<net::IOBuffer> io_buffer = |
| 149 new net::WrappedIOBuffer(buffer.get()); | 150 new net::WrappedIOBuffer(buffer.get()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 176 blob_storage_context.AddFinishedBlob(&builder); | 177 blob_storage_context.AddFinishedBlob(&builder); |
| 177 request_body->AppendBlob(kBlob); | 178 request_body->AppendBlob(kBlob); |
| 178 request_body->set_identifier(kIdentifier); | 179 request_body->set_identifier(kIdentifier); |
| 179 | 180 |
| 180 std::unique_ptr<net::UploadDataStream> upload( | 181 std::unique_ptr<net::UploadDataStream> upload( |
| 181 UploadDataStreamBuilder::Build( | 182 UploadDataStreamBuilder::Build( |
| 182 request_body.get(), &blob_storage_context, nullptr, | 183 request_body.get(), &blob_storage_context, nullptr, |
| 183 base::ThreadTaskRunnerHandle::Get().get())); | 184 base::ThreadTaskRunnerHandle::Get().get())); |
| 184 | 185 |
| 185 net::TestCompletionCallback init_callback; | 186 net::TestCompletionCallback init_callback; |
| 186 ASSERT_EQ(net::OK, upload->Init(init_callback.callback())); | 187 ASSERT_EQ(net::OK, |
| 188 upload->Init(init_callback.callback(), net::BoundNetLog())); |
| 187 | 189 |
| 188 // Read part of the data. | 190 // Read part of the data. |
| 189 const int kBufferLength = 4; | 191 const int kBufferLength = 4; |
| 190 scoped_refptr<net::IOBufferWithSize> buffer( | 192 scoped_refptr<net::IOBufferWithSize> buffer( |
| 191 new net::IOBufferWithSize(kBufferLength)); | 193 new net::IOBufferWithSize(kBufferLength)); |
| 192 net::TestCompletionCallback read_callback; | 194 net::TestCompletionCallback read_callback; |
| 193 int result = | 195 int result = |
| 194 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); | 196 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); |
| 195 EXPECT_EQ(kBufferLength, read_callback.GetResult(result)); | 197 EXPECT_EQ(kBufferLength, read_callback.GetResult(result)); |
| 196 EXPECT_EQ(0, | 198 EXPECT_EQ(0, |
| 197 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); | 199 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); |
| 198 | 200 |
| 199 // Reset. | 201 // Reset. |
| 200 ASSERT_EQ(net::OK, upload->Init(init_callback.callback())); | 202 ASSERT_EQ(net::OK, |
| 203 upload->Init(init_callback.callback(), net::BoundNetLog())); |
| 201 | 204 |
| 202 // Read all the data. | 205 // Read all the data. |
| 203 buffer = new net::IOBufferWithSize(kBlobDataLength); | 206 buffer = new net::IOBufferWithSize(kBlobDataLength); |
| 204 result = | 207 result = |
| 205 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); | 208 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); |
| 206 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); | 209 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); |
| 207 EXPECT_EQ(0, | 210 EXPECT_EQ(0, |
| 208 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); | 211 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); |
| 209 } | 212 } |
| 210 // Clean up for ASAN. | 213 // Clean up for ASAN. |
| 211 base::RunLoop().RunUntilIdle(); | 214 base::RunLoop().RunUntilIdle(); |
| 212 } | 215 } |
| 213 } // namespace content | 216 } // namespace content |
| OLD | NEW |