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

Side by Side Diff: webkit/fileapi/file_system_operation_unittest.cc

Issue 6767010: More filesystem cleanup: convert URL-encoded-as-FilePath to actual URL, where (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 | « webkit/fileapi/file_system_operation.cc ('k') | webkit/fileapi/file_system_path_manager.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_operation.h" 5 #include "webkit/fileapi/file_system_operation.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/scoped_temp_dir.h" 9 #include "base/memory/scoped_temp_dir.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 entries_ = entries; 49 entries_ = entries;
50 } 50 }
51 const std::vector<base::FileUtilProxy::Entry>& entries() const { 51 const std::vector<base::FileUtilProxy::Entry>& entries() const {
52 return entries_; 52 return entries_;
53 } 53 }
54 54
55 protected: 55 protected:
56 // Common temp base for nondestructive uses. 56 // Common temp base for nondestructive uses.
57 ScopedTempDir base_; 57 ScopedTempDir base_;
58 58
59 GURL URLForRelativePath(const std::string& path) const {
60 // Only the path will actually get used.
61 return GURL("file://").Resolve(base_.path().value()).Resolve(path);
62 }
63
64 GURL URLForPath(const FilePath& path) const {
65 // Only the path will actually get used.
66 return GURL("file://").Resolve(path.value());
67 }
68
59 // For post-operation status. 69 // For post-operation status.
60 int status_; 70 int status_;
61 base::PlatformFileInfo info_; 71 base::PlatformFileInfo info_;
62 FilePath path_; 72 FilePath path_;
63 std::vector<base::FileUtilProxy::Entry> entries_; 73 std::vector<base::FileUtilProxy::Entry> entries_;
64 74
65 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest); 75 DISALLOW_COPY_AND_ASSIGN(FileSystemOperationTest);
66 }; 76 };
67 77
68 class MockDispatcher : public FileSystemCallbackDispatcher { 78 class MockDispatcher : public FileSystemCallbackDispatcher {
(...skipping 15 matching lines...) Expand all
84 test_->set_path(platform_path); 94 test_->set_path(platform_path);
85 test_->set_status(kFileOperationSucceeded); 95 test_->set_status(kFileOperationSucceeded);
86 } 96 }
87 97
88 virtual void DidReadDirectory( 98 virtual void DidReadDirectory(
89 const std::vector<base::FileUtilProxy::Entry>& entries, 99 const std::vector<base::FileUtilProxy::Entry>& entries,
90 bool /* has_more */) { 100 bool /* has_more */) {
91 test_->set_entries(entries); 101 test_->set_entries(entries);
92 } 102 }
93 103
94 virtual void DidOpenFileSystem(const std::string&, const FilePath&) { 104 virtual void DidOpenFileSystem(const std::string&, const GURL&) {
95 NOTREACHED(); 105 NOTREACHED();
96 } 106 }
97 107
98 virtual void DidWrite(int64 bytes, bool complete) { 108 virtual void DidWrite(int64 bytes, bool complete) {
99 NOTREACHED(); 109 NOTREACHED();
100 } 110 }
101 111
102 private: 112 private:
103 FileSystemOperationTest* test_; 113 FileSystemOperationTest* test_;
104 }; 114 };
105 115
106 FileSystemOperation* FileSystemOperationTest::operation() { 116 FileSystemOperation* FileSystemOperationTest::operation() {
107 FileSystemOperation* operation = new FileSystemOperation( 117 FileSystemOperation* operation = new FileSystemOperation(
108 new MockDispatcher(this), 118 new MockDispatcher(this),
109 base::MessageLoopProxy::CreateForCurrentThread(), 119 base::MessageLoopProxy::CreateForCurrentThread(),
110 NULL, 120 NULL,
111 FileSystemFileUtil::GetInstance()); 121 FileSystemFileUtil::GetInstance());
112 operation->file_system_operation_context()->set_src_type( 122 operation->file_system_operation_context()->set_src_type(
113 kFileSystemTypeTemporary); 123 kFileSystemTypeTemporary);
114 operation->file_system_operation_context()->set_dest_type( 124 operation->file_system_operation_context()->set_dest_type(
115 kFileSystemTypeTemporary); 125 kFileSystemTypeTemporary);
126 GURL origin_url("fake://fake.foo/");
127 operation->file_system_operation_context()->set_src_origin_url(origin_url);
128 operation->file_system_operation_context()->set_dest_origin_url(origin_url);
116 return operation; 129 return operation;
117 } 130 }
118 131
119 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) { 132 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDoesntExist) {
120 FilePath src(base_.path().Append(FILE_PATH_LITERAL("a"))); 133 GURL src(URLForRelativePath("a"));
121 FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b"))); 134 GURL dest(URLForRelativePath("b"));
122 operation()->Move(src, dest); 135 operation()->Move(src, dest);
123 MessageLoop::current()->RunAllPending(); 136 MessageLoop::current()->RunAllPending();
124 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 137 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
125 } 138 }
126 139
127 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) { 140 TEST_F(FileSystemOperationTest, TestMoveFailureContainsPath) {
128 ScopedTempDir src_dir; 141 ScopedTempDir src_dir;
129 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 142 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
130 FilePath dest_dir_path; 143 FilePath dest_dir_path;
131 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(), 144 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(),
132 FILE_PATH_LITERAL("child_dir"), 145 FILE_PATH_LITERAL("child_dir"),
133 &dest_dir_path)); 146 &dest_dir_path));
134 operation()->Move(src_dir.path(), dest_dir_path); 147 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
135 MessageLoop::current()->RunAllPending(); 148 MessageLoop::current()->RunAllPending();
136 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 149 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
137 } 150 }
138 151
139 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) { 152 TEST_F(FileSystemOperationTest, TestMoveFailureSrcDirExistsDestFile) {
140 // Src exists and is dir. Dest is a file. 153 // Src exists and is dir. Dest is a file.
141 ScopedTempDir src_dir; 154 ScopedTempDir src_dir;
142 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 155 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
143 156
144 ScopedTempDir dest_dir; 157 ScopedTempDir dest_dir;
145 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 158 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
146 FilePath dest_file; 159 FilePath dest_file;
147 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); 160 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
148 161
149 operation()->Move(src_dir.path(), dest_file); 162 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_file));
150 MessageLoop::current()->RunAllPending(); 163 MessageLoop::current()->RunAllPending();
151 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); 164 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
152 } 165 }
153 166
154 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) { 167 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) {
155 // Src exists and is a directory. Dest is a non-empty directory. 168 // Src exists and is a directory. Dest is a non-empty directory.
156 ScopedTempDir src_dir; 169 ScopedTempDir src_dir;
157 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 170 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
158 171
159 ScopedTempDir dest_dir; 172 ScopedTempDir dest_dir;
160 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 173 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
161 FilePath child_file; 174 FilePath child_file;
162 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file); 175 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
163 176
164 operation()->Move(src_dir.path(), dest_dir.path()); 177 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
165 MessageLoop::current()->RunAllPending(); 178 MessageLoop::current()->RunAllPending();
166 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); 179 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
167 } 180 }
168 181
169 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { 182 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) {
170 // Src exists and is a file. Dest is a directory. 183 // Src exists and is a file. Dest is a directory.
171 ScopedTempDir src_dir; 184 ScopedTempDir src_dir;
172 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 185 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
173 FilePath src_file; 186 FilePath src_file;
174 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 187 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
175 188
176 ScopedTempDir dest_dir; 189 ScopedTempDir dest_dir;
177 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 190 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
178 191
179 operation()->Move(src_file, dest_dir.path()); 192 operation()->Move(URLForPath(src_file), URLForPath(dest_dir.path()));
180 MessageLoop::current()->RunAllPending(); 193 MessageLoop::current()->RunAllPending();
181 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 194 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
182 } 195 }
183 196
184 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { 197 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) {
185 // Dest. parent path does not exist. 198 // Dest. parent path does not exist.
186 ScopedTempDir src_dir; 199 ScopedTempDir src_dir;
187 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 200 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
188 FilePath nonexisting_file = base_.path().Append( 201 FilePath nonexisting_file = base_.path().Append(
189 FILE_PATH_LITERAL("NonexistingDir")).Append( 202 FILE_PATH_LITERAL("NonexistingDir")).Append(
190 FILE_PATH_LITERAL("NonexistingFile")); 203 FILE_PATH_LITERAL("NonexistingFile"));
191 204
192 operation()->Move(src_dir.path(), nonexisting_file); 205 operation()->Move(URLForPath(src_dir.path()), URLForPath(nonexisting_file));
193 MessageLoop::current()->RunAllPending(); 206 MessageLoop::current()->RunAllPending();
194 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 207 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
195 } 208 }
196 209
197 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) { 210 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndOverwrite) {
198 ScopedTempDir src_dir; 211 ScopedTempDir src_dir;
199 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 212 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
200 FilePath src_file; 213 FilePath src_file;
201 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 214 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
202 215
203 ScopedTempDir dest_dir; 216 ScopedTempDir dest_dir;
204 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 217 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
205 FilePath dest_file; 218 FilePath dest_file;
206 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); 219 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
207 220
208 operation()->Move(src_file, dest_file); 221 operation()->Move(URLForPath(src_file), URLForPath(dest_file));
209 MessageLoop::current()->RunAllPending(); 222 MessageLoop::current()->RunAllPending();
210 EXPECT_EQ(kFileOperationSucceeded, status()); 223 EXPECT_EQ(kFileOperationSucceeded, status());
211 EXPECT_TRUE(FileExists(dest_file)); 224 EXPECT_TRUE(FileExists(dest_file));
212 } 225 }
213 226
214 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) { 227 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcFileAndNew) {
215 ScopedTempDir src_dir; 228 ScopedTempDir src_dir;
216 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 229 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
217 FilePath src_file; 230 FilePath src_file;
218 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 231 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
219 232
220 ScopedTempDir dest_dir; 233 ScopedTempDir dest_dir;
221 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 234 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
222 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile"))); 235 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile")));
223 236
224 operation()->Move(src_file, dest_file); 237 operation()->Move(URLForPath(src_file), URLForPath(dest_file));
225 MessageLoop::current()->RunAllPending(); 238 MessageLoop::current()->RunAllPending();
226 EXPECT_EQ(kFileOperationSucceeded, status()); 239 EXPECT_EQ(kFileOperationSucceeded, status());
227 EXPECT_TRUE(FileExists(dest_file)); 240 EXPECT_TRUE(FileExists(dest_file));
228 } 241 }
229 242
230 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) { 243 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndOverwrite) {
231 ScopedTempDir src_dir; 244 ScopedTempDir src_dir;
232 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 245 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
233 246
234 ScopedTempDir dest_dir; 247 ScopedTempDir dest_dir;
235 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 248 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
236 249
237 operation()->Move(src_dir.path(), dest_dir.path()); 250 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
238 MessageLoop::current()->RunAllPending(); 251 MessageLoop::current()->RunAllPending();
239 EXPECT_EQ(kFileOperationSucceeded, status()); 252 EXPECT_EQ(kFileOperationSucceeded, status());
240 EXPECT_FALSE(file_util::DirectoryExists(src_dir.path())); 253 EXPECT_FALSE(file_util::DirectoryExists(src_dir.path()));
241 254
242 // Make sure we've overwritten but not moved the source under the |dest_dir|. 255 // Make sure we've overwritten but not moved the source under the |dest_dir|.
243 EXPECT_TRUE(file_util::DirectoryExists(dest_dir.path())); 256 EXPECT_TRUE(file_util::DirectoryExists(dest_dir.path()));
244 EXPECT_FALSE(file_util::DirectoryExists( 257 EXPECT_FALSE(file_util::DirectoryExists(
245 dest_dir.path().Append(src_dir.path().BaseName()))); 258 dest_dir.path().Append(src_dir.path().BaseName())));
246 } 259 }
247 260
248 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) { 261 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirAndNew) {
249 ScopedTempDir src_dir; 262 ScopedTempDir src_dir;
250 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 263 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
251 264
252 ScopedTempDir dir; 265 ScopedTempDir dir;
253 ASSERT_TRUE(dir.CreateUniqueTempDir()); 266 ASSERT_TRUE(dir.CreateUniqueTempDir());
254 FilePath dest_dir_path(dir.path().Append(FILE_PATH_LITERAL("NewDirectory"))); 267 FilePath dest_dir_path(dir.path().Append(FILE_PATH_LITERAL("NewDirectory")));
255 268
256 operation()->Move(src_dir.path(), dest_dir_path); 269 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
257 MessageLoop::current()->RunAllPending(); 270 MessageLoop::current()->RunAllPending();
258 EXPECT_EQ(kFileOperationSucceeded, status()); 271 EXPECT_EQ(kFileOperationSucceeded, status());
259 EXPECT_FALSE(file_util::DirectoryExists(src_dir.path())); 272 EXPECT_FALSE(file_util::DirectoryExists(src_dir.path()));
260 EXPECT_TRUE(file_util::DirectoryExists(dest_dir_path)); 273 EXPECT_TRUE(file_util::DirectoryExists(dest_dir_path));
261 } 274 }
262 275
263 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) { 276 TEST_F(FileSystemOperationTest, TestMoveSuccessSrcDirRecursive) {
264 ScopedTempDir src_dir; 277 ScopedTempDir src_dir;
265 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 278 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
266 FilePath child_file; 279 FilePath child_file;
267 file_util::CreateTemporaryFileInDir(src_dir.path(), &child_file); 280 file_util::CreateTemporaryFileInDir(src_dir.path(), &child_file);
268 281
269 ScopedTempDir dest_dir; 282 ScopedTempDir dest_dir;
270 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 283 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
271 284
272 operation()->Move(src_dir.path(), dest_dir.path()); 285 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
273 MessageLoop::current()->RunAllPending(); 286 MessageLoop::current()->RunAllPending();
274 EXPECT_EQ(kFileOperationSucceeded, status()); 287 EXPECT_EQ(kFileOperationSucceeded, status());
275 EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName()))); 288 EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName())));
276 } 289 }
277 290
278 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) { 291 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDoesntExist) {
279 FilePath src(base_.path().Append(FILE_PATH_LITERAL("a"))); 292 operation()->Copy(URLForRelativePath("a"), URLForRelativePath("b"));
280 FilePath dest(base_.path().Append(FILE_PATH_LITERAL("b")));
281 operation()->Copy(src, dest);
282 MessageLoop::current()->RunAllPending(); 293 MessageLoop::current()->RunAllPending();
283 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 294 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
284 } 295 }
285 296
286 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) { 297 TEST_F(FileSystemOperationTest, TestCopyFailureContainsPath) {
287 ScopedTempDir src_dir; 298 ScopedTempDir src_dir;
288 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 299 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
289 FilePath dest_dir_path; 300 FilePath dest_dir_path;
290 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(), 301 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(src_dir.path(),
291 FILE_PATH_LITERAL("child_dir"), 302 FILE_PATH_LITERAL("child_dir"),
292 &dest_dir_path)); 303 &dest_dir_path));
293 operation()->Copy(src_dir.path(), dest_dir_path); 304 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir_path));
294 MessageLoop::current()->RunAllPending(); 305 MessageLoop::current()->RunAllPending();
295 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status()); 306 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
296 } 307 }
297 308
298 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) { 309 TEST_F(FileSystemOperationTest, TestCopyFailureSrcDirExistsDestFile) {
299 // Src exists and is dir. Dest is a file. 310 // Src exists and is dir. Dest is a file.
300 ScopedTempDir src_dir; 311 ScopedTempDir src_dir;
301 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 312 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
302 313
303 ScopedTempDir dest_dir; 314 ScopedTempDir dest_dir;
304 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 315 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
305 FilePath dest_file; 316 FilePath dest_file;
306 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); 317 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
307 318
308 operation()->Copy(src_dir.path(), dest_file); 319 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_file));
309 MessageLoop::current()->RunAllPending(); 320 MessageLoop::current()->RunAllPending();
310 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); 321 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
311 } 322 }
312 323
313 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) { 324 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) {
314 // Src exists and is a directory. Dest is a non-empty directory. 325 // Src exists and is a directory. Dest is a non-empty directory.
315 ScopedTempDir src_dir; 326 ScopedTempDir src_dir;
316 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 327 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
317 328
318 ScopedTempDir dest_dir; 329 ScopedTempDir dest_dir;
319 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 330 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
320 FilePath child_file; 331 FilePath child_file;
321 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file); 332 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
322 333
323 operation()->Copy(src_dir.path(), dest_dir.path()); 334 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
324 MessageLoop::current()->RunAllPending(); 335 MessageLoop::current()->RunAllPending();
325 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); 336 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
326 } 337 }
327 338
328 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { 339 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) {
329 // Src exists and is a file. Dest is a directory. 340 // Src exists and is a file. Dest is a directory.
330 ScopedTempDir src_dir; 341 ScopedTempDir src_dir;
331 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 342 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
332 FilePath src_file; 343 FilePath src_file;
333 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 344 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
334 345
335 ScopedTempDir dest_dir; 346 ScopedTempDir dest_dir;
336 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 347 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
337 348
338 operation()->Copy(src_file, dest_dir.path()); 349 operation()->Copy(URLForPath(src_file), URLForPath(dest_dir.path()));
339 MessageLoop::current()->RunAllPending(); 350 MessageLoop::current()->RunAllPending();
340 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 351 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
341 } 352 }
342 353
343 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { 354 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) {
344 // Dest. parent path does not exist. 355 // Dest. parent path does not exist.
345 ScopedTempDir dir; 356 ScopedTempDir dir;
346 ASSERT_TRUE(dir.CreateUniqueTempDir()); 357 ASSERT_TRUE(dir.CreateUniqueTempDir());
347 FilePath src_dir = dir.path(); 358 FilePath src_dir = dir.path();
348 359
349 FilePath nonexisting(base_.path().Append(FILE_PATH_LITERAL("DontExistDir"))); 360 FilePath nonexisting(base_.path().Append(FILE_PATH_LITERAL("DontExistDir")));
350 file_util::EnsureEndsWithSeparator(&nonexisting); 361 file_util::EnsureEndsWithSeparator(&nonexisting);
351 FilePath nonexisting_file = nonexisting.Append( 362 FilePath nonexisting_file = nonexisting.Append(
352 FILE_PATH_LITERAL("DontExistFile")); 363 FILE_PATH_LITERAL("DontExistFile"));
353 364
354 operation()->Copy(src_dir, nonexisting_file); 365 operation()->Copy(URLForPath(src_dir), URLForPath(nonexisting_file));
355 MessageLoop::current()->RunAllPending(); 366 MessageLoop::current()->RunAllPending();
356 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 367 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
357 } 368 }
358 369
359 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) { 370 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndOverwrite) {
360 ScopedTempDir src_dir; 371 ScopedTempDir src_dir;
361 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 372 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
362 FilePath src_file; 373 FilePath src_file;
363 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 374 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
364 375
365 ScopedTempDir dest_dir; 376 ScopedTempDir dest_dir;
366 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 377 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
367 FilePath dest_file; 378 FilePath dest_file;
368 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); 379 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
369 380
370 operation()->Copy(src_file, dest_file); 381 operation()->Copy(URLForPath(src_file), URLForPath(dest_file));
371 MessageLoop::current()->RunAllPending(); 382 MessageLoop::current()->RunAllPending();
372 EXPECT_EQ(kFileOperationSucceeded, status()); 383 EXPECT_EQ(kFileOperationSucceeded, status());
373 EXPECT_TRUE(FileExists(dest_file)); 384 EXPECT_TRUE(FileExists(dest_file));
374 } 385 }
375 386
376 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) { 387 TEST_F(FileSystemOperationTest, TestCopySuccessSrcFileAndNew) {
377 ScopedTempDir src_dir; 388 ScopedTempDir src_dir;
378 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 389 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
379 FilePath src_file; 390 FilePath src_file;
380 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 391 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
381 392
382 ScopedTempDir dest_dir; 393 ScopedTempDir dest_dir;
383 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 394 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
384 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile"))); 395 FilePath dest_file(dest_dir.path().Append(FILE_PATH_LITERAL("NewFile")));
385 396
386 operation()->Copy(src_file, dest_file); 397 operation()->Copy(URLForPath(src_file), URLForPath(dest_file));
387 MessageLoop::current()->RunAllPending(); 398 MessageLoop::current()->RunAllPending();
388 EXPECT_EQ(kFileOperationSucceeded, status()); 399 EXPECT_EQ(kFileOperationSucceeded, status());
389 EXPECT_TRUE(FileExists(dest_file)); 400 EXPECT_TRUE(FileExists(dest_file));
390 } 401 }
391 402
392 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) { 403 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndOverwrite) {
393 ScopedTempDir src_dir; 404 ScopedTempDir src_dir;
394 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 405 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
395 406
396 ScopedTempDir dest_dir; 407 ScopedTempDir dest_dir;
397 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 408 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
398 409
399 operation()->Copy(src_dir.path(), dest_dir.path()); 410 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
400 MessageLoop::current()->RunAllPending(); 411 MessageLoop::current()->RunAllPending();
401 EXPECT_EQ(kFileOperationSucceeded, status()); 412 EXPECT_EQ(kFileOperationSucceeded, status());
402 413
403 // Make sure we've overwritten but not copied the source under the |dest_dir|. 414 // Make sure we've overwritten but not copied the source under the |dest_dir|.
404 EXPECT_TRUE(file_util::DirectoryExists(dest_dir.path())); 415 EXPECT_TRUE(file_util::DirectoryExists(dest_dir.path()));
405 EXPECT_FALSE(file_util::DirectoryExists( 416 EXPECT_FALSE(file_util::DirectoryExists(
406 dest_dir.path().Append(src_dir.path().BaseName()))); 417 dest_dir.path().Append(src_dir.path().BaseName())));
407 } 418 }
408 419
409 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) { 420 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirAndNew) {
410 ScopedTempDir src_dir; 421 ScopedTempDir src_dir;
411 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 422 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
412 423
413 ScopedTempDir dir; 424 ScopedTempDir dir;
414 ASSERT_TRUE(dir.CreateUniqueTempDir()); 425 ASSERT_TRUE(dir.CreateUniqueTempDir());
415 FilePath dest_dir(dir.path().Append(FILE_PATH_LITERAL("NewDirectory"))); 426 FilePath dest_dir(dir.path().Append(FILE_PATH_LITERAL("NewDirectory")));
416 427
417 operation()->Copy(src_dir.path(), dest_dir); 428 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir));
418 MessageLoop::current()->RunAllPending(); 429 MessageLoop::current()->RunAllPending();
419 EXPECT_EQ(kFileOperationSucceeded, status()); 430 EXPECT_EQ(kFileOperationSucceeded, status());
420 EXPECT_TRUE(file_util::DirectoryExists(dest_dir)); 431 EXPECT_TRUE(file_util::DirectoryExists(dest_dir));
421 } 432 }
422 433
423 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) { 434 TEST_F(FileSystemOperationTest, TestCopySuccessSrcDirRecursive) {
424 ScopedTempDir src_dir; 435 ScopedTempDir src_dir;
425 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 436 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
426 FilePath child_file; 437 FilePath child_file;
427 file_util::CreateTemporaryFileInDir(src_dir.path(), &child_file); 438 file_util::CreateTemporaryFileInDir(src_dir.path(), &child_file);
428 439
429 ScopedTempDir dest_dir; 440 ScopedTempDir dest_dir;
430 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 441 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
431 442
432 operation()->Copy(src_dir.path(), dest_dir.path()); 443 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
433 MessageLoop::current()->RunAllPending(); 444 MessageLoop::current()->RunAllPending();
434 EXPECT_EQ(kFileOperationSucceeded, status()); 445 EXPECT_EQ(kFileOperationSucceeded, status());
435 EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName()))); 446 EXPECT_TRUE(FileExists(dest_dir.path().Append(child_file.BaseName())));
436 } 447 }
437 448
438 TEST_F(FileSystemOperationTest, TestCreateFileFailure) { 449 TEST_F(FileSystemOperationTest, TestCreateFileFailure) {
439 // Already existing file and exclusive true. 450 // Already existing file and exclusive true.
440 ScopedTempDir dir; 451 ScopedTempDir dir;
441 ASSERT_TRUE(dir.CreateUniqueTempDir()); 452 ASSERT_TRUE(dir.CreateUniqueTempDir());
442 FilePath file; 453 FilePath file;
443 454
444 file_util::CreateTemporaryFileInDir(dir.path(), &file); 455 file_util::CreateTemporaryFileInDir(dir.path(), &file);
445 operation()->CreateFile(file, true); 456 operation()->CreateFile(URLForPath(file), true);
446 MessageLoop::current()->RunAllPending(); 457 MessageLoop::current()->RunAllPending();
447 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); 458 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
448 } 459 }
449 460
450 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) { 461 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileExists) {
451 // Already existing file and exclusive false. 462 // Already existing file and exclusive false.
452 ScopedTempDir dir; 463 ScopedTempDir dir;
453 ASSERT_TRUE(dir.CreateUniqueTempDir()); 464 ASSERT_TRUE(dir.CreateUniqueTempDir());
454 FilePath file; 465 FilePath file;
455 file_util::CreateTemporaryFileInDir(dir.path(), &file); 466 file_util::CreateTemporaryFileInDir(dir.path(), &file);
456 467
457 operation()->CreateFile(file, false); 468 operation()->CreateFile(URLForPath(file), false);
458 MessageLoop::current()->RunAllPending(); 469 MessageLoop::current()->RunAllPending();
459 EXPECT_EQ(kFileOperationSucceeded, status()); 470 EXPECT_EQ(kFileOperationSucceeded, status());
460 EXPECT_TRUE(FileExists(file)); 471 EXPECT_TRUE(FileExists(file));
461 } 472 }
462 473
463 TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) { 474 TEST_F(FileSystemOperationTest, TestCreateFileSuccessExclusive) {
464 // File doesn't exist but exclusive is true. 475 // File doesn't exist but exclusive is true.
465 ScopedTempDir dir; 476 ScopedTempDir dir;
466 ASSERT_TRUE(dir.CreateUniqueTempDir()); 477 ASSERT_TRUE(dir.CreateUniqueTempDir());
467 FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist")); 478 FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist"));
468 operation()->CreateFile(file, true); 479 operation()->CreateFile(URLForPath(file), true);
469 MessageLoop::current()->RunAllPending(); 480 MessageLoop::current()->RunAllPending();
470 EXPECT_EQ(kFileOperationSucceeded, status()); 481 EXPECT_EQ(kFileOperationSucceeded, status());
471 EXPECT_TRUE(FileExists(file)); 482 EXPECT_TRUE(FileExists(file));
472 } 483 }
473 484
474 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) { 485 TEST_F(FileSystemOperationTest, TestCreateFileSuccessFileDoesntExist) {
475 // Non existing file. 486 // Non existing file.
476 ScopedTempDir dir; 487 ScopedTempDir dir;
477 ASSERT_TRUE(dir.CreateUniqueTempDir()); 488 ASSERT_TRUE(dir.CreateUniqueTempDir());
478 FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist")); 489 FilePath file = dir.path().Append(FILE_PATH_LITERAL("FileDoesntExist"));
479 operation()->CreateFile(file, false); 490 operation()->CreateFile(URLForPath(file), false);
480 MessageLoop::current()->RunAllPending(); 491 MessageLoop::current()->RunAllPending();
481 EXPECT_EQ(kFileOperationSucceeded, status()); 492 EXPECT_EQ(kFileOperationSucceeded, status());
482 } 493 }
483 494
484 TEST_F(FileSystemOperationTest, 495 TEST_F(FileSystemOperationTest,
485 TestCreateDirFailureDestParentDoesntExist) { 496 TestCreateDirFailureDestParentDoesntExist) {
486 // Dest. parent path does not exist. 497 // Dest. parent path does not exist.
487 FilePath nonexisting(base_.path().Append( 498 FilePath nonexisting(base_.path().Append(
488 FILE_PATH_LITERAL("DirDoesntExist"))); 499 FILE_PATH_LITERAL("DirDoesntExist")));
489 FilePath nonexisting_file = nonexisting.Append( 500 FilePath nonexisting_file = nonexisting.Append(
490 FILE_PATH_LITERAL("FileDoesntExist")); 501 FILE_PATH_LITERAL("FileDoesntExist"));
491 operation()->CreateDirectory(nonexisting_file, false, false); 502 operation()->CreateDirectory(URLForPath(nonexisting_file), false, false);
492 MessageLoop::current()->RunAllPending(); 503 MessageLoop::current()->RunAllPending();
493 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 504 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
494 } 505 }
495 506
496 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) { 507 TEST_F(FileSystemOperationTest, TestCreateDirFailureDirExists) {
497 // Exclusive and dir existing at path. 508 // Exclusive and dir existing at path.
498 ScopedTempDir src_dir; 509 ScopedTempDir src_dir;
499 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 510 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
500 operation()->CreateDirectory(src_dir.path(), true, false); 511 operation()->CreateDirectory(URLForPath(src_dir.path()), true, false);
501 MessageLoop::current()->RunAllPending(); 512 MessageLoop::current()->RunAllPending();
502 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); 513 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
503 } 514 }
504 515
505 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) { 516 TEST_F(FileSystemOperationTest, TestCreateDirFailureFileExists) {
506 // Exclusive true and file existing at path. 517 // Exclusive true and file existing at path.
507 ScopedTempDir dir; 518 ScopedTempDir dir;
508 ASSERT_TRUE(dir.CreateUniqueTempDir()); 519 ASSERT_TRUE(dir.CreateUniqueTempDir());
509 FilePath file; 520 FilePath file;
510 file_util::CreateTemporaryFileInDir(dir.path(), &file); 521 file_util::CreateTemporaryFileInDir(dir.path(), &file);
511 operation()->CreateDirectory(file, true, false); 522 operation()->CreateDirectory(URLForPath(file), true, false);
512 MessageLoop::current()->RunAllPending(); 523 MessageLoop::current()->RunAllPending();
513 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status()); 524 EXPECT_EQ(base::PLATFORM_FILE_ERROR_EXISTS, status());
514 } 525 }
515 526
516 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) { 527 TEST_F(FileSystemOperationTest, TestCreateDirSuccess) {
517 // Dir exists and exclusive is false. 528 // Dir exists and exclusive is false.
518 ScopedTempDir dir; 529 ScopedTempDir dir;
519 ASSERT_TRUE(dir.CreateUniqueTempDir()); 530 ASSERT_TRUE(dir.CreateUniqueTempDir());
520 operation()->CreateDirectory(dir.path(), false, false); 531 operation()->CreateDirectory(URLForPath(dir.path()), false, false);
521 MessageLoop::current()->RunAllPending(); 532 MessageLoop::current()->RunAllPending();
522 EXPECT_EQ(kFileOperationSucceeded, status()); 533 EXPECT_EQ(kFileOperationSucceeded, status());
523 534
524 // Dir doesn't exist. 535 // Dir doesn't exist.
525 FilePath nonexisting_dir_path(base_.path().Append( 536 FilePath nonexisting_dir_path(base_.path().Append(
526 FILE_PATH_LITERAL("nonexistingdir"))); 537 FILE_PATH_LITERAL("nonexistingdir")));
527 operation()->CreateDirectory(nonexisting_dir_path, false, false); 538 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), false, false);
528 MessageLoop::current()->RunAllPending(); 539 MessageLoop::current()->RunAllPending();
529 EXPECT_EQ(kFileOperationSucceeded, status()); 540 EXPECT_EQ(kFileOperationSucceeded, status());
530 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path)); 541 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path));
531 } 542 }
532 543
533 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) { 544 TEST_F(FileSystemOperationTest, TestCreateDirSuccessExclusive) {
534 // Dir doesn't exist. 545 // Dir doesn't exist.
535 FilePath nonexisting_dir_path(base_.path().Append( 546 FilePath nonexisting_dir_path(base_.path().Append(
536 FILE_PATH_LITERAL("nonexistingdir"))); 547 FILE_PATH_LITERAL("nonexistingdir")));
537 548
538 operation()->CreateDirectory(nonexisting_dir_path, true, false); 549 operation()->CreateDirectory(URLForPath(nonexisting_dir_path), true, false);
539 MessageLoop::current()->RunAllPending(); 550 MessageLoop::current()->RunAllPending();
540 EXPECT_EQ(kFileOperationSucceeded, status()); 551 EXPECT_EQ(kFileOperationSucceeded, status());
541 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path)); 552 EXPECT_TRUE(file_util::DirectoryExists(nonexisting_dir_path));
542 } 553 }
543 554
544 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) { 555 TEST_F(FileSystemOperationTest, TestExistsAndMetadataFailure) {
545 FilePath nonexisting_dir_path(base_.path().Append( 556 FilePath nonexisting_dir_path(base_.path().Append(
546 FILE_PATH_LITERAL("nonexistingdir"))); 557 FILE_PATH_LITERAL("nonexistingdir")));
547 operation()->GetMetadata(nonexisting_dir_path); 558 operation()->GetMetadata(URLForPath(nonexisting_dir_path));
548 MessageLoop::current()->RunAllPending(); 559 MessageLoop::current()->RunAllPending();
549 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 560 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
550 561
551 operation()->FileExists(nonexisting_dir_path); 562 operation()->FileExists(URLForPath(nonexisting_dir_path));
552 MessageLoop::current()->RunAllPending(); 563 MessageLoop::current()->RunAllPending();
553 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 564 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
554 565
555 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); 566 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
556 operation()->DirectoryExists(nonexisting_dir_path); 567 operation()->DirectoryExists(URLForPath(nonexisting_dir_path));
557 MessageLoop::current()->RunAllPending(); 568 MessageLoop::current()->RunAllPending();
558 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 569 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
559 } 570 }
560 571
561 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) { 572 TEST_F(FileSystemOperationTest, TestExistsAndMetadataSuccess) {
562 ScopedTempDir dir; 573 ScopedTempDir dir;
563 ASSERT_TRUE(dir.CreateUniqueTempDir()); 574 ASSERT_TRUE(dir.CreateUniqueTempDir());
564 575
565 operation()->DirectoryExists(dir.path()); 576 operation()->DirectoryExists(URLForPath(dir.path()));
566 MessageLoop::current()->RunAllPending(); 577 MessageLoop::current()->RunAllPending();
567 EXPECT_EQ(kFileOperationSucceeded, status()); 578 EXPECT_EQ(kFileOperationSucceeded, status());
568 579
569 operation()->GetMetadata(dir.path()); 580 operation()->GetMetadata(URLForPath(dir.path()));
570 MessageLoop::current()->RunAllPending(); 581 MessageLoop::current()->RunAllPending();
571 EXPECT_EQ(kFileOperationSucceeded, status()); 582 EXPECT_EQ(kFileOperationSucceeded, status());
572 EXPECT_TRUE(info().is_directory); 583 EXPECT_TRUE(info().is_directory);
573 EXPECT_EQ(dir.path(), path()); 584 EXPECT_EQ(dir.path(), path());
574 585
575 FilePath file; 586 FilePath file;
576 file_util::CreateTemporaryFileInDir(dir.path(), &file); 587 file_util::CreateTemporaryFileInDir(dir.path(), &file);
577 operation()->FileExists(file); 588 operation()->FileExists(URLForPath(file));
578 MessageLoop::current()->RunAllPending(); 589 MessageLoop::current()->RunAllPending();
579 EXPECT_EQ(kFileOperationSucceeded, status()); 590 EXPECT_EQ(kFileOperationSucceeded, status());
580 591
581 operation()->GetMetadata(file); 592 operation()->GetMetadata(URLForPath(file));
582 MessageLoop::current()->RunAllPending(); 593 MessageLoop::current()->RunAllPending();
583 EXPECT_EQ(kFileOperationSucceeded, status()); 594 EXPECT_EQ(kFileOperationSucceeded, status());
584 EXPECT_FALSE(info().is_directory); 595 EXPECT_FALSE(info().is_directory);
585 EXPECT_EQ(file, path()); 596 EXPECT_EQ(file, path());
586 } 597 }
587 598
588 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) { 599 TEST_F(FileSystemOperationTest, TestTypeMismatchErrors) {
589 ScopedTempDir dir; 600 ScopedTempDir dir;
590 ASSERT_TRUE(dir.CreateUniqueTempDir()); 601 ASSERT_TRUE(dir.CreateUniqueTempDir());
591 operation()->FileExists(dir.path()); 602 operation()->FileExists(URLForPath(dir.path()));
592 MessageLoop::current()->RunAllPending(); 603 MessageLoop::current()->RunAllPending();
593 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 604 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status());
594 605
595 FilePath file; 606 FilePath file;
596 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file)); 607 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(dir.path(), &file));
597 operation()->DirectoryExists(file); 608 operation()->DirectoryExists(URLForPath(file));
598 MessageLoop::current()->RunAllPending(); 609 MessageLoop::current()->RunAllPending();
599 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); 610 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status());
600 } 611 }
601 612
602 TEST_F(FileSystemOperationTest, TestReadDirFailure) { 613 TEST_F(FileSystemOperationTest, TestReadDirFailure) {
603 // Path doesn't exist 614 // Path doesn't exist
604 FilePath nonexisting_dir_path(base_.path().Append( 615 FilePath nonexisting_dir_path(base_.path().Append(
605 FILE_PATH_LITERAL("NonExistingDir"))); 616 FILE_PATH_LITERAL("NonExistingDir")));
606 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path); 617 file_util::EnsureEndsWithSeparator(&nonexisting_dir_path);
607 operation()->ReadDirectory(nonexisting_dir_path); 618 operation()->ReadDirectory(URLForPath(nonexisting_dir_path));
608 MessageLoop::current()->RunAllPending(); 619 MessageLoop::current()->RunAllPending();
609 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 620 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
610 621
611 // File exists. 622 // File exists.
612 ScopedTempDir dir; 623 ScopedTempDir dir;
613 ASSERT_TRUE(dir.CreateUniqueTempDir()); 624 ASSERT_TRUE(dir.CreateUniqueTempDir());
614 FilePath file; 625 FilePath file;
615 file_util::CreateTemporaryFileInDir(dir.path(), &file); 626 file_util::CreateTemporaryFileInDir(dir.path(), &file);
616 operation()->ReadDirectory(file); 627 operation()->ReadDirectory(URLForPath(file));
617 MessageLoop::current()->RunAllPending(); 628 MessageLoop::current()->RunAllPending();
618 // TODO(kkanetkar) crbug.com/54309 to change the error code. 629 // TODO(kkanetkar) crbug.com/54309 to change the error code.
619 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 630 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
620 } 631 }
621 632
622 TEST_F(FileSystemOperationTest, TestReadDirSuccess) { 633 TEST_F(FileSystemOperationTest, TestReadDirSuccess) {
623 // parent_dir 634 // parent_dir
624 // | | 635 // | |
625 // child_dir child_file 636 // child_dir child_file
626 // Verify reading parent_dir. 637 // Verify reading parent_dir.
627 ScopedTempDir parent_dir; 638 ScopedTempDir parent_dir;
628 ASSERT_TRUE(parent_dir.CreateUniqueTempDir()); 639 ASSERT_TRUE(parent_dir.CreateUniqueTempDir());
629 FilePath child_file; 640 FilePath child_file;
630 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); 641 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file);
631 FilePath child_dir; 642 FilePath child_dir;
632 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( 643 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
633 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); 644 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
634 645
635 operation()->ReadDirectory(parent_dir.path()); 646 operation()->ReadDirectory(URLForPath(parent_dir.path()));
636 MessageLoop::current()->RunAllPending(); 647 MessageLoop::current()->RunAllPending();
637 EXPECT_EQ(kFileOperationStatusNotSet, status()); 648 EXPECT_EQ(kFileOperationStatusNotSet, status());
638 EXPECT_EQ(2u, entries().size()); 649 EXPECT_EQ(2u, entries().size());
639 650
640 for (size_t i = 0; i < entries().size(); ++i) { 651 for (size_t i = 0; i < entries().size(); ++i) {
641 if (entries()[i].is_directory) { 652 if (entries()[i].is_directory) {
642 EXPECT_EQ(child_dir.BaseName().value(), 653 EXPECT_EQ(child_dir.BaseName().value(),
643 entries()[i].name); 654 entries()[i].name);
644 } else { 655 } else {
645 EXPECT_EQ(child_file.BaseName().value(), 656 EXPECT_EQ(child_file.BaseName().value(),
646 entries()[i].name); 657 entries()[i].name);
647 } 658 }
648 } 659 }
649 } 660 }
650 661
651 TEST_F(FileSystemOperationTest, TestRemoveFailure) { 662 TEST_F(FileSystemOperationTest, TestRemoveFailure) {
652 // Path doesn't exist. 663 // Path doesn't exist.
653 FilePath nonexisting(base_.path().Append( 664 FilePath nonexisting(base_.path().Append(
654 FILE_PATH_LITERAL("NonExistingDir"))); 665 FILE_PATH_LITERAL("NonExistingDir")));
655 file_util::EnsureEndsWithSeparator(&nonexisting); 666 file_util::EnsureEndsWithSeparator(&nonexisting);
656 667
657 operation()->Remove(nonexisting, false /* recursive */); 668 operation()->Remove(URLForPath(nonexisting), false /* recursive */);
658 MessageLoop::current()->RunAllPending(); 669 MessageLoop::current()->RunAllPending();
659 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status()); 670 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND, status());
660 671
661 // It's an error to try to remove a non-empty directory if recursive flag 672 // It's an error to try to remove a non-empty directory if recursive flag
662 // is false. 673 // is false.
663 // parent_dir 674 // parent_dir
664 // | | 675 // | |
665 // child_dir child_file 676 // child_dir child_file
666 // Verify deleting parent_dir. 677 // Verify deleting parent_dir.
667 ScopedTempDir parent_dir; 678 ScopedTempDir parent_dir;
668 ASSERT_TRUE(parent_dir.CreateUniqueTempDir()); 679 ASSERT_TRUE(parent_dir.CreateUniqueTempDir());
669 FilePath child_file; 680 FilePath child_file;
670 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); 681 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file);
671 FilePath child_dir; 682 FilePath child_dir;
672 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( 683 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
673 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); 684 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
674 685
675 operation()->Remove(parent_dir.path(), false /* recursive */); 686 operation()->Remove(URLForPath(parent_dir.path()), false /* recursive */);
676 MessageLoop::current()->RunAllPending(); 687 MessageLoop::current()->RunAllPending();
677 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, 688 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY,
678 status()); 689 status());
679 } 690 }
680 691
681 TEST_F(FileSystemOperationTest, TestRemoveSuccess) { 692 TEST_F(FileSystemOperationTest, TestRemoveSuccess) {
682 ScopedTempDir empty_dir; 693 ScopedTempDir empty_dir;
683 ASSERT_TRUE(empty_dir.CreateUniqueTempDir()); 694 ASSERT_TRUE(empty_dir.CreateUniqueTempDir());
684 EXPECT_TRUE(file_util::DirectoryExists(empty_dir.path())); 695 EXPECT_TRUE(file_util::DirectoryExists(empty_dir.path()));
685 696
686 operation()->Remove(empty_dir.path(), false /* recursive */); 697 operation()->Remove(URLForPath(empty_dir.path()), false /* recursive */);
687 MessageLoop::current()->RunAllPending(); 698 MessageLoop::current()->RunAllPending();
688 EXPECT_EQ(kFileOperationSucceeded, status()); 699 EXPECT_EQ(kFileOperationSucceeded, status());
689 EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path())); 700 EXPECT_FALSE(file_util::DirectoryExists(empty_dir.path()));
690 701
691 // Removing a non-empty directory with recursive flag == true should be ok. 702 // Removing a non-empty directory with recursive flag == true should be ok.
692 // parent_dir 703 // parent_dir
693 // | | 704 // | |
694 // child_dir child_file 705 // child_dir child_file
695 // Verify deleting parent_dir. 706 // Verify deleting parent_dir.
696 ScopedTempDir parent_dir; 707 ScopedTempDir parent_dir;
697 ASSERT_TRUE(parent_dir.CreateUniqueTempDir()); 708 ASSERT_TRUE(parent_dir.CreateUniqueTempDir());
698 FilePath child_file; 709 FilePath child_file;
699 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file); 710 file_util::CreateTemporaryFileInDir(parent_dir.path(), &child_file);
700 FilePath child_dir; 711 FilePath child_dir;
701 ASSERT_TRUE(file_util::CreateTemporaryDirInDir( 712 ASSERT_TRUE(file_util::CreateTemporaryDirInDir(
702 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir)); 713 parent_dir.path(), FILE_PATH_LITERAL("child_dir"), &child_dir));
703 714
704 operation()->Remove(parent_dir.path(), true /* recursive */); 715 operation()->Remove(URLForPath(parent_dir.path()), true /* recursive */);
705 MessageLoop::current()->RunAllPending(); 716 MessageLoop::current()->RunAllPending();
706 EXPECT_EQ(kFileOperationSucceeded, status()); 717 EXPECT_EQ(kFileOperationSucceeded, status());
707 EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path())); 718 EXPECT_FALSE(file_util::DirectoryExists(parent_dir.path()));
708 } 719 }
709 720
710 // TODO(ericu): Add tests for Write, Cancel. 721 // TODO(ericu): Add tests for Write, Cancel.
711 722
712 TEST_F(FileSystemOperationTest, TestTruncate) { 723 TEST_F(FileSystemOperationTest, TestTruncate) {
713 ScopedTempDir dir; 724 ScopedTempDir dir;
714 ASSERT_TRUE(dir.CreateUniqueTempDir()); 725 ASSERT_TRUE(dir.CreateUniqueTempDir());
715 FilePath file; 726 FilePath file;
716 file_util::CreateTemporaryFileInDir(dir.path(), &file); 727 file_util::CreateTemporaryFileInDir(dir.path(), &file);
717 728
718 char test_data[] = "test data"; 729 char test_data[] = "test data";
719 int data_size = static_cast<int>(sizeof(test_data)); 730 int data_size = static_cast<int>(sizeof(test_data));
720 EXPECT_EQ(data_size, 731 EXPECT_EQ(data_size,
721 file_util::WriteFile(file, test_data, data_size)); 732 file_util::WriteFile(file, test_data, data_size));
722 733
723 // Check that its length is the size of the data written. 734 // Check that its length is the size of the data written.
724 operation()->GetMetadata(file); 735 operation()->GetMetadata(URLForPath(file));
725 MessageLoop::current()->RunAllPending(); 736 MessageLoop::current()->RunAllPending();
726 EXPECT_EQ(kFileOperationSucceeded, status()); 737 EXPECT_EQ(kFileOperationSucceeded, status());
727 EXPECT_FALSE(info().is_directory); 738 EXPECT_FALSE(info().is_directory);
728 EXPECT_EQ(data_size, info().size); 739 EXPECT_EQ(data_size, info().size);
729 740
730 // Extend the file by truncating it. 741 // Extend the file by truncating it.
731 int length = 17; 742 int length = 17;
732 operation()->Truncate(file, length); 743 operation()->Truncate(URLForPath(file), length);
733 MessageLoop::current()->RunAllPending(); 744 MessageLoop::current()->RunAllPending();
734 EXPECT_EQ(kFileOperationSucceeded, status()); 745 EXPECT_EQ(kFileOperationSucceeded, status());
735 746
736 // Check that its length is now 17 and that it's all zeroes after the test 747 // Check that its length is now 17 and that it's all zeroes after the test
737 // data. 748 // data.
738 base::PlatformFileInfo info; 749 base::PlatformFileInfo info;
739 750
740 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); 751 EXPECT_TRUE(file_util::GetFileInfo(file, &info));
741 EXPECT_EQ(length, info.size); 752 EXPECT_EQ(length, info.size);
742 char data[100]; 753 char data[100];
743 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); 754 EXPECT_EQ(length, file_util::ReadFile(file, data, length));
744 for (int i = 0; i < length; ++i) { 755 for (int i = 0; i < length; ++i) {
745 if (i < static_cast<int>(sizeof(test_data))) 756 if (i < static_cast<int>(sizeof(test_data)))
746 EXPECT_EQ(test_data[i], data[i]); 757 EXPECT_EQ(test_data[i], data[i]);
747 else 758 else
748 EXPECT_EQ(0, data[i]); 759 EXPECT_EQ(0, data[i]);
749 } 760 }
750 761
751 // Shorten the file by truncating it. 762 // Shorten the file by truncating it.
752 length = 3; 763 length = 3;
753 operation()->Truncate(file, length); 764 operation()->Truncate(URLForPath(file), length);
754 MessageLoop::current()->RunAllPending(); 765 MessageLoop::current()->RunAllPending();
755 EXPECT_EQ(kFileOperationSucceeded, status()); 766 EXPECT_EQ(kFileOperationSucceeded, status());
756 767
757 // Check that its length is now 3 and that it contains only bits of test data. 768 // Check that its length is now 3 and that it contains only bits of test data.
758 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); 769 EXPECT_TRUE(file_util::GetFileInfo(file, &info));
759 EXPECT_EQ(length, info.size); 770 EXPECT_EQ(length, info.size);
760 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); 771 EXPECT_EQ(length, file_util::ReadFile(file, data, length));
761 for (int i = 0; i < length; ++i) 772 for (int i = 0; i < length; ++i)
762 EXPECT_EQ(test_data[i], data[i]); 773 EXPECT_EQ(test_data[i], data[i]);
763 } 774 }
764 775
765 } // namespace fileapi 776 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_operation.cc ('k') | webkit/fileapi/file_system_path_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698