Chromium Code Reviews| 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, | |
| 154 ResetUploadStreamWithBlob) { | |
|
michaeln
2015/12/11 23:21:33
does this not fit on one line?
dmurph
2015/12/11 23:34:01
Done.
| |
| 155 base::MessageLoopForIO message_loop; | |
| 156 { | |
| 157 scoped_refptr<ResourceRequestBody> request_body = new ResourceRequestBody; | |
| 158 | |
| 159 const std::string kBlob = "blobuuid"; | |
| 160 const std::string kBlobData = "blobdata"; | |
| 161 const int64 kIdentifier = 12345; | |
| 162 | |
| 163 BlobStorageContext context; | |
|
mmenke
2015/12/11 23:15:45
May want to call this blob_storage_context. Match
dmurph
2015/12/11 23:34:01
Done.
| |
| 164 BlobDataBuilder builder(kBlob); | |
| 165 builder.AppendData(kBlobData); | |
| 166 scoped_ptr<BlobDataHandle> handle = context.AddFinishedBlob(&builder); | |
| 167 request_body->AppendBlob(kBlob); | |
| 168 request_body->set_identifier(kIdentifier); | |
| 169 | |
| 170 scoped_ptr<net::UploadDataStream> upload(UploadDataStreamBuilder::Build( | |
| 171 request_body.get(), &context, NULL, | |
|
mmenke
2015/12/11 23:15:45
nullptr
dmurph
2015/12/11 23:34:01
Done.
| |
| 172 base::ThreadTaskRunnerHandle::Get().get())); | |
| 173 | |
| 174 const storage::UploadBlobElementReader* r3 = | |
| 175 static_cast<storage::UploadBlobElementReader*>( | |
| 176 (*upload->GetElementReaders())[0].get()); | |
| 177 ASSERT_TRUE(r3); | |
|
mmenke
2015/12/11 23:15:45
This doesn't seem to get us anything.
michaeln
2015/12/11 23:21:33
right, the local var is not used
dmurph
2015/12/11 23:34:02
REmoved.
| |
| 178 | |
| 179 net::TestCompletionCallback init_callback; | |
| 180 ASSERT_EQ(net::OK, upload->Init(init_callback.callback())); | |
| 181 | |
| 182 // Read part of the data. | |
| 183 int kBufferLength = 4; | |
|
mmenke
2015/12/11 23:15:45
const
dmurph
2015/12/11 23:34:01
Done.
| |
| 184 scoped_ptr<char[]> buffer(new char[kBufferLength]); | |
|
mmenke
2015/12/11 23:15:45
scoped_array, or could just use IOBufferWithSize (
michaeln
2015/12/11 23:21:33
or you could put buffer on the stack, IOBufferWith
dmurph
2015/12/11 23:34:02
IMPOSSIBLE (refcounted ;)
Made it simpler though.
| |
| 185 scoped_refptr<net::IOBuffer> io_buffer = | |
| 186 new net::WrappedIOBuffer(buffer.get()); | |
| 187 net::TestCompletionCallback read_callback; | |
| 188 int result = | |
| 189 upload->Read(io_buffer.get(), kBufferLength, read_callback.callback()); | |
| 190 EXPECT_EQ(static_cast<int>(kBufferLength), read_callback.GetResult(result)); | |
|
mmenke
2015/12/11 23:15:45
kBufferLength is already an int.
dmurph
2015/12/11 23:34:02
Done.
| |
| 191 EXPECT_EQ(0, std::memcmp(kBlobData.c_str(), buffer.get(), kBufferLength)); | |
| 192 | |
| 193 // Reset. | |
| 194 ASSERT_EQ(net::OK, upload->Init(init_callback.callback())); | |
| 195 | |
| 196 // Read same part of data. | |
| 197 result = | |
| 198 upload->Read(io_buffer.get(), kBufferLength, read_callback.callback()); | |
| 199 EXPECT_EQ(static_cast<int>(kBufferLength), read_callback.GetResult(result)); | |
|
mmenke
2015/12/11 23:15:45
kBufferLength is already an int.
dmurph
2015/12/11 23:34:02
Done.
| |
| 200 EXPECT_EQ(0, std::memcmp(kBlobData.c_str(), buffer.get(), kBufferLength)); | |
|
mmenke
2015/12/11 23:15:45
Should we read the entire body here, just in case?
dmurph
2015/12/11 23:34:02
Sure.
| |
| 201 } | |
| 202 // Clean up for ASAN. | |
| 203 base::RunLoop().RunUntilIdle(); | |
| 204 } | |
| 152 } // namespace content | 205 } // namespace content |
| OLD | NEW |