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