| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 net::TestCompletionCallback read_callback; | 142 net::TestCompletionCallback read_callback; |
| 143 int result = | 143 int result = |
| 144 upload->Read(io_buffer.get(), kBufferLength, read_callback.callback()); | 144 upload->Read(io_buffer.get(), kBufferLength, read_callback.callback()); |
| 145 EXPECT_EQ(static_cast<int>(kZeroLength), read_callback.GetResult(result)); | 145 EXPECT_EQ(static_cast<int>(kZeroLength), read_callback.GetResult(result)); |
| 146 | 146 |
| 147 base::DeleteFile(test_blob_path, false); | 147 base::DeleteFile(test_blob_path, false); |
| 148 } | 148 } |
| 149 // Clean up for ASAN. | 149 // Clean up for ASAN. |
| 150 base::RunLoop().RunUntilIdle(); | 150 base::RunLoop().RunUntilIdle(); |
| 151 } | 151 } |
| 152 | |
| 153 TEST(UploadDataStreamBuilderTest, ResetUploadStreamWithBlob) { | |
| 154 base::MessageLoopForIO message_loop; | |
| 155 { | |
| 156 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; | |
| 157 | |
| 158 const std::string kBlob = "blobuuid"; | |
| 159 const std::string kBlobData = "blobdata"; | |
| 160 const int kBlobDataLength = 8; | |
| 161 const int64 kIdentifier = 12345; | |
| 162 | |
| 163 BlobStorageContext blob_storage_context; | |
| 164 BlobDataBuilder builder(kBlob); | |
| 165 builder.AppendData(kBlobData); | |
| 166 scoped_ptr<BlobDataHandle> handle = | |
| 167 blob_storage_context.AddFinishedBlob(&builder); | |
| 168 request_body->AppendBlob(kBlob); | |
| 169 request_body->set_identifier(kIdentifier); | |
| 170 | |
| 171 scoped_ptr<net::UploadDataStream> upload(UploadDataStreamBuilder::Build( | |
| 172 request_body.get(), &blob_storage_context, nullptr, | |
| 173 base::ThreadTaskRunnerHandle::Get().get())); | |
| 174 | |
| 175 net::TestCompletionCallback init_callback; | |
| 176 ASSERT_EQ(net::OK, upload->Init(init_callback.callback())); | |
| 177 | |
| 178 // Read part of the data. | |
| 179 const int kBufferLength = 4; | |
| 180 scoped_refptr<net::IOBufferWithSize> buffer( | |
| 181 new net::IOBufferWithSize(kBufferLength)); | |
| 182 net::TestCompletionCallback read_callback; | |
| 183 int result = | |
| 184 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); | |
| 185 EXPECT_EQ(kBufferLength, read_callback.GetResult(result)); | |
| 186 EXPECT_EQ(0, | |
| 187 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); | |
| 188 | |
| 189 // Reset. | |
| 190 ASSERT_EQ(net::OK, upload->Init(init_callback.callback())); | |
| 191 | |
| 192 // Read all the data. | |
| 193 buffer = new net::IOBufferWithSize(kBlobDataLength); | |
| 194 result = | |
| 195 upload->Read(buffer.get(), buffer->size(), read_callback.callback()); | |
| 196 EXPECT_EQ(kBlobDataLength, read_callback.GetResult(result)); | |
| 197 EXPECT_EQ(0, | |
| 198 std::memcmp(kBlobData.c_str(), buffer->data(), buffer->size())); | |
| 199 } | |
| 200 // Clean up for ASAN. | |
| 201 base::RunLoop().RunUntilIdle(); | |
| 202 } | |
| 203 } // namespace content | 152 } // namespace content |
| OLD | NEW |