| OLD | NEW |
| 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/drive_file_system.h" | 5 #include "chrome/browser/chromeos/drive/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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 file_system_->change_list_loader(), | 206 file_system_->change_list_loader(), |
| 207 true, // is_delta_feed | 207 true, // is_delta_feed |
| 208 fake_drive_service_->GetRootResourceId(), | 208 fake_drive_service_->GetRootResourceId(), |
| 209 root_feed_changestamp_)) { | 209 root_feed_changestamp_)) { |
| 210 return false; | 210 return false; |
| 211 } | 211 } |
| 212 root_feed_changestamp_++; | 212 root_feed_changestamp_++; |
| 213 return true; | 213 return true; |
| 214 } | 214 } |
| 215 | 215 |
| 216 void AddDirectoryFromFile(const base::FilePath& directory_path, | 216 DriveFileError AddDirectory(const base::FilePath& directory_path) { |
| 217 const std::string& filename) { | |
| 218 scoped_ptr<Value> atom = google_apis::test_util::LoadJSONFile(filename); | |
| 219 ASSERT_TRUE(atom); | |
| 220 ASSERT_TRUE(atom->GetType() == Value::TYPE_DICTIONARY); | |
| 221 | |
| 222 DictionaryValue* dict_value = NULL; | |
| 223 Value* entry_value = NULL; | |
| 224 ASSERT_TRUE(atom->GetAsDictionary(&dict_value)); | |
| 225 ASSERT_TRUE(dict_value->Get("entry", &entry_value)); | |
| 226 | |
| 227 DictionaryValue* entry_dict = NULL; | |
| 228 ASSERT_TRUE(entry_value->GetAsDictionary(&entry_dict)); | |
| 229 | |
| 230 // Tweak entry title to match the last segment of the directory path | |
| 231 // (new directory name). | |
| 232 std::vector<base::FilePath::StringType> dir_parts; | |
| 233 directory_path.GetComponents(&dir_parts); | |
| 234 entry_dict->SetString("title.$t", dir_parts[dir_parts.size() - 1]); | |
| 235 | |
| 236 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 217 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 237 file_system_->CreateDirectory( | 218 file_system_->CreateDirectory( |
| 238 directory_path, | 219 directory_path, |
| 239 false, // is_exclusive | 220 false, // is_exclusive |
| 240 false, // is_recursive | 221 false, // is_recursive |
| 241 google_apis::test_util::CreateCopyResultCallback(&error)); | 222 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 242 google_apis::test_util::RunBlockingPoolTask(); | 223 google_apis::test_util::RunBlockingPoolTask(); |
| 243 EXPECT_EQ(DRIVE_FILE_OK, error); | 224 return error; |
| 244 } | 225 } |
| 245 | 226 |
| 246 bool RemoveEntry(const base::FilePath& file_path) { | 227 bool RemoveEntry(const base::FilePath& file_path) { |
| 247 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 228 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 248 file_system_->Remove( | 229 file_system_->Remove( |
| 249 file_path, false, | 230 file_path, false, |
| 250 google_apis::test_util::CreateCopyResultCallback(&error)); | 231 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 251 google_apis::test_util::RunBlockingPoolTask(); | 232 google_apis::test_util::RunBlockingPoolTask(); |
| 252 return error == DRIVE_FILE_OK; | 233 return error == DRIVE_FILE_OK; |
| 253 } | 234 } |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 "drive/root/Directory 1/Document 1 excludeDir-test.gdoc")); | 949 "drive/root/Directory 1/Document 1 excludeDir-test.gdoc")); |
| 969 EXPECT_FALSE(EntryExists(remote_dest_file_path)); | 950 EXPECT_FALSE(EntryExists(remote_dest_file_path)); |
| 970 | 951 |
| 971 // We'll add a file to the Drive root and then move to "Directory 1". | 952 // We'll add a file to the Drive root and then move to "Directory 1". |
| 972 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 953 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 973 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | 954 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 974 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 955 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 975 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) | 956 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/Directory 1"))))) |
| 976 .Times(1); | 957 .Times(1); |
| 977 | 958 |
| 978 // We'll copy a hosted document using CopyHostedDocument. | |
| 979 // ".gdoc" suffix should be stripped when copying. | |
| 980 scoped_ptr<base::Value> value = | |
| 981 google_apis::test_util::LoadJSONFile( | |
| 982 "chromeos/gdata/uploaded_document.json"); | |
| 983 scoped_ptr<google_apis::ResourceEntry> resource_entry = | |
| 984 google_apis::ResourceEntry::ExtractAndParse(*value); | |
| 985 | |
| 986 | |
| 987 // Transfer the local file to Drive. | 959 // Transfer the local file to Drive. |
| 988 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 960 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
| 989 file_system_->TransferFileFromLocalToRemote( | 961 file_system_->TransferFileFromLocalToRemote( |
| 990 local_src_file_path, | 962 local_src_file_path, |
| 991 remote_dest_file_path, | 963 remote_dest_file_path, |
| 992 google_apis::test_util::CreateCopyResultCallback(&error)); | 964 google_apis::test_util::CreateCopyResultCallback(&error)); |
| 993 google_apis::test_util::RunBlockingPoolTask(); | 965 google_apis::test_util::RunBlockingPoolTask(); |
| 994 | 966 |
| 995 EXPECT_EQ(DRIVE_FILE_OK, error); | 967 EXPECT_EQ(DRIVE_FILE_OK, error); |
| 996 | 968 |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); | 1263 base::FilePath dest_parent_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
| 1292 base::FilePath dest_file_path( | 1264 base::FilePath dest_file_path( |
| 1293 FILE_PATH_LITERAL("drive/root/New Folder 1/Test.log")); | 1265 FILE_PATH_LITERAL("drive/root/New Folder 1/Test.log")); |
| 1294 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); | 1266 base::FilePath interim_file_path(FILE_PATH_LITERAL("drive/root/Test.log")); |
| 1295 | 1267 |
| 1296 ASSERT_TRUE(LoadRootFeedDocument()); | 1268 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1297 | 1269 |
| 1298 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1270 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1299 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | 1271 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1300 | 1272 |
| 1301 AddDirectoryFromFile(dest_parent_path, | 1273 EXPECT_EQ(DRIVE_FILE_OK, AddDirectory(dest_parent_path)); |
| 1302 "chromeos/gdata/directory_entry_atom.json"); | |
| 1303 | 1274 |
| 1304 ASSERT_TRUE(EntryExists(src_file_path)); | 1275 ASSERT_TRUE(EntryExists(src_file_path)); |
| 1305 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( | 1276 scoped_ptr<DriveEntryProto> src_entry_proto = GetEntryInfoByPathSync( |
| 1306 src_file_path); | 1277 src_file_path); |
| 1307 ASSERT_TRUE(src_entry_proto); | 1278 ASSERT_TRUE(src_entry_proto); |
| 1308 std::string src_file_resource_id = | 1279 std::string src_file_resource_id = |
| 1309 src_entry_proto->resource_id(); | 1280 src_entry_proto->resource_id(); |
| 1310 EXPECT_FALSE(src_entry_proto->edit_url().empty()); | 1281 EXPECT_FALSE(src_entry_proto->edit_url().empty()); |
| 1311 | 1282 |
| 1312 ASSERT_TRUE(EntryExists(src_parent_path)); | 1283 ASSERT_TRUE(EntryExists(src_parent_path)); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1492 | 1463 |
| 1493 TEST_F(DriveFileSystemTest, CreateDirectory) { | 1464 TEST_F(DriveFileSystemTest, CreateDirectory) { |
| 1494 ASSERT_TRUE(LoadRootFeedDocument()); | 1465 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1495 | 1466 |
| 1496 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1467 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1497 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | 1468 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); |
| 1498 | 1469 |
| 1499 // Create directory in root. | 1470 // Create directory in root. |
| 1500 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); | 1471 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); |
| 1501 EXPECT_FALSE(EntryExists(dir_path)); | 1472 EXPECT_FALSE(EntryExists(dir_path)); |
| 1502 AddDirectoryFromFile(dir_path, "chromeos/gdata/directory_entry_atom.json"); | 1473 EXPECT_EQ(DRIVE_FILE_OK, AddDirectory(dir_path)); |
| 1503 EXPECT_TRUE(EntryExists(dir_path)); | 1474 EXPECT_TRUE(EntryExists(dir_path)); |
| 1504 | 1475 |
| 1505 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1476 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 1506 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) | 1477 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) |
| 1507 .Times(1); | 1478 .Times(1); |
| 1508 | 1479 |
| 1509 // Create directory in a sub directory. | 1480 // Create directory in a sub directory. |
| 1510 base::FilePath subdir_path( | 1481 base::FilePath subdir_path( |
| 1511 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2")); | 1482 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2")); |
| 1512 EXPECT_FALSE(EntryExists(subdir_path)); | 1483 EXPECT_FALSE(EntryExists(subdir_path)); |
| 1513 AddDirectoryFromFile(subdir_path, | 1484 EXPECT_EQ(DRIVE_FILE_OK, AddDirectory(subdir_path)); |
| 1514 "chromeos/gdata/directory_entry_atom2.json"); | |
| 1515 EXPECT_TRUE(EntryExists(subdir_path)); | 1485 EXPECT_TRUE(EntryExists(subdir_path)); |
| 1516 } | 1486 } |
| 1517 | 1487 |
| 1518 // Create a directory through the document service | |
| 1519 TEST_F(DriveFileSystemTest, CreateDirectoryWithService) { | |
| 1520 ASSERT_TRUE(LoadRootFeedDocument()); | |
| 1521 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
| 1522 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | |
| 1523 | |
| 1524 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | |
| 1525 file_system_->CreateDirectory( | |
| 1526 base::FilePath(FILE_PATH_LITERAL("drive/root/Sample Directory Title")), | |
| 1527 false, // is_exclusive | |
| 1528 true, // is_recursive | |
| 1529 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 1530 google_apis::test_util::RunBlockingPoolTask(); | |
| 1531 | |
| 1532 EXPECT_EQ(DRIVE_FILE_OK, error); | |
| 1533 } | |
| 1534 | |
| 1535 TEST_F(DriveFileSystemTest, PinAndUnpin) { | 1488 TEST_F(DriveFileSystemTest, PinAndUnpin) { |
| 1536 ASSERT_TRUE(LoadRootFeedDocument()); | 1489 ASSERT_TRUE(LoadRootFeedDocument()); |
| 1537 | 1490 |
| 1538 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); | 1491 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); |
| 1539 | 1492 |
| 1540 // Get the file info. | 1493 // Get the file info. |
| 1541 scoped_ptr<DriveEntryProto> entry(GetEntryInfoByPathSync(file_path)); | 1494 scoped_ptr<DriveEntryProto> entry(GetEntryInfoByPathSync(file_path)); |
| 1542 ASSERT_TRUE(entry); | 1495 ASSERT_TRUE(entry); |
| 1543 | 1496 |
| 1544 // Pin the file. | 1497 // Pin the file. |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2163 | 2116 |
| 2164 // An app for foo.exe should now be found, as the registry was loaded. | 2117 // An app for foo.exe should now be found, as the registry was loaded. |
| 2165 drive_webapps_registry_->GetWebAppsForFile( | 2118 drive_webapps_registry_->GetWebAppsForFile( |
| 2166 base::FilePath(FILE_PATH_LITERAL("foo.exe")), | 2119 base::FilePath(FILE_PATH_LITERAL("foo.exe")), |
| 2167 "" /* mime_type */, | 2120 "" /* mime_type */, |
| 2168 &apps); | 2121 &apps); |
| 2169 EXPECT_EQ(1U, apps.size()); | 2122 EXPECT_EQ(1U, apps.size()); |
| 2170 } | 2123 } |
| 2171 | 2124 |
| 2172 } // namespace drive | 2125 } // namespace drive |
| OLD | NEW |