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

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

Issue 1549113002: Switch to standard integer types in content/browser/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 12 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
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 "storage/browser/fileapi/file_system_file_stream_reader.h" 5 #include "storage/browser/fileapi/file_system_file_stream_reader.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
7 #include <limits> 10 #include <limits>
8 #include <string> 11 #include <string>
9 12
10 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
12 #include "base/run_loop.h" 16 #include "base/run_loop.h"
13 #include "content/public/test/async_file_test_helper.h" 17 #include "content/public/test/async_file_test_helper.h"
14 #include "content/public/test/test_file_system_context.h" 18 #include "content/public/test/test_file_system_context.h"
15 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h" 21 #include "net/base/test_completion_callback.h"
18 #include "storage/browser/fileapi/external_mount_points.h" 22 #include "storage/browser/fileapi/external_mount_points.h"
19 #include "storage/browser/fileapi/file_system_context.h" 23 #include "storage/browser/fileapi/file_system_context.h"
20 #include "storage/browser/fileapi/file_system_file_util.h" 24 #include "storage/browser/fileapi/file_system_file_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 86
83 WriteFile(kTestFileName, kTestData, kTestDataSize, 87 WriteFile(kTestFileName, kTestData, kTestDataSize,
84 &test_file_modification_time_); 88 &test_file_modification_time_);
85 } 89 }
86 90
87 void TearDown() override { base::RunLoop().RunUntilIdle(); } 91 void TearDown() override { base::RunLoop().RunUntilIdle(); }
88 92
89 protected: 93 protected:
90 storage::FileSystemFileStreamReader* CreateFileReader( 94 storage::FileSystemFileStreamReader* CreateFileReader(
91 const std::string& file_name, 95 const std::string& file_name,
92 int64 initial_offset, 96 int64_t initial_offset,
93 const base::Time& expected_modification_time) { 97 const base::Time& expected_modification_time) {
94 return new FileSystemFileStreamReader(file_system_context_.get(), 98 return new FileSystemFileStreamReader(file_system_context_.get(),
95 GetFileSystemURL(file_name), 99 GetFileSystemURL(file_name),
96 initial_offset, 100 initial_offset,
97 expected_modification_time); 101 expected_modification_time);
98 } 102 }
99 103
100 base::Time test_file_modification_time() const { 104 base::Time test_file_modification_time() const {
101 return test_file_modification_time_; 105 return test_file_modification_time_;
102 } 106 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 160
157 scoped_ptr<FileSystemFileStreamReader> reader( 161 scoped_ptr<FileSystemFileStreamReader> reader(
158 CreateFileReader(kFileName, 0, base::Time())); 162 CreateFileReader(kFileName, 0, base::Time()));
159 int result = 0; 163 int result = 0;
160 std::string data; 164 std::string data;
161 ReadFromReader(reader.get(), &data, 10, &result); 165 ReadFromReader(reader.get(), &data, 10, &result);
162 ASSERT_EQ(net::OK, result); 166 ASSERT_EQ(net::OK, result);
163 ASSERT_EQ(0U, data.size()); 167 ASSERT_EQ(0U, data.size());
164 168
165 net::TestInt64CompletionCallback callback; 169 net::TestInt64CompletionCallback callback;
166 int64 length_result = reader->GetLength(callback.callback()); 170 int64_t length_result = reader->GetLength(callback.callback());
167 if (length_result == net::ERR_IO_PENDING) 171 if (length_result == net::ERR_IO_PENDING)
168 length_result = callback.WaitForResult(); 172 length_result = callback.WaitForResult();
169 ASSERT_EQ(0, length_result); 173 ASSERT_EQ(0, length_result);
170 } 174 }
171 175
172 TEST_F(FileSystemFileStreamReaderTest, GetLengthNormal) { 176 TEST_F(FileSystemFileStreamReaderTest, GetLengthNormal) {
173 scoped_ptr<FileSystemFileStreamReader> reader( 177 scoped_ptr<FileSystemFileStreamReader> reader(
174 CreateFileReader(kTestFileName, 0, test_file_modification_time())); 178 CreateFileReader(kTestFileName, 0, test_file_modification_time()));
175 net::TestInt64CompletionCallback callback; 179 net::TestInt64CompletionCallback callback;
176 int64 result = reader->GetLength(callback.callback()); 180 int64_t result = reader->GetLength(callback.callback());
177 if (result == net::ERR_IO_PENDING) 181 if (result == net::ERR_IO_PENDING)
178 result = callback.WaitForResult(); 182 result = callback.WaitForResult();
179 ASSERT_EQ(kTestDataSize, result); 183 ASSERT_EQ(kTestDataSize, result);
180 } 184 }
181 185
182 TEST_F(FileSystemFileStreamReaderTest, GetLengthAfterModified) { 186 TEST_F(FileSystemFileStreamReaderTest, GetLengthAfterModified) {
183 // Pass a fake expected modifictaion time so that the expectation fails. 187 // Pass a fake expected modifictaion time so that the expectation fails.
184 base::Time fake_expected_modification_time = 188 base::Time fake_expected_modification_time =
185 test_file_modification_time() - base::TimeDelta::FromSeconds(10); 189 test_file_modification_time() - base::TimeDelta::FromSeconds(10);
186 190
187 scoped_ptr<FileSystemFileStreamReader> reader( 191 scoped_ptr<FileSystemFileStreamReader> reader(
188 CreateFileReader(kTestFileName, 0, fake_expected_modification_time)); 192 CreateFileReader(kTestFileName, 0, fake_expected_modification_time));
189 net::TestInt64CompletionCallback callback; 193 net::TestInt64CompletionCallback callback;
190 int64 result = reader->GetLength(callback.callback()); 194 int64_t result = reader->GetLength(callback.callback());
191 if (result == net::ERR_IO_PENDING) 195 if (result == net::ERR_IO_PENDING)
192 result = callback.WaitForResult(); 196 result = callback.WaitForResult();
193 ASSERT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result); 197 ASSERT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);
194 198
195 // With NULL expected modification time this should work. 199 // With NULL expected modification time this should work.
196 reader.reset(CreateFileReader(kTestFileName, 0, base::Time())); 200 reader.reset(CreateFileReader(kTestFileName, 0, base::Time()));
197 result = reader->GetLength(callback.callback()); 201 result = reader->GetLength(callback.callback());
198 if (result == net::ERR_IO_PENDING) 202 if (result == net::ERR_IO_PENDING)
199 result = callback.WaitForResult(); 203 result = callback.WaitForResult();
200 ASSERT_EQ(kTestDataSize, result); 204 ASSERT_EQ(kTestDataSize, result);
201 } 205 }
202 206
203 TEST_F(FileSystemFileStreamReaderTest, GetLengthWithOffset) { 207 TEST_F(FileSystemFileStreamReaderTest, GetLengthWithOffset) {
204 scoped_ptr<FileSystemFileStreamReader> reader( 208 scoped_ptr<FileSystemFileStreamReader> reader(
205 CreateFileReader(kTestFileName, 3, base::Time())); 209 CreateFileReader(kTestFileName, 3, base::Time()));
206 net::TestInt64CompletionCallback callback; 210 net::TestInt64CompletionCallback callback;
207 int64 result = reader->GetLength(callback.callback()); 211 int64_t result = reader->GetLength(callback.callback());
208 if (result == net::ERR_IO_PENDING) 212 if (result == net::ERR_IO_PENDING)
209 result = callback.WaitForResult(); 213 result = callback.WaitForResult();
210 // Initial offset does not affect the result of GetLength. 214 // Initial offset does not affect the result of GetLength.
211 ASSERT_EQ(kTestDataSize, result); 215 ASSERT_EQ(kTestDataSize, result);
212 } 216 }
213 217
214 TEST_F(FileSystemFileStreamReaderTest, ReadNormal) { 218 TEST_F(FileSystemFileStreamReaderTest, ReadNormal) {
215 scoped_ptr<FileSystemFileStreamReader> reader( 219 scoped_ptr<FileSystemFileStreamReader> reader(
216 CreateFileReader(kTestFileName, 0, test_file_modification_time())); 220 CreateFileReader(kTestFileName, 0, test_file_modification_time()));
217 int result = 0; 221 int result = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 new net::IOBufferWithSize(kTestDataSize)); 265 new net::IOBufferWithSize(kTestDataSize));
262 int rv = reader->Read(buf.get(), buf->size(), base::Bind(&NeverCalled)); 266 int rv = reader->Read(buf.get(), buf->size(), base::Bind(&NeverCalled));
263 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0); 267 ASSERT_TRUE(rv == net::ERR_IO_PENDING || rv >= 0);
264 268
265 // Delete immediately. 269 // Delete immediately.
266 // Should not crash; nor should NeverCalled be callback. 270 // Should not crash; nor should NeverCalled be callback.
267 reader.reset(); 271 reader.reset();
268 } 272 }
269 273
270 } // namespace content 274 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698