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

Side by Side Diff: content/browser/fileapi/upload_file_system_file_element_reader_unittest.cc

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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
OLDNEW
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/fileapi/upload_file_system_file_element_reader.h" 5 #include "content/browser/fileapi/upload_file_system_file_element_reader.h"
6 6
7 #include <limits>
8
7 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 11 #include "base/run_loop.h"
10 #include "content/public/test/async_file_test_helper.h" 12 #include "content/public/test/async_file_test_helper.h"
11 #include "content/public/test/test_file_system_context.h" 13 #include "content/public/test/test_file_system_context.h"
12 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
13 #include "net/base/test_completion_callback.h" 15 #include "net/base/test_completion_callback.h"
14 #include "storage/browser/fileapi/file_system_backend.h" 16 #include "storage/browser/fileapi/file_system_backend.h"
15 #include "storage/browser/fileapi/file_system_context.h" 17 #include "storage/browser/fileapi/file_system_context.h"
16 #include "storage/browser/fileapi/file_system_operation_context.h" 18 #include "storage/browser/fileapi/file_system_operation_context.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 55
54 // Prepare a file on file system. 56 // Prepare a file on file system.
55 const char kTestData[] = "abcdefghijklmnop0123456789"; 57 const char kTestData[] = "abcdefghijklmnop0123456789";
56 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1); 58 file_data_.assign(kTestData, kTestData + arraysize(kTestData) - 1);
57 const char kFilename[] = "File.dat"; 59 const char kFilename[] = "File.dat";
58 file_url_ = GetFileSystemURL(kFilename); 60 file_url_ = GetFileSystemURL(kFilename);
59 WriteFileSystemFile(kFilename, &file_data_[0], file_data_.size(), 61 WriteFileSystemFile(kFilename, &file_data_[0], file_data_.size(),
60 &file_modification_time_); 62 &file_modification_time_);
61 63
62 // Create and initialize a reader. 64 // Create and initialize a reader.
63 reader_.reset( 65 reader_.reset(new UploadFileSystemFileElementReader(
64 new UploadFileSystemFileElementReader(file_system_context_.get(), 66 file_system_context_.get(), file_url_, 0,
65 file_url_, 67 std::numeric_limits<uint64_t>::max(), file_modification_time_));
66 0,
67 kuint64max,
68 file_modification_time_));
69 net::TestCompletionCallback callback; 68 net::TestCompletionCallback callback;
70 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(callback.callback())); 69 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(callback.callback()));
71 EXPECT_EQ(net::OK, callback.WaitForResult()); 70 EXPECT_EQ(net::OK, callback.WaitForResult());
72 EXPECT_EQ(file_data_.size(), reader_->GetContentLength()); 71 EXPECT_EQ(file_data_.size(), reader_->GetContentLength());
73 EXPECT_EQ(file_data_.size(), reader_->BytesRemaining()); 72 EXPECT_EQ(file_data_.size(), reader_->BytesRemaining());
74 EXPECT_FALSE(reader_->IsInMemory()); 73 EXPECT_FALSE(reader_->IsInMemory());
75 } 74 }
76 75
77 void TearDown() override { 76 void TearDown() override {
78 reader_.reset(); 77 reader_.reset();
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 236 }
238 237
239 TEST_F(UploadFileSystemFileElementReaderTest, Range) { 238 TEST_F(UploadFileSystemFileElementReaderTest, Range) {
240 const int kOffset = 2; 239 const int kOffset = 2;
241 const int kLength = file_data_.size() - kOffset * 3; 240 const int kLength = file_data_.size() - kOffset * 3;
242 reader_.reset(new UploadFileSystemFileElementReader( 241 reader_.reset(new UploadFileSystemFileElementReader(
243 file_system_context_.get(), file_url_, kOffset, kLength, base::Time())); 242 file_system_context_.get(), file_url_, kOffset, kLength, base::Time()));
244 net::TestCompletionCallback init_callback; 243 net::TestCompletionCallback init_callback;
245 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); 244 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback()));
246 EXPECT_EQ(net::OK, init_callback.WaitForResult()); 245 EXPECT_EQ(net::OK, init_callback.WaitForResult());
247 EXPECT_EQ(static_cast<uint64>(kLength), reader_->GetContentLength()); 246 EXPECT_EQ(static_cast<uint64_t>(kLength), reader_->GetContentLength());
248 EXPECT_EQ(static_cast<uint64>(kLength), reader_->BytesRemaining()); 247 EXPECT_EQ(static_cast<uint64_t>(kLength), reader_->BytesRemaining());
249 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(kLength); 248 scoped_refptr<net::IOBufferWithSize> buf = new net::IOBufferWithSize(kLength);
250 net::TestCompletionCallback read_callback; 249 net::TestCompletionCallback read_callback;
251 ASSERT_EQ(net::ERR_IO_PENDING, 250 ASSERT_EQ(net::ERR_IO_PENDING,
252 reader_->Read(buf.get(), buf->size(), read_callback.callback())); 251 reader_->Read(buf.get(), buf->size(), read_callback.callback()));
253 EXPECT_EQ(kLength, read_callback.WaitForResult()); 252 EXPECT_EQ(kLength, read_callback.WaitForResult());
254 EXPECT_TRUE(std::equal(file_data_.begin() + kOffset, 253 EXPECT_TRUE(std::equal(file_data_.begin() + kOffset,
255 file_data_.begin() + kOffset + kLength, 254 file_data_.begin() + kOffset + kLength,
256 buf->data())); 255 buf->data()));
257 } 256 }
258 257
259 TEST_F(UploadFileSystemFileElementReaderTest, FileChanged) { 258 TEST_F(UploadFileSystemFileElementReaderTest, FileChanged) {
260 // Expect one second before the actual modification time to simulate change. 259 // Expect one second before the actual modification time to simulate change.
261 const base::Time expected_modification_time = 260 const base::Time expected_modification_time =
262 file_modification_time_ - base::TimeDelta::FromSeconds(1); 261 file_modification_time_ - base::TimeDelta::FromSeconds(1);
263 reader_.reset( 262 reader_.reset(new UploadFileSystemFileElementReader(
264 new UploadFileSystemFileElementReader(file_system_context_.get(), 263 file_system_context_.get(), file_url_, 0,
265 file_url_, 264 std::numeric_limits<uint64_t>::max(), expected_modification_time));
266 0,
267 kuint64max,
268 expected_modification_time));
269 net::TestCompletionCallback init_callback; 265 net::TestCompletionCallback init_callback;
270 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); 266 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback()));
271 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult()); 267 EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, init_callback.WaitForResult());
272 } 268 }
273 269
274 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) { 270 TEST_F(UploadFileSystemFileElementReaderTest, WrongURL) {
275 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat"); 271 const GURL wrong_url = GetFileSystemURL("wrong_file_name.dat");
276 reader_.reset(new UploadFileSystemFileElementReader( 272 reader_.reset(new UploadFileSystemFileElementReader(
277 file_system_context_.get(), wrong_url, 0, kuint64max, base::Time())); 273 file_system_context_.get(), wrong_url, 0,
274 std::numeric_limits<uint64_t>::max(), base::Time()));
278 net::TestCompletionCallback init_callback; 275 net::TestCompletionCallback init_callback;
279 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback())); 276 ASSERT_EQ(net::ERR_IO_PENDING, reader_->Init(init_callback.callback()));
280 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult()); 277 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, init_callback.WaitForResult());
281 } 278 }
282 279
283 } // namespace content 280 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698