| 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/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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 file_system_->change_list_loader(), | 154 file_system_->change_list_loader(), |
| 155 true, // is_delta_feed | 155 true, // is_delta_feed |
| 156 fake_drive_service_->GetRootResourceId(), | 156 fake_drive_service_->GetRootResourceId(), |
| 157 root_feed_changestamp_)) { | 157 root_feed_changestamp_)) { |
| 158 return false; | 158 return false; |
| 159 } | 159 } |
| 160 root_feed_changestamp_++; | 160 root_feed_changestamp_++; |
| 161 return true; | 161 return true; |
| 162 } | 162 } |
| 163 | 163 |
| 164 FileError AddDirectory(const base::FilePath& directory_path) { | |
| 165 FileError error = FILE_ERROR_FAILED; | |
| 166 file_system_->CreateDirectory( | |
| 167 directory_path, | |
| 168 false, // is_exclusive | |
| 169 false, // is_recursive | |
| 170 google_apis::test_util::CreateCopyResultCallback(&error)); | |
| 171 google_apis::test_util::RunBlockingPoolTask(); | |
| 172 return error; | |
| 173 } | |
| 174 | 164 |
| 175 // Gets resource entry by path synchronously. | 165 // Gets resource entry by path synchronously. |
| 176 scoped_ptr<ResourceEntry> GetResourceEntryByPathSync( | 166 scoped_ptr<ResourceEntry> GetResourceEntryByPathSync( |
| 177 const base::FilePath& file_path) { | 167 const base::FilePath& file_path) { |
| 178 FileError error = FILE_ERROR_FAILED; | 168 FileError error = FILE_ERROR_FAILED; |
| 179 scoped_ptr<ResourceEntry> entry; | 169 scoped_ptr<ResourceEntry> entry; |
| 180 file_system_->GetResourceEntryByPath( | 170 file_system_->GetResourceEntryByPath( |
| 181 file_path, | 171 file_path, |
| 182 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 172 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
| 183 google_apis::test_util::RunBlockingPoolTask(); | 173 google_apis::test_util::RunBlockingPoolTask(); |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 google_apis::test_util::RunBlockingPoolTask(); | 1110 google_apis::test_util::RunBlockingPoolTask(); |
| 1121 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); | 1111 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); |
| 1122 | 1112 |
| 1123 EXPECT_TRUE(EntryExists(src_file_path)); | 1113 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1124 EXPECT_TRUE(EntryExists(src_file_path)); | 1114 EXPECT_TRUE(EntryExists(src_file_path)); |
| 1125 EXPECT_TRUE(EntryExists(dest_parent_path)); | 1115 EXPECT_TRUE(EntryExists(dest_parent_path)); |
| 1126 | 1116 |
| 1127 EXPECT_FALSE(EntryExists(dest_file_path)); | 1117 EXPECT_FALSE(EntryExists(dest_file_path)); |
| 1128 } | 1118 } |
| 1129 | 1119 |
| 1130 TEST_F(FileSystemTest, CreateDirectory) { | |
| 1131 ASSERT_TRUE(LoadRootFeedDocument()); | |
| 1132 | |
| 1133 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
| 1134 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root"))))).Times(1); | |
| 1135 | |
| 1136 // Create directory in root. | |
| 1137 base::FilePath dir_path(FILE_PATH_LITERAL("drive/root/New Folder 1")); | |
| 1138 EXPECT_FALSE(EntryExists(dir_path)); | |
| 1139 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(dir_path)); | |
| 1140 EXPECT_TRUE(EntryExists(dir_path)); | |
| 1141 | |
| 1142 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | |
| 1143 Eq(base::FilePath(FILE_PATH_LITERAL("drive/root/New Folder 1"))))) | |
| 1144 .Times(1); | |
| 1145 | |
| 1146 // Create directory in a sub directory. | |
| 1147 base::FilePath subdir_path( | |
| 1148 FILE_PATH_LITERAL("drive/root/New Folder 1/New Folder 2")); | |
| 1149 EXPECT_FALSE(EntryExists(subdir_path)); | |
| 1150 EXPECT_EQ(FILE_ERROR_OK, AddDirectory(subdir_path)); | |
| 1151 EXPECT_TRUE(EntryExists(subdir_path)); | |
| 1152 } | |
| 1153 | |
| 1154 TEST_F(FileSystemTest, CreateDirectoryByImplicitLoad) { | 1120 TEST_F(FileSystemTest, CreateDirectoryByImplicitLoad) { |
| 1155 // Intentionally *not* calling LoadRootFeedDocument(), for testing that | 1121 // Intentionally *not* calling LoadRootFeedDocument(), for testing that |
| 1156 // CreateDirectory ensures feed loading before it runs. | 1122 // CreateDirectory ensures feed loading before it runs. |
| 1157 | 1123 |
| 1158 base::FilePath existing_directory( | 1124 base::FilePath existing_directory( |
| 1159 FILE_PATH_LITERAL("drive/root/Directory 1")); | 1125 FILE_PATH_LITERAL("drive/root/Directory 1")); |
| 1160 FileError error = FILE_ERROR_FAILED; | 1126 FileError error = FILE_ERROR_FAILED; |
| 1161 file_system_->CreateDirectory( | 1127 file_system_->CreateDirectory( |
| 1162 existing_directory, | 1128 existing_directory, |
| 1163 true, // is_exclusive | 1129 true, // is_exclusive |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 entry->resource_id(), | 1674 entry->resource_id(), |
| 1709 entry->file_specific_info().file_md5(), | 1675 entry->file_specific_info().file_md5(), |
| 1710 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); | 1676 google_apis::test_util::CreateCopyResultCallback(&success, &cache_entry)); |
| 1711 google_apis::test_util::RunBlockingPoolTask(); | 1677 google_apis::test_util::RunBlockingPoolTask(); |
| 1712 | 1678 |
| 1713 EXPECT_TRUE(success); | 1679 EXPECT_TRUE(success); |
| 1714 EXPECT_FALSE(cache_entry.is_mounted()); | 1680 EXPECT_FALSE(cache_entry.is_mounted()); |
| 1715 } | 1681 } |
| 1716 | 1682 |
| 1717 } // namespace drive | 1683 } // namespace drive |
| OLD | NEW |