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

Side by Side Diff: chrome/browser/chromeos/drive/fileapi_worker_unittest.cc

Issue 99923002: Move temp file functions to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
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 "chrome/browser/chromeos/drive/fileapi_worker.h" 5 #include "chrome/browser/chromeos/drive/fileapi_worker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 base::Bind(&GetFileSystem, static_cast<FileSystemInterface*>(NULL)), 163 base::Bind(&GetFileSystem, static_cast<FileSystemInterface*>(NULL)),
164 google_apis::test_util::CreateCopyResultCallback(&file_system), 164 google_apis::test_util::CreateCopyResultCallback(&file_system),
165 base::Closure()); 165 base::Closure());
166 } 166 }
167 167
168 TEST_F(FileApiWorkerTest, OpenFileForCreateWrite) { 168 TEST_F(FileApiWorkerTest, OpenFileForCreateWrite) {
169 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever"); 169 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever");
170 const std::string kWriteData = "byebye"; 170 const std::string kWriteData = "byebye";
171 171
172 base::FilePath temp_path; 172 base::FilePath temp_path;
173 file_util::CreateTemporaryFile(&temp_path); 173 base::CreateTemporaryFile(&temp_path);
174 174
175 // CREATE => CREATE (fails if file existed.) 175 // CREATE => CREATE (fails if file existed.)
176 TestFileSystemForOpenFile file_system(temp_path, CREATE_FILE); 176 TestFileSystemForOpenFile file_system(temp_path, CREATE_FILE);
177 const int64 kExpectedSize = 0; 177 const int64 kExpectedSize = 0;
178 178
179 OpenFile(kDummyPath, 179 OpenFile(kDummyPath,
180 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE, 180 base::PLATFORM_FILE_CREATE | base::PLATFORM_FILE_WRITE,
181 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData), 181 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData),
182 &file_system); 182 &file_system);
183 test_util::RunBlockingPoolTask(); 183 test_util::RunBlockingPoolTask();
184 EXPECT_TRUE(file_system.closed()); 184 EXPECT_TRUE(file_system.closed());
185 } 185 }
186 186
187 TEST_F(FileApiWorkerTest, OpenFileForOpenAlwaysWrite) { 187 TEST_F(FileApiWorkerTest, OpenFileForOpenAlwaysWrite) {
188 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever"); 188 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever");
189 const std::string kWriteData = "byebye"; 189 const std::string kWriteData = "byebye";
190 const std::string kInitialData = "hello"; 190 const std::string kInitialData = "hello";
191 191
192 base::FilePath temp_path; 192 base::FilePath temp_path;
193 file_util::CreateTemporaryFile(&temp_path); 193 base::CreateTemporaryFile(&temp_path);
194 google_apis::test_util::WriteStringToFile(temp_path, kInitialData); 194 google_apis::test_util::WriteStringToFile(temp_path, kInitialData);
195 195
196 // OPEN_ALWAYS => OPEN_OR_CREATE (success whether file exists or not.) 196 // OPEN_ALWAYS => OPEN_OR_CREATE (success whether file exists or not.)
197 // No truncation should take place. 197 // No truncation should take place.
198 TestFileSystemForOpenFile file_system(temp_path, OPEN_OR_CREATE_FILE); 198 TestFileSystemForOpenFile file_system(temp_path, OPEN_OR_CREATE_FILE);
199 const int64 kExpectedSize = static_cast<int64>(kInitialData.size()); 199 const int64 kExpectedSize = static_cast<int64>(kInitialData.size());
200 200
201 OpenFile(kDummyPath, 201 OpenFile(kDummyPath,
202 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE, 202 base::PLATFORM_FILE_OPEN_ALWAYS | base::PLATFORM_FILE_WRITE,
203 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData), 203 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData),
204 &file_system); 204 &file_system);
205 test_util::RunBlockingPoolTask(); 205 test_util::RunBlockingPoolTask();
206 EXPECT_TRUE(file_system.closed()); 206 EXPECT_TRUE(file_system.closed());
207 } 207 }
208 208
209 TEST_F(FileApiWorkerTest, OpenFileForOpenTruncatedWrite) { 209 TEST_F(FileApiWorkerTest, OpenFileForOpenTruncatedWrite) {
210 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever"); 210 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever");
211 const std::string kInitialData = "hello"; 211 const std::string kInitialData = "hello";
212 const std::string kWriteData = "byebye"; 212 const std::string kWriteData = "byebye";
213 213
214 base::FilePath temp_path; 214 base::FilePath temp_path;
215 file_util::CreateTemporaryFile(&temp_path); 215 base::CreateTemporaryFile(&temp_path);
216 google_apis::test_util::WriteStringToFile(temp_path, kInitialData); 216 google_apis::test_util::WriteStringToFile(temp_path, kInitialData);
217 217
218 // OPEN_TRUNCATED => OPEN (failure when the file did not exist.) 218 // OPEN_TRUNCATED => OPEN (failure when the file did not exist.)
219 // It should truncate the file before passing to the callback. 219 // It should truncate the file before passing to the callback.
220 TestFileSystemForOpenFile file_system(temp_path, OPEN_FILE); 220 TestFileSystemForOpenFile file_system(temp_path, OPEN_FILE);
221 const int64 kExpectedSize = 0; 221 const int64 kExpectedSize = 0;
222 222
223 OpenFile(kDummyPath, 223 OpenFile(kDummyPath,
224 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE, 224 base::PLATFORM_FILE_OPEN_TRUNCATED | base::PLATFORM_FILE_WRITE,
225 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData), 225 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData),
226 &file_system); 226 &file_system);
227 test_util::RunBlockingPoolTask(); 227 test_util::RunBlockingPoolTask();
228 EXPECT_TRUE(file_system.closed()); 228 EXPECT_TRUE(file_system.closed());
229 } 229 }
230 230
231 TEST_F(FileApiWorkerTest, OpenFileForOpenCreateAlwaysWrite) { 231 TEST_F(FileApiWorkerTest, OpenFileForOpenCreateAlwaysWrite) {
232 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever"); 232 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever");
233 const std::string kInitialData = "hello"; 233 const std::string kInitialData = "hello";
234 const std::string kWriteData = "byebye"; 234 const std::string kWriteData = "byebye";
235 235
236 base::FilePath temp_path; 236 base::FilePath temp_path;
237 file_util::CreateTemporaryFile(&temp_path); 237 base::CreateTemporaryFile(&temp_path);
238 google_apis::test_util::WriteStringToFile(temp_path, kInitialData); 238 google_apis::test_util::WriteStringToFile(temp_path, kInitialData);
239 239
240 // CREATE_ALWAYS => OPEN_OR_CREATE (success whether file exists or not.) 240 // CREATE_ALWAYS => OPEN_OR_CREATE (success whether file exists or not.)
241 // It should truncate the file before passing to the callback. 241 // It should truncate the file before passing to the callback.
242 TestFileSystemForOpenFile file_system(temp_path, OPEN_OR_CREATE_FILE); 242 TestFileSystemForOpenFile file_system(temp_path, OPEN_OR_CREATE_FILE);
243 const int64 kExpectedSize = 0; 243 const int64 kExpectedSize = 0;
244 244
245 OpenFile(kDummyPath, 245 OpenFile(kDummyPath,
246 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE, 246 base::PLATFORM_FILE_CREATE_ALWAYS | base::PLATFORM_FILE_WRITE,
247 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData), 247 base::Bind(&VerifyWrite, kExpectedSize, temp_path, kWriteData),
248 &file_system); 248 &file_system);
249 test_util::RunBlockingPoolTask(); 249 test_util::RunBlockingPoolTask();
250 EXPECT_TRUE(file_system.closed()); 250 EXPECT_TRUE(file_system.closed());
251 } 251 }
252 252
253 TEST_F(FileApiWorkerTest, OpenFileForOpenRead) { 253 TEST_F(FileApiWorkerTest, OpenFileForOpenRead) {
254 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever"); 254 const base::FilePath kDummyPath = base::FilePath::FromUTF8Unsafe("whatever");
255 const std::string kInitialData = "hello"; 255 const std::string kInitialData = "hello";
256 256
257 base::FilePath temp_path; 257 base::FilePath temp_path;
258 file_util::CreateTemporaryFile(&temp_path); 258 base::CreateTemporaryFile(&temp_path);
259 google_apis::test_util::WriteStringToFile(temp_path, kInitialData); 259 google_apis::test_util::WriteStringToFile(temp_path, kInitialData);
260 260
261 // OPEN => OPEN (failure when the file did not exist.) 261 // OPEN => OPEN (failure when the file did not exist.)
262 TestFileSystemForOpenFile file_system(temp_path, OPEN_FILE); 262 TestFileSystemForOpenFile file_system(temp_path, OPEN_FILE);
263 263
264 OpenFile(kDummyPath, 264 OpenFile(kDummyPath,
265 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, 265 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
266 base::Bind(&VerifyRead, kInitialData), 266 base::Bind(&VerifyRead, kInitialData),
267 &file_system); 267 &file_system);
268 test_util::RunBlockingPoolTask(); 268 test_util::RunBlockingPoolTask();
269 EXPECT_TRUE(file_system.closed()); 269 EXPECT_TRUE(file_system.closed());
270 } 270 }
271 271
272 } // namespace fileapi_internal 272 } // namespace fileapi_internal
273 } // namespace drive 273 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698