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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 PathToVerify(const FilePath& in_path_to_scan, | 107 PathToVerify(const FilePath& in_path_to_scan, |
108 const FilePath& in_expected_existing_path) : | 108 const FilePath& in_expected_existing_path) : |
109 path_to_scan(in_path_to_scan), | 109 path_to_scan(in_path_to_scan), |
110 expected_existing_path(in_expected_existing_path) { | 110 expected_existing_path(in_expected_existing_path) { |
111 } | 111 } |
112 | 112 |
113 FilePath path_to_scan; | 113 FilePath path_to_scan; |
114 FilePath expected_existing_path; | 114 FilePath expected_existing_path; |
115 }; | 115 }; |
116 | 116 |
| 117 struct SearchResultPair { |
| 118 const char* search_path; |
| 119 const char* real_path; |
| 120 }; |
| 121 |
| 122 // Callback to GDataFileSystem::SearchAsync used in ContentSearch test. |
| 123 // Verifies that returned proto buffer contains entries specified in search |
| 124 // feed, and that treing file names are formatted like |
| 125 // "<resource_id>.<file_name>". |
| 126 void ContentSearchCallback(MessageLoop* message_loop, |
| 127 base::PlatformFileError error, |
| 128 scoped_ptr<gdata::GDataDirectoryProto> dir_proto) { |
| 129 ASSERT_EQ(base::PLATFORM_FILE_OK, error); |
| 130 ASSERT_TRUE(dir_proto.get()); |
| 131 |
| 132 // Search feed contains 2 entries. One file (SubDirectory File 1.txt) and one |
| 133 // directory (Directory 1). Entries generated from the fedd should have names |
| 134 // in format resource_id.actual_file_name. |
| 135 ASSERT_EQ(1, dir_proto->child_files_size()); |
| 136 EXPECT_EQ("file:2_file_resouce_id.SubDirectory File 1.txt", |
| 137 dir_proto->child_files(0).gdata_entry().file_name()); |
| 138 |
| 139 ASSERT_EQ(1, dir_proto->child_directories_size()); |
| 140 EXPECT_EQ("folder:1_folder_resource_id.Directory 1", |
| 141 dir_proto->child_directories(0).gdata_entry().file_name()); |
| 142 |
| 143 message_loop->Quit(); |
| 144 } |
| 145 |
117 } // anonymous namespace | 146 } // anonymous namespace |
118 | 147 |
119 namespace gdata { | 148 namespace gdata { |
120 | 149 |
121 class MockFreeDiskSpaceGetter : public FreeDiskSpaceGetterInterface { | 150 class MockFreeDiskSpaceGetter : public FreeDiskSpaceGetterInterface { |
122 public: | 151 public: |
123 virtual ~MockFreeDiskSpaceGetter() {} | 152 virtual ~MockFreeDiskSpaceGetter() {} |
124 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64()); | 153 MOCK_CONST_METHOD0(AmountOfFreeDiskSpace, int64()); |
125 }; | 154 }; |
126 | 155 |
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 TEST_F(GDataFileSystemTest, DuplicatedAsyncInitialization) { | 1157 TEST_F(GDataFileSystemTest, DuplicatedAsyncInitialization) { |
1129 int counter = 0; | 1158 int counter = 0; |
1130 ReadDirectoryCallback callback = base::Bind( | 1159 ReadDirectoryCallback callback = base::Bind( |
1131 &AsyncInitializationCallback, | 1160 &AsyncInitializationCallback, |
1132 &counter, | 1161 &counter, |
1133 2, | 1162 2, |
1134 FilePath(FILE_PATH_LITERAL("gdata")), | 1163 FilePath(FILE_PATH_LITERAL("gdata")), |
1135 &message_loop_); | 1164 &message_loop_); |
1136 | 1165 |
1137 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | 1166 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
1138 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, _)).Times(1); | 1167 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, _, _)).Times(1); |
1139 | 1168 |
1140 file_system_->ReadDirectoryByPathAsync( | 1169 file_system_->ReadDirectoryByPathAsync( |
1141 FilePath(FILE_PATH_LITERAL("gdata")), callback); | 1170 FilePath(FILE_PATH_LITERAL("gdata")), callback); |
1142 file_system_->ReadDirectoryByPathAsync( | 1171 file_system_->ReadDirectoryByPathAsync( |
1143 FilePath(FILE_PATH_LITERAL("gdata")), callback); | 1172 FilePath(FILE_PATH_LITERAL("gdata")), callback); |
1144 message_loop_.Run(); // Wait to get our result | 1173 message_loop_.Run(); // Wait to get our result |
1145 EXPECT_EQ(2, counter); | 1174 EXPECT_EQ(2, counter); |
1146 } | 1175 } |
1147 | 1176 |
1148 TEST_F(GDataFileSystemTest, SearchRootDirectory) { | 1177 TEST_F(GDataFileSystemTest, SearchRootDirectory) { |
(...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3069 | 3098 |
3070 file_system_->GetFileByResourceId(file->resource_id(), callback, | 3099 file_system_->GetFileByResourceId(file->resource_id(), callback, |
3071 GetDownloadDataCallback()); | 3100 GetDownloadDataCallback()); |
3072 RunAllPendingForIO(); | 3101 RunAllPendingForIO(); |
3073 | 3102 |
3074 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); | 3103 EXPECT_EQ(REGULAR_FILE, callback_helper_->file_type_); |
3075 EXPECT_EQ(downloaded_file.value(), | 3104 EXPECT_EQ(downloaded_file.value(), |
3076 callback_helper_->download_path_.value()); | 3105 callback_helper_->download_path_.value()); |
3077 } | 3106 } |
3078 | 3107 |
| 3108 TEST_F(GDataFileSystemTest, ContentSearch) { |
| 3109 LoadRootFeedDocument("root_feed.json"); |
| 3110 |
| 3111 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "foo", _)) |
| 3112 .Times(1); |
| 3113 |
| 3114 ReadDirectoryCallback callback = base::Bind( |
| 3115 &ContentSearchCallback, |
| 3116 &message_loop_); |
| 3117 |
| 3118 file_system_->SearchAsync("foo", callback); |
| 3119 message_loop_.Run(); // Wait to get our result |
| 3120 |
| 3121 const SearchResultPair kSearchResultPairs[] = { |
| 3122 { "gdata/.search/foo/file:2_file_resouce_id.SubDirectory File 1.txt", |
| 3123 "gdata/Directory 1/SubDirectory File 1.txt" }, |
| 3124 { "gdata/.search/foo/folder:1_folder_resource_id.Directory 1", |
| 3125 "gdata/Directory 1" }, |
| 3126 { "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3127 "SubDirectory File 1.txt", |
| 3128 "gdata/Directory 1/SubDirectory File 1.txt" } |
| 3129 }; |
| 3130 |
| 3131 for (size_t i = 0; i < arraysize(kSearchResultPairs); ++i) { |
| 3132 FilePath search_file_path(FILE_PATH_LITERAL( |
| 3133 kSearchResultPairs[i].search_path)); |
| 3134 FilePath real_file_path(FILE_PATH_LITERAL( |
| 3135 kSearchResultPairs[i].real_path)); |
| 3136 |
| 3137 GDataEntry* search_file_entry = FindEntry(search_file_path); |
| 3138 ASSERT_TRUE(search_file_entry) |
| 3139 << "Can't find " << search_file_path.value(); |
| 3140 |
| 3141 GDataEntry* real_file_entry = FindEntry(real_file_path); |
| 3142 ASSERT_TRUE(real_file_entry) |
| 3143 << "Can't find " << real_file_path.value(); |
| 3144 |
| 3145 EXPECT_EQ(search_file_entry, real_file_entry); |
| 3146 } |
| 3147 } |
| 3148 |
| 3149 TEST_F(GDataFileSystemTest, ContentSearch_Delete) { |
| 3150 LoadRootFeedDocument("root_feed.json"); |
| 3151 |
| 3152 EXPECT_CALL(*mock_doc_service_, DeleteDocument(_, _)).Times(1); |
| 3153 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3154 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); |
| 3155 |
| 3156 FilePath search_file_path(FILE_PATH_LITERAL( |
| 3157 "gdata/.search/foo/file:2_file_resouce_id.SubDirectory File 1.txt")); |
| 3158 FilePath real_file_path(FILE_PATH_LITERAL( |
| 3159 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3160 |
| 3161 ASSERT_TRUE(FindEntry(real_file_path)); |
| 3162 ASSERT_TRUE(FindEntry(search_file_path)); |
| 3163 |
| 3164 FileOperationCallback callback = |
| 3165 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3166 callback_helper_.get()); |
| 3167 |
| 3168 file_system_->Remove(search_file_path, false, callback); |
| 3169 message_loop_.RunAllPending(); // Wait to get our result |
| 3170 |
| 3171 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3172 |
| 3173 EXPECT_FALSE(FindEntry(real_file_path)); |
| 3174 EXPECT_FALSE(FindEntry(search_file_path)); |
| 3175 } |
| 3176 |
| 3177 TEST_F(GDataFileSystemTest, ContentSearch_RenameResult) { |
| 3178 LoadRootFeedDocument("root_feed.json"); |
| 3179 |
| 3180 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3181 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); |
| 3182 |
| 3183 EXPECT_CALL(*mock_doc_service_, RenameResource( |
| 3184 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3185 "SubDirectory File 1.txt.renamed", _)) |
| 3186 .Times(1); |
| 3187 |
| 3188 FilePath source_path_search(FILE_PATH_LITERAL( |
| 3189 "gdata/.search/foo/file:2_file_resouce_id.SubDirectory File 1.txt")); |
| 3190 FilePath source_path_real(FILE_PATH_LITERAL( |
| 3191 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3192 |
| 3193 FilePath renamed_path_search(FILE_PATH_LITERAL( |
| 3194 "gdata/.search/foo/" |
| 3195 "file:2_file_resouce_id.SubDirectory File 1.txt.renamed")); |
| 3196 FilePath renamed_path_real(FILE_PATH_LITERAL( |
| 3197 "gdata/Directory 1/SubDirectory File 1.txt.renamed")); |
| 3198 |
| 3199 FileOperationCallback callback = |
| 3200 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3201 callback_helper_.get()); |
| 3202 |
| 3203 file_system_->Move(source_path_search, renamed_path_search, callback); |
| 3204 message_loop_.RunAllPending(); |
| 3205 |
| 3206 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3207 |
| 3208 EXPECT_FALSE(FindEntry(source_path_real)); |
| 3209 EXPECT_FALSE(FindEntry(source_path_search)); |
| 3210 |
| 3211 EXPECT_TRUE(FindEntry(renamed_path_real)); |
| 3212 EXPECT_TRUE(FindEntry(renamed_path_search)); |
| 3213 } |
| 3214 |
| 3215 TEST_F(GDataFileSystemTest, ContentSearch_Move) { |
| 3216 LoadRootFeedDocument("root_feed.json"); |
| 3217 |
| 3218 // Setup directory observer mocks. |
| 3219 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3220 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); |
| 3221 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3222 Eq(FilePath(FILE_PATH_LITERAL( |
| 3223 "gdata/Directory 1/Sub Directory Folder"))))) |
| 3224 .Times(1); |
| 3225 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3226 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); |
| 3227 |
| 3228 // Setup documents service mocks. |
| 3229 EXPECT_CALL(*mock_doc_service_, RenameResource( |
| 3230 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3231 "SubDirectory File 1.txt.dest", _)) |
| 3232 .Times(1); |
| 3233 EXPECT_CALL(*mock_doc_service_, RemoveResourceFromDirectory( |
| 3234 Eq(GURL("https://1_folder_content_url/")), |
| 3235 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3236 "file:2_file_resouce_id", _)) |
| 3237 .Times(1); |
| 3238 EXPECT_CALL(*mock_doc_service_, AddResourceToDirectory( |
| 3239 Eq(GURL("https://1_folder_content_url/")), |
| 3240 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), _)) |
| 3241 .Times(1); |
| 3242 |
| 3243 // Start the test. |
| 3244 FilePath source_path_search(FILE_PATH_LITERAL( |
| 3245 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3246 "SubDirectory File 1.txt")); |
| 3247 FilePath source_path_real(FILE_PATH_LITERAL( |
| 3248 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3249 |
| 3250 FilePath destination_path_search(FILE_PATH_LITERAL( |
| 3251 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3252 "Sub Directory Folder/SubDirectory File 1.txt.dest")); |
| 3253 FilePath destination_path_real(FILE_PATH_LITERAL( |
| 3254 "gdata/Directory 1/Sub Directory Folder/SubDirectory File 1.txt.dest")); |
| 3255 |
| 3256 ASSERT_TRUE(FindEntry(source_path_search)); |
| 3257 ASSERT_TRUE(FindEntry(source_path_real)); |
| 3258 |
| 3259 FileOperationCallback callback = |
| 3260 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3261 callback_helper_.get()); |
| 3262 |
| 3263 file_system_->Move(source_path_search, destination_path_search, callback); |
| 3264 message_loop_.RunAllPending(); |
| 3265 |
| 3266 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3267 |
| 3268 EXPECT_FALSE(FindEntry(source_path_search)); |
| 3269 EXPECT_FALSE(FindEntry(source_path_real)); |
| 3270 |
| 3271 EXPECT_TRUE(FindEntry(destination_path_search)); |
| 3272 EXPECT_TRUE(FindEntry(destination_path_real)); |
| 3273 } |
| 3274 |
| 3275 // Move file to gdata file system from search result directory. |
| 3276 TEST_F(GDataFileSystemTest, ContentSearch_MoveToGData) { |
| 3277 LoadRootFeedDocument("root_feed.json"); |
| 3278 |
| 3279 // Setup directory observer mocks. |
| 3280 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3281 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); |
| 3282 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3283 Eq(FilePath(FILE_PATH_LITERAL( |
| 3284 "gdata/Directory 1/Sub Directory Folder"))))) |
| 3285 .Times(1); |
| 3286 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3287 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); |
| 3288 |
| 3289 // Setup documents service mocks. |
| 3290 EXPECT_CALL(*mock_doc_service_, RenameResource( |
| 3291 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3292 "SubDirectory File 1.txt.dest", _)) |
| 3293 .Times(1); |
| 3294 EXPECT_CALL(*mock_doc_service_, RemoveResourceFromDirectory( |
| 3295 Eq(GURL("https://1_folder_content_url/")), |
| 3296 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3297 "file:2_file_resouce_id", _)) |
| 3298 .Times(1); |
| 3299 EXPECT_CALL(*mock_doc_service_, AddResourceToDirectory( |
| 3300 Eq(GURL("https://1_folder_content_url/")), |
| 3301 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), _)) |
| 3302 .Times(1); |
| 3303 |
| 3304 // Statr the test. |
| 3305 FilePath source_path_search(FILE_PATH_LITERAL( |
| 3306 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3307 "SubDirectory File 1.txt")); |
| 3308 FilePath source_path_real(FILE_PATH_LITERAL( |
| 3309 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3310 |
| 3311 FilePath destination_path_search(FILE_PATH_LITERAL( |
| 3312 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3313 "Sub Directory Folder/SubDirectory File 1.txt.dest")); |
| 3314 FilePath destination_path_real(FILE_PATH_LITERAL( |
| 3315 "gdata/Directory 1/Sub Directory Folder/SubDirectory File 1.txt.dest")); |
| 3316 |
| 3317 ASSERT_TRUE(FindEntry(source_path_search)); |
| 3318 ASSERT_TRUE(FindEntry(source_path_real)); |
| 3319 |
| 3320 FileOperationCallback callback = |
| 3321 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3322 callback_helper_.get()); |
| 3323 |
| 3324 file_system_->Move(source_path_search, destination_path_real, callback); |
| 3325 message_loop_.RunAllPending(); |
| 3326 |
| 3327 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3328 |
| 3329 EXPECT_FALSE(FindEntry(source_path_search)); |
| 3330 EXPECT_FALSE(FindEntry(source_path_real)); |
| 3331 |
| 3332 EXPECT_TRUE(FindEntry(destination_path_search)); |
| 3333 EXPECT_TRUE(FindEntry(destination_path_real)); |
| 3334 } |
| 3335 |
| 3336 TEST_F(GDataFileSystemTest, ContentSearch_MoveToSearch) { |
| 3337 LoadRootFeedDocument("root_feed.json"); |
| 3338 |
| 3339 // Setup directory observer mocks. |
| 3340 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3341 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); |
| 3342 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3343 Eq(FilePath(FILE_PATH_LITERAL( |
| 3344 "gdata/Directory 1/Sub Directory Folder"))))) |
| 3345 .Times(1); |
| 3346 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3347 Eq(FilePath(FILE_PATH_LITERAL("gdata"))))).Times(1); |
| 3348 |
| 3349 // Setup documents service mocks. |
| 3350 EXPECT_CALL(*mock_doc_service_, RenameResource( |
| 3351 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3352 "SubDirectory File 1.txt.dest", _)) |
| 3353 .Times(1); |
| 3354 EXPECT_CALL(*mock_doc_service_, RemoveResourceFromDirectory( |
| 3355 Eq(GURL("https://1_folder_content_url/")), |
| 3356 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), |
| 3357 "file:2_file_resouce_id", _)) |
| 3358 .Times(1); |
| 3359 EXPECT_CALL(*mock_doc_service_, AddResourceToDirectory( |
| 3360 Eq(GURL("https://1_folder_content_url/")), |
| 3361 Eq(GURL("https://dir1_file_link_self/file:2_file_resouce_id")), _)) |
| 3362 .Times(1); |
| 3363 |
| 3364 // Statr the test. |
| 3365 FilePath source_path_search(FILE_PATH_LITERAL( |
| 3366 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3367 "SubDirectory File 1.txt")); |
| 3368 FilePath source_path_real(FILE_PATH_LITERAL( |
| 3369 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3370 |
| 3371 FilePath destination_path_search(FILE_PATH_LITERAL( |
| 3372 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3373 "Sub Directory Folder/SubDirectory File 1.txt.dest")); |
| 3374 FilePath destination_path_real(FILE_PATH_LITERAL( |
| 3375 "gdata/Directory 1/Sub Directory Folder/SubDirectory File 1.txt.dest")); |
| 3376 |
| 3377 ASSERT_TRUE(FindEntry(source_path_search)); |
| 3378 ASSERT_TRUE(FindEntry(source_path_real)); |
| 3379 |
| 3380 FileOperationCallback callback = |
| 3381 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3382 callback_helper_.get()); |
| 3383 |
| 3384 file_system_->Move(source_path_real, destination_path_search, callback); |
| 3385 message_loop_.RunAllPending(); |
| 3386 |
| 3387 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3388 |
| 3389 EXPECT_FALSE(FindEntry(source_path_search)); |
| 3390 EXPECT_FALSE(FindEntry(source_path_real)); |
| 3391 |
| 3392 EXPECT_TRUE(FindEntry(destination_path_search)); |
| 3393 EXPECT_TRUE(FindEntry(destination_path_real)); |
| 3394 } |
| 3395 |
| 3396 TEST_F(GDataFileSystemTest, ContentSearch_CopyToSearchDirectory) { |
| 3397 LoadRootFeedDocument("root_feed.json"); |
| 3398 |
| 3399 FilePath src_file_path(FILE_PATH_LITERAL( |
| 3400 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3401 FilePath dest_file_path(FILE_PATH_LITERAL( |
| 3402 "gdata/.search/Directory 1")); |
| 3403 |
| 3404 FileOperationCallback callback = |
| 3405 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3406 callback_helper_.get()); |
| 3407 |
| 3408 file_system_->Copy(src_file_path, dest_file_path, callback); |
| 3409 message_loop_.RunAllPending(); |
| 3410 |
| 3411 EXPECT_NE(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3412 |
| 3413 EXPECT_TRUE(FindEntry(src_file_path)); |
| 3414 } |
| 3415 |
| 3416 TEST_F(GDataFileSystemTest, ContentSearch_CopyToSearchResultDirectory) { |
| 3417 LoadRootFeedDocument("root_feed.json"); |
| 3418 |
| 3419 FilePath src_file_path(FILE_PATH_LITERAL( |
| 3420 "gdata/Directory 1/SubDirectory File 1.txt")); |
| 3421 FilePath dest_file_path(FILE_PATH_LITERAL( |
| 3422 "gdata/.search/foo/Directory 1")); |
| 3423 |
| 3424 FileOperationCallback callback = |
| 3425 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3426 callback_helper_.get()); |
| 3427 |
| 3428 file_system_->Copy(src_file_path, dest_file_path, callback); |
| 3429 message_loop_.RunAllPending(); |
| 3430 |
| 3431 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
| 3432 callback_helper_->last_error_); |
| 3433 |
| 3434 EXPECT_TRUE(FindEntry(src_file_path)); |
| 3435 } |
| 3436 |
| 3437 TEST_F(GDataFileSystemTest, ContentSearch_CreateDirInSearchResultDirectory) { |
| 3438 LoadRootFeedDocument("root_feed.json"); |
| 3439 |
| 3440 FilePath dest_file_path(FILE_PATH_LITERAL( |
| 3441 "gdata/.search/foo/New Folder")); |
| 3442 |
| 3443 FileOperationCallback callback = |
| 3444 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3445 callback_helper_.get()); |
| 3446 |
| 3447 file_system_->CreateDirectory(dest_file_path, false, false, callback); |
| 3448 message_loop_.RunAllPending(); |
| 3449 |
| 3450 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
| 3451 callback_helper_->last_error_); |
| 3452 } |
| 3453 |
| 3454 TEST_F(GDataFileSystemTest, ContentSearch_CreateDirInSearchDirectory) { |
| 3455 LoadRootFeedDocument("root_feed.json"); |
| 3456 |
| 3457 FilePath dest_file_path(FILE_PATH_LITERAL( |
| 3458 "gdata/.search/New Folder")); |
| 3459 |
| 3460 FileOperationCallback callback = |
| 3461 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3462 callback_helper_.get()); |
| 3463 |
| 3464 file_system_->CreateDirectory(dest_file_path, false, false, callback); |
| 3465 message_loop_.RunAllPending(); |
| 3466 |
| 3467 EXPECT_EQ(base::PLATFORM_FILE_ERROR_INVALID_OPERATION, |
| 3468 callback_helper_->last_error_); |
| 3469 } |
| 3470 |
| 3471 TEST_F(GDataFileSystemTest, ContentSearch_CreateDirectory) { |
| 3472 LoadRootFeedDocument("root_feed.json"); |
| 3473 |
| 3474 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
| 3475 Eq(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))))).Times(1); |
| 3476 EXPECT_CALL(*mock_doc_service_, CreateDirectory( |
| 3477 Eq(GURL("https://1_folder_content_url/")), "FolderNew", _)).Times(1); |
| 3478 |
| 3479 FilePath search_dir_path(FILE_PATH_LITERAL( |
| 3480 "gdata/.search/foo/folder:1_folder_resource_id.Directory 1/" |
| 3481 "FolderNew")); |
| 3482 FilePath real_dir_path(FILE_PATH_LITERAL("gdata/Directory 1/FolderNew")); |
| 3483 |
| 3484 EXPECT_FALSE(FindEntry(search_dir_path)); |
| 3485 EXPECT_FALSE(FindEntry(real_dir_path)); |
| 3486 |
| 3487 FileOperationCallback callback = |
| 3488 base::Bind(&CallbackHelper::FileOperationCallback, |
| 3489 callback_helper_.get()); |
| 3490 |
| 3491 file_system_->CreateDirectory(search_dir_path, false, false, callback); |
| 3492 message_loop_.RunAllPending(); |
| 3493 |
| 3494 EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_); |
| 3495 |
| 3496 EXPECT_TRUE(FindEntry(search_dir_path)); |
| 3497 EXPECT_TRUE(FindEntry(real_dir_path)); |
| 3498 } |
3079 | 3499 |
3080 TEST_F(GDataFileSystemTest, GetAvailableSpace) { | 3500 TEST_F(GDataFileSystemTest, GetAvailableSpace) { |
3081 EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1); | 3501 EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1); |
3082 | 3502 |
3083 GetAvailableSpaceCallback callback = | 3503 GetAvailableSpaceCallback callback = |
3084 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, | 3504 base::Bind(&CallbackHelper::GetAvailableSpaceCallback, |
3085 callback_helper_.get()); | 3505 callback_helper_.get()); |
3086 | 3506 |
3087 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); | 3507 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)); |
3088 | 3508 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3139 EXPECT_EQ(1, num_callback_invocations_); | 3559 EXPECT_EQ(1, num_callback_invocations_); |
3140 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); | 3560 EXPECT_TRUE(CacheEntryExists(resource_id, md5)); |
3141 | 3561 |
3142 // Try to remove the file. | 3562 // Try to remove the file. |
3143 num_callback_invocations_ = 0; | 3563 num_callback_invocations_ = 0; |
3144 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); | 3564 TestRemoveFromCache(resource_id, base::PLATFORM_FILE_OK); |
3145 EXPECT_EQ(1, num_callback_invocations_); | 3565 EXPECT_EQ(1, num_callback_invocations_); |
3146 } | 3566 } |
3147 | 3567 |
3148 } // namespace gdata | 3568 } // namespace gdata |
OLD | NEW |