| 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 GDataRootDirectory::CACHE_TYPE_TMP, | 185 GDataRootDirectory::CACHE_TYPE_TMP, |
| 186 GDataFileSystem::CACHED_FILE_FROM_SERVER); | 186 GDataFileSystem::CACHED_FILE_FROM_SERVER); |
| 187 } | 187 } |
| 188 | 188 |
| 189 GDataFileBase* FindFile(const FilePath& file_path) { | 189 GDataFileBase* FindFile(const FilePath& file_path) { |
| 190 ReadOnlyFindFileDelegate search_delegate; | 190 ReadOnlyFindFileDelegate search_delegate; |
| 191 file_system_->FindFileByPathSync(file_path, &search_delegate); | 191 file_system_->FindFileByPathSync(file_path, &search_delegate); |
| 192 return search_delegate.file(); | 192 return search_delegate.file(); |
| 193 } | 193 } |
| 194 | 194 |
| 195 GDataFileBase* FindFileByResourceId(const std::string& resource_id) { |
| 196 ReadOnlyFindFileDelegate search_delegate; |
| 197 file_system_->FindFileByPathSync(FilePath(FILE_PATH_LITERAL("gdata")), |
| 198 &search_delegate); |
| 199 return search_delegate.file()->AsGDataRootDirectory()->GetFileByResource( |
| 200 resource_id); |
| 201 } |
| 202 |
| 195 void FindAndTestFilePath(const FilePath& file_path) { | 203 void FindAndTestFilePath(const FilePath& file_path) { |
| 196 GDataFileBase* file = FindFile(file_path); | 204 GDataFileBase* file = FindFile(file_path); |
| 197 ASSERT_TRUE(file) << "File can't be found " << file_path.value(); | 205 ASSERT_TRUE(file) << "File can't be found " << file_path.value(); |
| 198 EXPECT_EQ(file->GetFilePath(), file_path); | 206 EXPECT_EQ(file->GetFilePath(), file_path); |
| 199 } | 207 } |
| 200 | 208 |
| 201 GDataFileBase* FindFileByResource(const std::string& resource) { | 209 GDataFileBase* FindFileByResource(const std::string& resource) { |
| 202 return file_system_->root_->GetFileByResource(resource); | 210 return file_system_->root_->GetFileByResource(resource); |
| 203 } | 211 } |
| 204 | 212 |
| (...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Feed 1 File.txt"))); | 927 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Feed 1 File.txt"))); |
| 920 FindAndTestFilePath( | 928 FindAndTestFilePath( |
| 921 FilePath(FILE_PATH_LITERAL( | 929 FilePath(FILE_PATH_LITERAL( |
| 922 "gdata/Directory 1/Feed 1 SubDirectory File.txt"))); | 930 "gdata/Directory 1/Feed 1 SubDirectory File.txt"))); |
| 923 | 931 |
| 924 // Test second feed elements. | 932 // Test second feed elements. |
| 925 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Feed 2 File.txt"))); | 933 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Feed 2 File.txt"))); |
| 926 FindAndTestFilePath( | 934 FindAndTestFilePath( |
| 927 FilePath(FILE_PATH_LITERAL( | 935 FilePath(FILE_PATH_LITERAL( |
| 928 "gdata/Directory 1/Sub Directory Folder/Feed 2 Directory"))); | 936 "gdata/Directory 1/Sub Directory Folder/Feed 2 Directory"))); |
| 937 |
| 938 // Make sure orphaned files didn't make into the file system. |
| 939 ASSERT_FALSE(FindFileByResourceId("file:orphan_file_resource_id")); |
| 940 ASSERT_FALSE(FindFileByResourceId("folder:orphan_feed_folder_resouce_id")); |
| 941 ASSERT_FALSE(FindFileByResourceId("file:orphan_subfolder_file_resource_id")); |
| 929 } | 942 } |
| 930 | 943 |
| 931 TEST_F(GDataFileSystemTest, CopyNotExistingFile) { | 944 TEST_F(GDataFileSystemTest, CopyNotExistingFile) { |
| 932 FilePath src_file_path(FILE_PATH_LITERAL("gdata/Dummy file.txt")); | 945 FilePath src_file_path(FILE_PATH_LITERAL("gdata/Dummy file.txt")); |
| 933 FilePath dest_file_path(FILE_PATH_LITERAL("gdata/Test.log")); | 946 FilePath dest_file_path(FILE_PATH_LITERAL("gdata/Test.log")); |
| 934 | 947 |
| 935 LoadRootFeedDocument("root_feed.json"); | 948 LoadRootFeedDocument("root_feed.json"); |
| 936 | 949 |
| 937 GDataFileBase* src_file = NULL; | 950 GDataFileBase* src_file = NULL; |
| 938 EXPECT_TRUE((src_file = FindFile(src_file_path)) == NULL); | 951 EXPECT_TRUE((src_file = FindFile(src_file_path)) == NULL); |
| (...skipping 1276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2215 | 2228 |
| 2216 // Verify account meta feed is saved to cache. | 2229 // Verify account meta feed is saved to cache. |
| 2217 RunAllPendingForCache(); // Flush all cache operations. | 2230 RunAllPendingForCache(); // Flush all cache operations. |
| 2218 FilePath path = file_system_->cache_paths_[ | 2231 FilePath path = file_system_->cache_paths_[ |
| 2219 GDataRootDirectory::CACHE_TYPE_META].Append( | 2232 GDataRootDirectory::CACHE_TYPE_META].Append( |
| 2220 FILE_PATH_LITERAL("account_metadata.json")); | 2233 FILE_PATH_LITERAL("account_metadata.json")); |
| 2221 EXPECT_TRUE(file_util::PathExists(path)); | 2234 EXPECT_TRUE(file_util::PathExists(path)); |
| 2222 } | 2235 } |
| 2223 | 2236 |
| 2224 } // namespace gdata | 2237 } // namespace gdata |
| OLD | NEW |