Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(79)

Side by Side Diff: net/base/upload_file_element_reader_unittest.cc

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/upload_data_stream_unittest.cc ('k') | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/upload_file_element_reader.h" 5 #include "net/base/upload_file_element_reader.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
(...skipping 12 matching lines...) Expand all
23 bytes_.assign(kData, kData + arraysize(kData) - 1); 23 bytes_.assign(kData, kData + arraysize(kData) - 1);
24 24
25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 25 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
26 26
27 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(), 27 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_dir_.path(),
28 &temp_file_path_)); 28 &temp_file_path_));
29 ASSERT_EQ( 29 ASSERT_EQ(
30 static_cast<int>(bytes_.size()), 30 static_cast<int>(bytes_.size()),
31 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size())); 31 file_util::WriteFile(temp_file_path_, &bytes_[0], bytes_.size()));
32 32
33 reader_.reset(new UploadFileElementReader( 33 reader_.reset(
34 base::MessageLoopProxy::current(), 34 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
35 temp_file_path_, 0, kuint64max, base::Time())); 35 temp_file_path_,
36 0,
37 kuint64max,
38 base::Time()));
36 TestCompletionCallback callback; 39 TestCompletionCallback callback;
37 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback())); 40 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(callback.callback()));
38 EXPECT_EQ(OK, callback.WaitForResult()); 41 EXPECT_EQ(OK, callback.WaitForResult());
39 EXPECT_EQ(bytes_.size(), reader_->GetContentLength()); 42 EXPECT_EQ(bytes_.size(), reader_->GetContentLength());
40 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining()); 43 EXPECT_EQ(bytes_.size(), reader_->BytesRemaining());
41 EXPECT_FALSE(reader_->IsInMemory()); 44 EXPECT_FALSE(reader_->IsInMemory());
42 } 45 }
43 46
44 std::vector<char> bytes_; 47 std::vector<char> bytes_;
45 scoped_ptr<UploadElementReader> reader_; 48 scoped_ptr<UploadElementReader> reader_;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 buf2); 166 buf2);
164 167
165 // Make sure callbacks are not called for cancelled operations. 168 // Make sure callbacks are not called for cancelled operations.
166 EXPECT_FALSE(read_callback1.have_result()); 169 EXPECT_FALSE(read_callback1.have_result());
167 EXPECT_FALSE(init_callback1.have_result()); 170 EXPECT_FALSE(init_callback1.have_result());
168 } 171 }
169 172
170 TEST_F(UploadFileElementReaderTest, Range) { 173 TEST_F(UploadFileElementReaderTest, Range) {
171 const uint64 kOffset = 2; 174 const uint64 kOffset = 2;
172 const uint64 kLength = bytes_.size() - kOffset * 3; 175 const uint64 kLength = bytes_.size() - kOffset * 3;
173 reader_.reset(new UploadFileElementReader( 176 reader_.reset(
174 base::MessageLoopProxy::current(), 177 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
175 temp_file_path_, kOffset, kLength, base::Time())); 178 temp_file_path_,
179 kOffset,
180 kLength,
181 base::Time()));
176 TestCompletionCallback init_callback; 182 TestCompletionCallback init_callback;
177 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); 183 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback()));
178 EXPECT_EQ(OK, init_callback.WaitForResult()); 184 EXPECT_EQ(OK, init_callback.WaitForResult());
179 EXPECT_EQ(kLength, reader_->GetContentLength()); 185 EXPECT_EQ(kLength, reader_->GetContentLength());
180 EXPECT_EQ(kLength, reader_->BytesRemaining()); 186 EXPECT_EQ(kLength, reader_->BytesRemaining());
181 std::vector<char> buf(kLength); 187 std::vector<char> buf(kLength);
182 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]); 188 scoped_refptr<IOBuffer> wrapped_buffer = new WrappedIOBuffer(&buf[0]);
183 TestCompletionCallback read_callback; 189 TestCompletionCallback read_callback;
184 ASSERT_EQ( 190 ASSERT_EQ(
185 ERR_IO_PENDING, 191 ERR_IO_PENDING,
186 reader_->Read(wrapped_buffer.get(), kLength, read_callback.callback())); 192 reader_->Read(wrapped_buffer.get(), kLength, read_callback.callback()));
187 EXPECT_EQ(static_cast<int>(kLength), read_callback.WaitForResult()); 193 EXPECT_EQ(static_cast<int>(kLength), read_callback.WaitForResult());
188 const std::vector<char> expected(bytes_.begin() + kOffset, 194 const std::vector<char> expected(bytes_.begin() + kOffset,
189 bytes_.begin() + kOffset + kLength); 195 bytes_.begin() + kOffset + kLength);
190 EXPECT_EQ(expected, buf); 196 EXPECT_EQ(expected, buf);
191 } 197 }
192 198
193 TEST_F(UploadFileElementReaderTest, FileChanged) { 199 TEST_F(UploadFileElementReaderTest, FileChanged) {
194 base::PlatformFileInfo info; 200 base::PlatformFileInfo info;
195 ASSERT_TRUE(file_util::GetFileInfo(temp_file_path_, &info)); 201 ASSERT_TRUE(file_util::GetFileInfo(temp_file_path_, &info));
196 202
197 // Expect one second before the actual modification time to simulate change. 203 // Expect one second before the actual modification time to simulate change.
198 const base::Time expected_modification_time = 204 const base::Time expected_modification_time =
199 info.last_modified - base::TimeDelta::FromSeconds(1); 205 info.last_modified - base::TimeDelta::FromSeconds(1);
200 reader_.reset(new UploadFileElementReader( 206 reader_.reset(
201 base::MessageLoopProxy::current(), 207 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
202 temp_file_path_, 0, kuint64max, expected_modification_time)); 208 temp_file_path_,
209 0,
210 kuint64max,
211 expected_modification_time));
203 TestCompletionCallback init_callback; 212 TestCompletionCallback init_callback;
204 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); 213 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback()));
205 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); 214 EXPECT_EQ(ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult());
206 } 215 }
207 216
208 TEST_F(UploadFileElementReaderTest, WrongPath) { 217 TEST_F(UploadFileElementReaderTest, WrongPath) {
209 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); 218 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path"));
210 reader_.reset(new UploadFileElementReader( 219 reader_.reset(
211 base::MessageLoopProxy::current(), 220 new UploadFileElementReader(base::MessageLoopProxy::current().get(),
212 wrong_path, 0, kuint64max, base::Time())); 221 wrong_path,
222 0,
223 kuint64max,
224 base::Time()));
213 TestCompletionCallback init_callback; 225 TestCompletionCallback init_callback;
214 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback())); 226 ASSERT_EQ(ERR_IO_PENDING, reader_->Init(init_callback.callback()));
215 EXPECT_EQ(OK, init_callback.WaitForResult()); 227 EXPECT_EQ(OK, init_callback.WaitForResult());
216 EXPECT_EQ(0U, reader_->GetContentLength()); 228 EXPECT_EQ(0U, reader_->GetContentLength());
217 EXPECT_EQ(0U, reader_->BytesRemaining()); 229 EXPECT_EQ(0U, reader_->BytesRemaining());
218 } 230 }
219 231
220 232
221 class UploadFileElementReaderSyncTest : public PlatformTest { 233 class UploadFileElementReaderSyncTest : public PlatformTest {
222 protected: 234 protected:
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 TEST_F(UploadFileElementReaderSyncTest, WrongPath) { 358 TEST_F(UploadFileElementReaderSyncTest, WrongPath) {
347 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path")); 359 const base::FilePath wrong_path(FILE_PATH_LITERAL("wrong_path"));
348 reader_.reset(new UploadFileElementReaderSync( 360 reader_.reset(new UploadFileElementReaderSync(
349 wrong_path, 0, kuint64max, base::Time())); 361 wrong_path, 0, kuint64max, base::Time()));
350 ASSERT_EQ(OK, reader_->Init(CompletionCallback())); 362 ASSERT_EQ(OK, reader_->Init(CompletionCallback()));
351 EXPECT_EQ(0U, reader_->GetContentLength()); 363 EXPECT_EQ(0U, reader_->GetContentLength());
352 EXPECT_EQ(0U, reader_->BytesRemaining()); 364 EXPECT_EQ(0U, reader_->BytesRemaining());
353 } 365 }
354 366
355 } // namespace net 367 } // namespace net
OLDNEW
« no previous file with comments | « net/base/upload_data_stream_unittest.cc ('k') | net/disk_cache/backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698