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

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

Issue 15972002: Add MoveOperationTest for drive::file_system::MoveOperationTest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: I'm stupid Created 7 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 1115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1126
1127 ASSERT_TRUE(EntryExists(src_file_path)); 1127 ASSERT_TRUE(EntryExists(src_file_path));
1128 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync( 1128 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1129 src_file_path); 1129 src_file_path);
1130 ASSERT_TRUE(src_entry); 1130 ASSERT_TRUE(src_entry);
1131 std::string src_file_path_resource_id = src_entry->resource_id(); 1131 std::string src_file_path_resource_id = src_entry->resource_id();
1132 1132
1133 EXPECT_FALSE(EntryExists(dest_parent_path)); 1133 EXPECT_FALSE(EntryExists(dest_parent_path));
1134 1134
1135 FileError error = FILE_ERROR_OK; 1135 FileError error = FILE_ERROR_OK;
1136 file_system_->Move( 1136 file_system_->Copy(
1137 src_file_path, 1137 src_file_path,
1138 dest_file_path, 1138 dest_file_path,
1139 google_apis::test_util::CreateCopyResultCallback(&error)); 1139 google_apis::test_util::CreateCopyResultCallback(&error));
1140 google_apis::test_util::RunBlockingPoolTask(); 1140 google_apis::test_util::RunBlockingPoolTask();
1141 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error); 1141 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1142 1142
1143 EXPECT_TRUE(EntryExists(src_file_path)); 1143 EXPECT_TRUE(EntryExists(src_file_path));
1144 EXPECT_FALSE(EntryExists(dest_parent_path)); 1144 EXPECT_FALSE(EntryExists(dest_parent_path));
1145 EXPECT_FALSE(EntryExists(dest_file_path)); 1145 EXPECT_FALSE(EntryExists(dest_file_path));
1146 } 1146 }
(...skipping 29 matching lines...) Expand all
1176 google_apis::test_util::RunBlockingPoolTask(); 1176 google_apis::test_util::RunBlockingPoolTask();
1177 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); 1177 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
1178 1178
1179 EXPECT_TRUE(EntryExists(src_file_path)); 1179 EXPECT_TRUE(EntryExists(src_file_path));
1180 EXPECT_TRUE(EntryExists(src_file_path)); 1180 EXPECT_TRUE(EntryExists(src_file_path));
1181 EXPECT_TRUE(EntryExists(dest_parent_path)); 1181 EXPECT_TRUE(EntryExists(dest_parent_path));
1182 1182
1183 EXPECT_FALSE(EntryExists(dest_file_path)); 1183 EXPECT_FALSE(EntryExists(dest_file_path));
1184 } 1184 }
1185 1185
1186 TEST_F(DriveFileSystemTest, RenameFile) {
1187 const base::FilePath src_file_path(
1188 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1189 const base::FilePath src_parent_path(
1190 FILE_PATH_LITERAL("drive/root/Directory 1"));
1191 const base::FilePath dest_file_path(
1192 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log"));
1193
1194 ASSERT_TRUE(LoadRootFeedDocument());
1195
1196 ASSERT_TRUE(EntryExists(src_file_path));
1197 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1198 src_file_path);
1199 ASSERT_TRUE(src_entry);
1200 std::string src_file_resource_id =
1201 src_entry->resource_id();
1202
1203 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1204 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1205 .Times(1);
1206
1207 FileError error = FILE_ERROR_FAILED;
1208 file_system_->Move(
1209 src_file_path,
1210 dest_file_path,
1211 google_apis::test_util::CreateCopyResultCallback(&error));
1212 google_apis::test_util::RunBlockingPoolTask();
1213 EXPECT_EQ(FILE_ERROR_OK, error);
1214
1215 EXPECT_FALSE(EntryExists(src_file_path));
1216 EXPECT_TRUE(EntryExists(dest_file_path));
1217 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1218 }
1219
1220 TEST_F(DriveFileSystemTest, MoveFileFromRootToSubDirectory) {
1221 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1222 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
1223 base::FilePath dest_file_path(
1224 FILE_PATH_LITERAL("drive/root/Directory 1/Test.log"));
1225
1226 ASSERT_TRUE(LoadRootFeedDocument());
1227
1228 ASSERT_TRUE(EntryExists(src_file_path));
1229 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1230 src_file_path);
1231 ASSERT_TRUE(src_entry);
1232 std::string src_file_resource_id = src_entry->resource_id();
1233
1234 ASSERT_TRUE(EntryExists(dest_parent_path));
1235 scoped_ptr<ResourceEntry> dest_parent_proto = GetResourceEntryByPathSync(
1236 dest_parent_path);
1237 ASSERT_TRUE(dest_parent_proto);
1238 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1239
1240 // Expect notification for both source and destination directories.
1241 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1242 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1243 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1244 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1245 .Times(1);
1246
1247 FileError error = FILE_ERROR_FAILED;
1248 file_system_->Move(
1249 src_file_path,
1250 dest_file_path,
1251 google_apis::test_util::CreateCopyResultCallback(&error));
1252 google_apis::test_util::RunBlockingPoolTask();
1253 EXPECT_EQ(FILE_ERROR_OK, error);
1254
1255 EXPECT_FALSE(EntryExists(src_file_path));
1256 EXPECT_TRUE(EntryExists(dest_file_path));
1257 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1258 }
1259
1260 TEST_F(DriveFileSystemTest, MoveFileFromSubDirectoryToRoot) {
1261 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
1262 base::FilePath src_file_path(
1263 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1264 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1265
1266 ASSERT_TRUE(LoadRootFeedDocument());
1267
1268 ASSERT_TRUE(EntryExists(src_file_path));
1269 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1270 src_file_path);
1271 ASSERT_TRUE(src_entry);
1272 std::string src_file_resource_id = src_entry->resource_id();
1273
1274 ASSERT_TRUE(EntryExists(src_parent_path));
1275 scoped_ptr<ResourceEntry> src_parent_proto = GetResourceEntryByPathSync(
1276 src_parent_path);
1277 ASSERT_TRUE(src_parent_proto);
1278 ASSERT_TRUE(src_parent_proto->file_info().is_directory());
1279
1280 // Expect notification for both source and destination directories.
1281 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1282 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1283 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1284 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1285 .Times(1);
1286
1287 FileError error = FILE_ERROR_FAILED;
1288 file_system_->Move(
1289 src_file_path,
1290 dest_file_path,
1291 google_apis::test_util::CreateCopyResultCallback(&error));
1292 google_apis::test_util::RunBlockingPoolTask();
1293 EXPECT_EQ(FILE_ERROR_OK, error);
1294
1295 EXPECT_FALSE(EntryExists(src_file_path));
1296 ASSERT_TRUE(EntryExists(dest_file_path));
1297 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1298 }
1299
1300 TEST_F(DriveFileSystemTest, MoveFileBetweenSubDirectories) {
1301 base::FilePath src_parent_path(FILE_PATH_LITERAL("drive/root/Directory 1"));
1302 base::FilePath src_file_path(
1303 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1304 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/New Folder 1"));
1305 base::FilePath dest_file_path(
1306 FILE_PATH_LITERAL("drive/root/New Folder 1/Test.log"));
1307 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1308
1309 ASSERT_TRUE(LoadRootFeedDocument());
1310
1311 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1312 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1);
1313
1314 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(dest_parent_path));
1315
1316 ASSERT_TRUE(EntryExists(src_file_path));
1317 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1318 src_file_path);
1319 ASSERT_TRUE(src_entry);
1320 std::string src_file_resource_id = src_entry->resource_id();
1321
1322 ASSERT_TRUE(EntryExists(src_parent_path));
1323 scoped_ptr<ResourceEntry> src_parent_proto = GetResourceEntryByPathSync(
1324 src_parent_path);
1325 ASSERT_TRUE(src_parent_proto);
1326 ASSERT_TRUE(src_parent_proto->file_info().is_directory());
1327
1328 ASSERT_TRUE(EntryExists(dest_parent_path));
1329 scoped_ptr<ResourceEntry> dest_parent_proto = GetResourceEntryByPathSync(
1330 dest_parent_path);
1331 ASSERT_TRUE(dest_parent_proto);
1332 ASSERT_TRUE(dest_parent_proto->file_info().is_directory());
1333
1334 EXPECT_FALSE(EntryExists(interim_file_path));
1335
1336 // Expect notification for both source and destination directories.
1337 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1338 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1")))))
1339 .Times(1);
1340 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged(
1341 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1")))))
1342 .Times(1);
1343
1344 FileError error = FILE_ERROR_FAILED;
1345 file_system_->Move(
1346 src_file_path,
1347 dest_file_path,
1348 google_apis::test_util::CreateCopyResultCallback(&error));
1349 google_apis::test_util::RunBlockingPoolTask();
1350 EXPECT_EQ(FILE_ERROR_OK, error);
1351
1352 EXPECT_FALSE(EntryExists(src_file_path));
1353 EXPECT_FALSE(EntryExists(interim_file_path));
1354
1355 EXPECT_FALSE(EntryExists(src_file_path));
1356 EXPECT_TRUE(EntryExists(dest_file_path));
1357 EXPECT_EQ(src_file_resource_id, GetResourceIdByPath(dest_file_path));
1358 }
1359
1360 TEST_F(DriveFileSystemTest, MoveNotExistingFile) {
1361 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1362 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Test.log"));
1363
1364 ASSERT_TRUE(LoadRootFeedDocument());
1365
1366 EXPECT_FALSE(EntryExists(src_file_path));
1367
1368 FileError error = FILE_ERROR_OK;
1369 file_system_->Move(
1370 src_file_path,
1371 dest_file_path,
1372 google_apis::test_util::CreateCopyResultCallback(&error));
1373 google_apis::test_util::RunBlockingPoolTask();
1374 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1375
1376 EXPECT_FALSE(EntryExists(src_file_path));
1377 EXPECT_FALSE(EntryExists(dest_file_path));
1378 }
1379
1380 TEST_F(DriveFileSystemTest, MoveFileToNonExistingDirectory) {
1381 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1382 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/Dummy"));
1383 base::FilePath dest_file_path(FILE_PATH_LITERAL("drive/root/Dummy/Test.log"));
1384
1385 ASSERT_TRUE(LoadRootFeedDocument());
1386
1387 ASSERT_TRUE(EntryExists(src_file_path));
1388 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1389 src_file_path);
1390 ASSERT_TRUE(src_entry);
1391 std::string src_file_resource_id = src_entry->resource_id();
1392
1393 EXPECT_FALSE(EntryExists(dest_parent_path));
1394
1395 FileError error = FILE_ERROR_OK;
1396 file_system_->Move(
1397 src_file_path,
1398 dest_file_path,
1399 google_apis::test_util::CreateCopyResultCallback(&error));
1400 google_apis::test_util::RunBlockingPoolTask();
1401 EXPECT_EQ(FILE_ERROR_NOT_FOUND, error);
1402
1403 EXPECT_FALSE(EntryExists(dest_parent_path));
1404 EXPECT_FALSE(EntryExists(dest_file_path));
1405 }
1406
1407 // Test the case where the parent of |dest_file_path| is a existing file,
1408 // not a directory.
1409 TEST_F(DriveFileSystemTest, MoveFileToInvalidPath) {
1410 base::FilePath src_file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1411 base::FilePath dest_parent_path(
1412 FILE_PATH_LITERAL("drive/root/Duplicate Name.txt"));
1413 base::FilePath dest_file_path(FILE_PATH_LITERAL(
1414 "drive/root/Duplicate Name.txt/Test.log"));
1415
1416 ASSERT_TRUE(LoadRootFeedDocument());
1417
1418 ASSERT_TRUE(EntryExists(src_file_path));
1419 scoped_ptr<ResourceEntry> src_entry = GetResourceEntryByPathSync(
1420 src_file_path);
1421 ASSERT_TRUE(src_entry);
1422 std::string src_file_resource_id = src_entry->resource_id();
1423
1424 ASSERT_TRUE(EntryExists(dest_parent_path));
1425 scoped_ptr<ResourceEntry> dest_parent_proto = GetResourceEntryByPathSync(
1426 dest_parent_path);
1427 ASSERT_TRUE(dest_parent_proto);
1428
1429 FileError error = FILE_ERROR_OK;
1430 file_system_->Move(
1431 src_file_path,
1432 dest_file_path,
1433 google_apis::test_util::CreateCopyResultCallback(&error));
1434 google_apis::test_util::RunBlockingPoolTask();
1435 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
1436
1437 EXPECT_TRUE(EntryExists(src_file_path));
1438 EXPECT_TRUE(EntryExists(dest_parent_path));
1439 EXPECT_FALSE(EntryExists(dest_file_path));
1440 }
1441
1442 TEST_F(DriveFileSystemTest, RemoveEntries) { 1186 TEST_F(DriveFileSystemTest, RemoveEntries) {
1443 ASSERT_TRUE(LoadRootFeedDocument()); 1187 ASSERT_TRUE(LoadRootFeedDocument());
1444 1188
1445 base::FilePath nonexisting_file( 1189 base::FilePath nonexisting_file(
1446 FILE_PATH_LITERAL("drive/root/Dummy file.txt")); 1190 FILE_PATH_LITERAL("drive/root/Dummy file.txt"));
1447 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt")); 1191 base::FilePath file_in_root(FILE_PATH_LITERAL("drive/root/File 1.txt"));
1448 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1")); 1192 base::FilePath dir_in_root(FILE_PATH_LITERAL("drive/root/Directory 1"));
1449 base::FilePath file_in_subdir( 1193 base::FilePath file_in_subdir(
1450 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt")); 1194 FILE_PATH_LITERAL("drive/root/Directory 1/SubDirectory File 1.txt"));
1451 1195
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
2250 entry->resource_id(), 1994 entry->resource_id(),
2251 entry->file_specific_info().file_md5(), 1995 entry->file_specific_info().file_md5(),
2252 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); 1996 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry));
2253 google_apis::test_util::RunBlockingPoolTask(); 1997 google_apis::test_util::RunBlockingPoolTask();
2254 1998
2255 EXPECT_TRUE(success); 1999 EXPECT_TRUE(success);
2256 EXPECT_FALSE(cache_entry.is_mounted()); 2000 EXPECT_FALSE(cache_entry.is_mounted());
2257 } 2001 }
2258 2002
2259 } // namespace drive 2003 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system/touch_operation_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698