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

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

Issue 6881078: Modify error code of move/copy preparation. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
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_file_util.cc ('k') | no next file » | 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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ScopedTempDir src_dir; 154 ScopedTempDir src_dir;
155 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 155 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
156 156
157 ScopedTempDir dest_dir; 157 ScopedTempDir dest_dir;
158 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 158 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
159 FilePath dest_file; 159 FilePath dest_file;
160 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); 160 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
161 161
162 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_file)); 162 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_file));
163 MessageLoop::current()->RunAllPending(); 163 MessageLoop::current()->RunAllPending();
164 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); 164 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
165 } 165 }
166 166
167 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) { 167 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestNonEmptyDir) {
168 // 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.
169 ScopedTempDir src_dir; 169 ScopedTempDir src_dir;
170 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 170 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
171 171
172 ScopedTempDir dest_dir; 172 ScopedTempDir dest_dir;
173 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 173 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
174 FilePath child_file; 174 FilePath child_file;
175 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file); 175 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
176 176
177 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path())); 177 operation()->Move(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
178 MessageLoop::current()->RunAllPending(); 178 MessageLoop::current()->RunAllPending();
179 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); 179 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
180 } 180 }
181 181
182 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) { 182 TEST_F(FileSystemOperationTest, TestMoveFailureSrcFileExistsDestDir) {
183 // Src exists and is a file. Dest is a directory. 183 // Src exists and is a file. Dest is a directory.
184 ScopedTempDir src_dir; 184 ScopedTempDir src_dir;
185 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 185 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
186 FilePath src_file; 186 FilePath src_file;
187 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 187 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
188 188
189 ScopedTempDir dest_dir; 189 ScopedTempDir dest_dir;
190 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 190 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
191 191
192 operation()->Move(URLForPath(src_file), URLForPath(dest_dir.path())); 192 operation()->Move(URLForPath(src_file), URLForPath(dest_dir.path()));
193 MessageLoop::current()->RunAllPending(); 193 MessageLoop::current()->RunAllPending();
194 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 194 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
195 } 195 }
196 196
197 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) { 197 TEST_F(FileSystemOperationTest, TestMoveFailureDestParentDoesntExist) {
198 // Dest. parent path does not exist. 198 // Dest. parent path does not exist.
199 ScopedTempDir src_dir; 199 ScopedTempDir src_dir;
200 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 200 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
201 FilePath nonexisting_file = base_.path().Append( 201 FilePath nonexisting_file = base_.path().Append(
202 FILE_PATH_LITERAL("NonexistingDir")).Append( 202 FILE_PATH_LITERAL("NonexistingDir")).Append(
203 FILE_PATH_LITERAL("NonexistingFile")); 203 FILE_PATH_LITERAL("NonexistingFile"));
204 204
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 ScopedTempDir src_dir; 318 ScopedTempDir src_dir;
319 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 319 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
320 320
321 ScopedTempDir dest_dir; 321 ScopedTempDir dest_dir;
322 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 322 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
323 FilePath dest_file; 323 FilePath dest_file;
324 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file); 324 file_util::CreateTemporaryFileInDir(dest_dir.path(), &dest_file);
325 325
326 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_file)); 326 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_file));
327 MessageLoop::current()->RunAllPending(); 327 MessageLoop::current()->RunAllPending();
328 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY, status()); 328 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
329 } 329 }
330 330
331 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) { 331 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestNonEmptyDir) {
332 // Src exists and is a directory. Dest is a non-empty directory. 332 // Src exists and is a directory. Dest is a non-empty directory.
333 ScopedTempDir src_dir; 333 ScopedTempDir src_dir;
334 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 334 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
335 335
336 ScopedTempDir dest_dir; 336 ScopedTempDir dest_dir;
337 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 337 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
338 FilePath child_file; 338 FilePath child_file;
339 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file); 339 file_util::CreateTemporaryFileInDir(dest_dir.path(), &child_file);
340 340
341 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path())); 341 operation()->Copy(URLForPath(src_dir.path()), URLForPath(dest_dir.path()));
342 MessageLoop::current()->RunAllPending(); 342 MessageLoop::current()->RunAllPending();
343 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status()); 343 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_EMPTY, status());
344 } 344 }
345 345
346 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) { 346 TEST_F(FileSystemOperationTest, TestCopyFailureSrcFileExistsDestDir) {
347 // Src exists and is a file. Dest is a directory. 347 // Src exists and is a file. Dest is a directory.
348 ScopedTempDir src_dir; 348 ScopedTempDir src_dir;
349 ASSERT_TRUE(src_dir.CreateUniqueTempDir()); 349 ASSERT_TRUE(src_dir.CreateUniqueTempDir());
350 FilePath src_file; 350 FilePath src_file;
351 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file); 351 file_util::CreateTemporaryFileInDir(src_dir.path(), &src_file);
352 352
353 ScopedTempDir dest_dir; 353 ScopedTempDir dest_dir;
354 ASSERT_TRUE(dest_dir.CreateUniqueTempDir()); 354 ASSERT_TRUE(dest_dir.CreateUniqueTempDir());
355 355
356 operation()->Copy(URLForPath(src_file), URLForPath(dest_dir.path())); 356 operation()->Copy(URLForPath(src_file), URLForPath(dest_dir.path()));
357 MessageLoop::current()->RunAllPending(); 357 MessageLoop::current()->RunAllPending();
358 EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_A_FILE, status()); 358 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, status());
359 } 359 }
360 360
361 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) { 361 TEST_F(FileSystemOperationTest, TestCopyFailureDestParentDoesntExist) {
362 // Dest. parent path does not exist. 362 // Dest. parent path does not exist.
363 ScopedTempDir dir; 363 ScopedTempDir dir;
364 ASSERT_TRUE(dir.CreateUniqueTempDir()); 364 ASSERT_TRUE(dir.CreateUniqueTempDir());
365 FilePath src_dir = dir.path(); 365 FilePath src_dir = dir.path();
366 366
367 FilePath nonexisting(base_.path().Append(FILE_PATH_LITERAL("DontExistDir"))); 367 FilePath nonexisting(base_.path().Append(FILE_PATH_LITERAL("DontExistDir")));
368 file_util::EnsureEndsWithSeparator(&nonexisting); 368 file_util::EnsureEndsWithSeparator(&nonexisting);
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 779
780 // Check that its length is now 3 and that it contains only bits of test data. 780 // Check that its length is now 3 and that it contains only bits of test data.
781 EXPECT_TRUE(file_util::GetFileInfo(file, &info)); 781 EXPECT_TRUE(file_util::GetFileInfo(file, &info));
782 EXPECT_EQ(length, info.size); 782 EXPECT_EQ(length, info.size);
783 EXPECT_EQ(length, file_util::ReadFile(file, data, length)); 783 EXPECT_EQ(length, file_util::ReadFile(file, data, length));
784 for (int i = 0; i < length; ++i) 784 for (int i = 0; i < length; ++i)
785 EXPECT_EQ(test_data[i], data[i]); 785 EXPECT_EQ(test_data[i], data[i]);
786 } 786 }
787 787
788 } // namespace fileapi 788 } // namespace fileapi
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_file_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698