| 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 #include <string> | 5 #include <string> |
| 5 #include <vector> | 6 #include <vector> |
| 6 | 7 |
| 7 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 12 #include "base/string16.h" | 13 #include "base/string16.h" |
| 13 #include "base/time.h" | 14 #include "base/time.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 38 : ui_thread_(content::BrowserThread::UI, &message_loop_) { | 39 : ui_thread_(content::BrowserThread::UI, &message_loop_) { |
| 39 } | 40 } |
| 40 | 41 |
| 41 virtual void SetUp() { | 42 virtual void SetUp() { |
| 42 profile_.reset(new TestingProfile); | 43 profile_.reset(new TestingProfile); |
| 43 file_system_ = GDataFileSystemFactory::GetForProfile(profile_.get()); | 44 file_system_ = GDataFileSystemFactory::GetForProfile(profile_.get()); |
| 44 } | 45 } |
| 45 | 46 |
| 46 // Loads test json file as root ("/gdata") element. | 47 // Loads test json file as root ("/gdata") element. |
| 47 void LoadRootFeedDocument(const std::string& filename) { | 48 void LoadRootFeedDocument(const std::string& filename) { |
| 48 LoadSubdirFeedDocument(FilePath("gdata"), filename); | 49 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata")), filename); |
| 49 } | 50 } |
| 50 | 51 |
| 51 // Loads test json file as subdirectory content of |directory_path|. | 52 // Loads test json file as subdirectory content of |directory_path|. |
| 52 void LoadSubdirFeedDocument(const FilePath& directory_path, | 53 void LoadSubdirFeedDocument(const FilePath& directory_path, |
| 53 const std::string& filename) { | 54 const std::string& filename) { |
| 54 std::string error; | 55 std::string error; |
| 55 scoped_ptr<Value> document(LoadJSONFile(filename)); | 56 scoped_ptr<Value> document(LoadJSONFile(filename)); |
| 56 ASSERT_TRUE(document.get()); | 57 ASSERT_TRUE(document.get()); |
| 57 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); | 58 ASSERT_TRUE(document->GetType() == Value::TYPE_DICTIONARY); |
| 58 GURL unused; | 59 GURL unused; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 MOCK_METHOD2(OnEnterDirectory, FindFileTraversalCommand( | 177 MOCK_METHOD2(OnEnterDirectory, FindFileTraversalCommand( |
| 177 const FilePath&, GDataDirectory* dir)); | 178 const FilePath&, GDataDirectory* dir)); |
| 178 MOCK_METHOD1(OnError, void(base::PlatformFileError)); | 179 MOCK_METHOD1(OnError, void(base::PlatformFileError)); |
| 179 }; | 180 }; |
| 180 | 181 |
| 181 TEST_F(GDataFileSystemTest, SearchRootDirectory) { | 182 TEST_F(GDataFileSystemTest, SearchRootDirectory) { |
| 182 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 183 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 183 new MockFindFileDelegate(); | 184 new MockFindFileDelegate(); |
| 184 | 185 |
| 185 EXPECT_CALL(*mock_find_file_delegate.get(), | 186 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 186 OnDirectoryFound(FilePath("gdata"), _)) | 187 OnDirectoryFound(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 187 .Times(1); | 188 .Times(1); |
| 188 | 189 |
| 189 file_system_->FindFileByPath(FilePath("gdata"), | 190 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata")), |
| 190 mock_find_file_delegate); | 191 mock_find_file_delegate); |
| 191 } | 192 } |
| 192 | 193 |
| 193 TEST_F(GDataFileSystemTest, SearchExistingFile) { | 194 TEST_F(GDataFileSystemTest, SearchExistingFile) { |
| 194 LoadRootFeedDocument("root_feed.json"); | 195 LoadRootFeedDocument("root_feed.json"); |
| 195 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 196 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 196 new MockFindFileDelegate(); | 197 new MockFindFileDelegate(); |
| 197 | 198 |
| 198 EXPECT_CALL(*mock_find_file_delegate.get(), | 199 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 199 OnEnterDirectory(FilePath("gdata"), _)) | 200 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 200 .Times(1) | 201 .Times(1) |
| 201 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 202 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 202 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 203 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 203 .Times(1); | 204 .Times(1); |
| 204 | 205 |
| 205 file_system_->FindFileByPath(FilePath("gdata/File 1.txt"), | 206 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata/File 1.txt")), |
| 206 mock_find_file_delegate); | 207 mock_find_file_delegate); |
| 207 } | 208 } |
| 208 | 209 |
| 209 TEST_F(GDataFileSystemTest, SearchExistingDocument) { | 210 TEST_F(GDataFileSystemTest, SearchExistingDocument) { |
| 210 LoadRootFeedDocument("root_feed.json"); | 211 LoadRootFeedDocument("root_feed.json"); |
| 211 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 212 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 212 new MockFindFileDelegate(); | 213 new MockFindFileDelegate(); |
| 213 | 214 |
| 214 EXPECT_CALL(*mock_find_file_delegate.get(), | 215 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 215 OnEnterDirectory(FilePath("gdata"), _)) | 216 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 216 .Times(1) | 217 .Times(1) |
| 217 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 218 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 218 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 219 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 219 .Times(1); | 220 .Times(1); |
| 220 | 221 |
| 221 file_system_->FindFileByPath(FilePath("gdata/Document 1.gdocument"), | 222 file_system_->FindFileByPath( |
| 222 mock_find_file_delegate); | 223 FilePath(FILE_PATH_LITERAL("gdata/Document 1.gdocument")), |
| 224 mock_find_file_delegate); |
| 223 } | 225 } |
| 224 | 226 |
| 225 TEST_F(GDataFileSystemTest, SearchDuplicateNames) { | 227 TEST_F(GDataFileSystemTest, SearchDuplicateNames) { |
| 226 LoadRootFeedDocument("root_feed.json"); | 228 LoadRootFeedDocument("root_feed.json"); |
| 227 | 229 |
| 228 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 230 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 229 new MockFindFileDelegate(); | 231 new MockFindFileDelegate(); |
| 230 EXPECT_CALL(*mock_find_file_delegate.get(), | 232 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 231 OnEnterDirectory(FilePath("gdata"), _)) | 233 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 232 .Times(1) | 234 .Times(1) |
| 233 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 235 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 234 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 236 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 235 .Times(1); | 237 .Times(1); |
| 236 file_system_->FindFileByPath(FilePath("gdata/Duplicate Name.txt"), | 238 file_system_->FindFileByPath( |
| 237 mock_find_file_delegate); | 239 FilePath(FILE_PATH_LITERAL("gdata/Duplicate Name.txt")), |
| 240 mock_find_file_delegate); |
| 238 | 241 |
| 239 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate2 = | 242 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate2 = |
| 240 new MockFindFileDelegate(); | 243 new MockFindFileDelegate(); |
| 241 EXPECT_CALL(*mock_find_file_delegate2.get(), | 244 EXPECT_CALL(*mock_find_file_delegate2.get(), |
| 242 OnEnterDirectory(FilePath("gdata"), _)) | 245 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 243 .Times(1) | 246 .Times(1) |
| 244 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 247 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 245 EXPECT_CALL(*mock_find_file_delegate2.get(), OnFileFound(_)) | 248 EXPECT_CALL(*mock_find_file_delegate2.get(), OnFileFound(_)) |
| 246 .Times(1); | 249 .Times(1); |
| 247 file_system_->FindFileByPath(FilePath("gdata/Duplicate Name (2).txt"), | 250 file_system_->FindFileByPath( |
| 248 mock_find_file_delegate2); | 251 FilePath(FILE_PATH_LITERAL("gdata/Duplicate Name (2).txt")), |
| 252 mock_find_file_delegate2); |
| 249 } | 253 } |
| 250 | 254 |
| 251 TEST_F(GDataFileSystemTest, SearchExistingDirectory) { | 255 TEST_F(GDataFileSystemTest, SearchExistingDirectory) { |
| 252 LoadRootFeedDocument("root_feed.json"); | 256 LoadRootFeedDocument("root_feed.json"); |
| 253 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 257 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 254 new MockFindFileDelegate(); | 258 new MockFindFileDelegate(); |
| 255 | 259 |
| 256 EXPECT_CALL(*mock_find_file_delegate.get(), | 260 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 257 OnEnterDirectory(FilePath("gdata"), _)) | 261 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 258 .Times(1) | 262 .Times(1) |
| 259 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 263 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 260 EXPECT_CALL(*mock_find_file_delegate.get(), OnDirectoryFound(_, _)) | 264 EXPECT_CALL(*mock_find_file_delegate.get(), OnDirectoryFound(_, _)) |
| 261 .Times(1); | 265 .Times(1); |
| 262 | 266 |
| 263 file_system_->FindFileByPath(FilePath("gdata/Directory 1"), | 267 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 264 mock_find_file_delegate); | 268 mock_find_file_delegate); |
| 265 } | 269 } |
| 266 | 270 |
| 267 | 271 |
| 268 TEST_F(GDataFileSystemTest, SearchNonExistingFile) { | 272 TEST_F(GDataFileSystemTest, SearchNonExistingFile) { |
| 269 LoadRootFeedDocument("root_feed.json"); | 273 LoadRootFeedDocument("root_feed.json"); |
| 270 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 274 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 271 new MockFindFileDelegate(); | 275 new MockFindFileDelegate(); |
| 272 | 276 |
| 273 EXPECT_CALL(*mock_find_file_delegate.get(), | 277 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 274 OnEnterDirectory(FilePath("gdata"), _)) | 278 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 275 .Times(1) | 279 .Times(1) |
| 276 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 280 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 277 EXPECT_CALL(*mock_find_file_delegate.get(), | 281 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 278 OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND)) | 282 OnError(base::PLATFORM_FILE_ERROR_NOT_FOUND)) |
| 279 .Times(1); | 283 .Times(1); |
| 280 | 284 |
| 281 file_system_->FindFileByPath(FilePath("gdata/nonexisting.file"), | 285 file_system_->FindFileByPath( |
| 282 mock_find_file_delegate); | 286 FilePath(FILE_PATH_LITERAL("gdata/nonexisting.file")), |
| 287 mock_find_file_delegate); |
| 283 } | 288 } |
| 284 | 289 |
| 285 TEST_F(GDataFileSystemTest, StopFileSearch) { | 290 TEST_F(GDataFileSystemTest, StopFileSearch) { |
| 286 LoadRootFeedDocument("root_feed.json"); | 291 LoadRootFeedDocument("root_feed.json"); |
| 287 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 292 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 288 new MockFindFileDelegate(); | 293 new MockFindFileDelegate(); |
| 289 | 294 |
| 290 // Stop on first directory entry. | 295 // Stop on first directory entry. |
| 291 EXPECT_CALL(*mock_find_file_delegate.get(), | 296 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 292 OnEnterDirectory(FilePath("gdata"), _)) | 297 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 293 .Times(1) | 298 .Times(1) |
| 294 .WillOnce(Return(FindFileDelegate::FIND_FILE_TERMINATES)); | 299 .WillOnce(Return(FindFileDelegate::FIND_FILE_TERMINATES)); |
| 295 | 300 |
| 296 file_system_->FindFileByPath(FilePath("gdata/Directory 1"), | 301 file_system_->FindFileByPath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 297 mock_find_file_delegate); | 302 mock_find_file_delegate); |
| 298 } | 303 } |
| 299 | 304 |
| 300 TEST_F(GDataFileSystemTest, SearchInSubdir) { | 305 TEST_F(GDataFileSystemTest, SearchInSubdir) { |
| 301 LoadRootFeedDocument("root_feed.json"); | 306 LoadRootFeedDocument("root_feed.json"); |
| 302 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 307 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 308 "subdir_feed.json"); |
| 303 | 309 |
| 304 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = | 310 scoped_refptr<MockFindFileDelegate> mock_find_file_delegate = |
| 305 new MockFindFileDelegate(); | 311 new MockFindFileDelegate(); |
| 306 | 312 |
| 307 EXPECT_CALL(*mock_find_file_delegate.get(), | 313 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 308 OnEnterDirectory(FilePath("gdata"), _)) | 314 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata")), _)) |
| 309 .Times(1) | 315 .Times(1) |
| 310 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 316 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 311 | 317 |
| 312 EXPECT_CALL(*mock_find_file_delegate.get(), | 318 EXPECT_CALL(*mock_find_file_delegate.get(), |
| 313 OnEnterDirectory(FilePath("gdata/Directory 1"), _)) | 319 OnEnterDirectory(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 320 _)) |
| 314 .Times(1) | 321 .Times(1) |
| 315 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); | 322 .WillOnce(Return(FindFileDelegate::FIND_FILE_CONTINUES)); |
| 316 | 323 |
| 317 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) | 324 EXPECT_CALL(*mock_find_file_delegate.get(), OnFileFound(_)) |
| 318 .Times(1); | 325 .Times(1); |
| 319 | 326 |
| 320 file_system_->FindFileByPath( | 327 file_system_->FindFileByPath( |
| 321 FilePath("gdata/Directory 1/SubDirectory File 1.txt"), | 328 FilePath(FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt")), |
| 322 mock_find_file_delegate); | 329 mock_find_file_delegate); |
| 323 } | 330 } |
| 324 | 331 |
| 325 TEST_F(GDataFileSystemTest, FilePathTests) { | 332 TEST_F(GDataFileSystemTest, FilePathTests) { |
| 326 LoadRootFeedDocument("root_feed.json"); | 333 LoadRootFeedDocument("root_feed.json"); |
| 327 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 334 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 335 "subdir_feed.json"); |
| 328 | 336 |
| 329 FindAndTestFilePath(FilePath("gdata/File 1.txt")); | 337 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/File 1.txt"))); |
| 330 FindAndTestFilePath(FilePath("gdata/Directory 1")); | 338 FindAndTestFilePath(FilePath(FILE_PATH_LITERAL("gdata/Directory 1"))); |
| 331 FindAndTestFilePath(FilePath("gdata/Directory 1/SubDirectory File 1.txt")); | 339 FindAndTestFilePath( |
| 340 FilePath(FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt"))); |
| 332 } | 341 } |
| 333 | 342 |
| 334 TEST_F(GDataFileSystemTest, RemoveFiles) { | 343 TEST_F(GDataFileSystemTest, RemoveFiles) { |
| 335 LoadRootFeedDocument("root_feed.json"); | 344 LoadRootFeedDocument("root_feed.json"); |
| 336 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 345 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 346 "subdir_feed.json"); |
| 337 | 347 |
| 338 FilePath nonexisting_file("gdata/Dummy file.txt"); | 348 FilePath nonexisting_file(FILE_PATH_LITERAL("gdata/Dummy file.txt")); |
| 339 FilePath file_in_root("gdata/File 1.txt"); | 349 FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt")); |
| 340 FilePath dir_in_root("gdata/Directory 1"); | 350 FilePath dir_in_root(FILE_PATH_LITERAL("gdata/Directory 1")); |
| 341 FilePath file_in_subdir("gdata/Directory 1/SubDirectory File 1.txt"); | 351 FilePath file_in_subdir( |
| 352 FILE_PATH_LITERAL("gdata/Directory 1/SubDirectory File 1.txt")); |
| 342 | 353 |
| 343 EXPECT_TRUE(FindFile(file_in_root) != NULL); | 354 EXPECT_TRUE(FindFile(file_in_root) != NULL); |
| 344 EXPECT_TRUE(FindFile(dir_in_root) != NULL); | 355 EXPECT_TRUE(FindFile(dir_in_root) != NULL); |
| 345 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); | 356 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); |
| 346 | 357 |
| 347 // Remove first file in root. | 358 // Remove first file in root. |
| 348 EXPECT_TRUE(RemoveFile(file_in_root)); | 359 EXPECT_TRUE(RemoveFile(file_in_root)); |
| 349 EXPECT_TRUE(FindFile(file_in_root) == NULL); | 360 EXPECT_TRUE(FindFile(file_in_root) == NULL); |
| 350 EXPECT_TRUE(FindFile(dir_in_root) != NULL); | 361 EXPECT_TRUE(FindFile(dir_in_root) != NULL); |
| 351 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); | 362 EXPECT_TRUE(FindFile(file_in_subdir) != NULL); |
| 352 | 363 |
| 353 // Remove directory. | 364 // Remove directory. |
| 354 EXPECT_TRUE(RemoveFile(dir_in_root)); | 365 EXPECT_TRUE(RemoveFile(dir_in_root)); |
| 355 EXPECT_TRUE(FindFile(file_in_root) == NULL); | 366 EXPECT_TRUE(FindFile(file_in_root) == NULL); |
| 356 EXPECT_TRUE(FindFile(dir_in_root) == NULL); | 367 EXPECT_TRUE(FindFile(dir_in_root) == NULL); |
| 357 EXPECT_TRUE(FindFile(file_in_subdir) == NULL); | 368 EXPECT_TRUE(FindFile(file_in_subdir) == NULL); |
| 358 | 369 |
| 359 // Try removing file in already removed subdirectory. | 370 // Try removing file in already removed subdirectory. |
| 360 EXPECT_FALSE(RemoveFile(file_in_subdir)); | 371 EXPECT_FALSE(RemoveFile(file_in_subdir)); |
| 361 | 372 |
| 362 // Try removing non-existing file. | 373 // Try removing non-existing file. |
| 363 EXPECT_FALSE(RemoveFile(nonexisting_file)); | 374 EXPECT_FALSE(RemoveFile(nonexisting_file)); |
| 364 | 375 |
| 365 // Try removing root file element. | 376 // Try removing root file element. |
| 366 EXPECT_FALSE(RemoveFile(FilePath("gdata"))); | 377 EXPECT_FALSE(RemoveFile(FilePath(FILE_PATH_LITERAL("gdata")))); |
| 367 } | 378 } |
| 368 | 379 |
| 369 | |
| 370 TEST_F(GDataFileSystemTest, CreateDirectory) { | 380 TEST_F(GDataFileSystemTest, CreateDirectory) { |
| 371 LoadRootFeedDocument("root_feed.json"); | 381 LoadRootFeedDocument("root_feed.json"); |
| 372 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 382 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 383 "subdir_feed.json"); |
| 373 | 384 |
| 374 // Create directory in root. | 385 // Create directory in root. |
| 375 FilePath dir_path("gdata/New Folder 1"); | 386 FilePath dir_path(FILE_PATH_LITERAL("gdata/New Folder 1")); |
| 376 EXPECT_TRUE(FindFile(dir_path) == NULL); | 387 EXPECT_TRUE(FindFile(dir_path) == NULL); |
| 377 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); | 388 AddDirectoryFromFile(dir_path, "directory_entry_atom.json"); |
| 378 EXPECT_TRUE(FindFile(dir_path) != NULL); | 389 EXPECT_TRUE(FindFile(dir_path) != NULL); |
| 379 | 390 |
| 380 // Create directory in a sub dirrectory. | 391 // Create directory in a sub dirrectory. |
| 381 FilePath subdir_path("gdata/New Folder 1/New Folder 2"); | 392 FilePath subdir_path(FILE_PATH_LITERAL("gdata/New Folder 1/New Folder 2")); |
| 382 EXPECT_TRUE(FindFile(subdir_path) == NULL); | 393 EXPECT_TRUE(FindFile(subdir_path) == NULL); |
| 383 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); | 394 AddDirectoryFromFile(subdir_path, "directory_entry_atom.json"); |
| 384 EXPECT_TRUE(FindFile(subdir_path) != NULL); | 395 EXPECT_TRUE(FindFile(subdir_path) != NULL); |
| 385 } | 396 } |
| 386 | 397 |
| 387 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { | 398 TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) { |
| 388 LoadRootFeedDocument("root_feed.json"); | 399 LoadRootFeedDocument("root_feed.json"); |
| 389 LoadSubdirFeedDocument(FilePath("gdata/Directory 1"), "subdir_feed.json"); | 400 LoadSubdirFeedDocument(FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 401 "subdir_feed.json"); |
| 390 | 402 |
| 391 GURL last_dir_content_url; | 403 GURL last_dir_content_url; |
| 392 FilePath first_missing_parent_path; | 404 FilePath first_missing_parent_path; |
| 393 | 405 |
| 394 // Create directory in root. | 406 // Create directory in root. |
| 395 FilePath dir_path("gdata/New Folder 1"); | 407 FilePath dir_path(FILE_PATH_LITERAL("gdata/New Folder 1")); |
| 396 EXPECT_EQ( | 408 EXPECT_EQ( |
| 409 GDataFileSystem::FOUND_MISSING, |
| 397 file_system_->FindFirstMissingParentDirectory(dir_path, | 410 file_system_->FindFirstMissingParentDirectory(dir_path, |
| 398 &last_dir_content_url, | 411 &last_dir_content_url, |
| 399 &first_missing_parent_path), | 412 &first_missing_parent_path)); |
| 400 GDataFileSystem::FOUND_MISSING); | 413 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("gdata/New Folder 1")), |
| 401 EXPECT_EQ(dir_path, first_missing_parent_path); | 414 first_missing_parent_path); |
| 402 EXPECT_TRUE(last_dir_content_url.is_empty()); // root directory. | 415 EXPECT_TRUE(last_dir_content_url.is_empty()); // root directory. |
| 403 | 416 |
| 404 // Missing folders in subdir of an existing folder. | 417 // Missing folders in subdir of an existing folder. |
| 405 FilePath dir_path2("gdata/Directory 1/New Folder 2"); | 418 FilePath dir_path2(FILE_PATH_LITERAL("gdata/Directory 1/New Folder 2")); |
| 406 EXPECT_EQ( | 419 EXPECT_EQ( |
| 420 GDataFileSystem::FOUND_MISSING, |
| 407 file_system_->FindFirstMissingParentDirectory(dir_path2, | 421 file_system_->FindFirstMissingParentDirectory(dir_path2, |
| 408 &last_dir_content_url, | 422 &last_dir_content_url, |
| 409 &first_missing_parent_path), | 423 &first_missing_parent_path)); |
| 410 GDataFileSystem::FOUND_MISSING); | 424 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("gdata/Directory 1/New Folder 2")), |
| 411 EXPECT_EQ(dir_path2, first_missing_parent_path); | 425 first_missing_parent_path); |
| 412 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. | 426 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. |
| 413 | 427 |
| 414 // Missing two folders on the path. | 428 // Missing two folders on the path. |
| 415 FilePath dir_path3 = dir_path2.Append("Another Foder"); | 429 FilePath dir_path3 = dir_path2.Append(FILE_PATH_LITERAL("Another Foder")); |
| 416 EXPECT_EQ( | 430 EXPECT_EQ( |
| 431 GDataFileSystem::FOUND_MISSING, |
| 417 file_system_->FindFirstMissingParentDirectory(dir_path3, | 432 file_system_->FindFirstMissingParentDirectory(dir_path3, |
| 418 &last_dir_content_url, | 433 &last_dir_content_url, |
| 419 &first_missing_parent_path), | 434 &first_missing_parent_path)); |
| 420 GDataFileSystem::FOUND_MISSING); | 435 EXPECT_EQ(FilePath(FILE_PATH_LITERAL("gdata/Directory 1/New Folder 2")), |
| 421 EXPECT_EQ(dir_path3.DirName(), first_missing_parent_path); | 436 first_missing_parent_path); |
| 422 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. | 437 EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory. |
| 423 | 438 |
| 424 // Folders on top of an existing file. | 439 // Folders on top of an existing file. |
| 425 EXPECT_EQ( | 440 EXPECT_EQ( |
| 441 GDataFileSystem::FOUND_INVALID, |
| 426 file_system_->FindFirstMissingParentDirectory( | 442 file_system_->FindFirstMissingParentDirectory( |
| 427 FilePath("gdata/File 1.txt/BadDir"), | 443 FilePath(FILE_PATH_LITERAL("gdata/File 1.txt/BadDir")), |
| 428 &last_dir_content_url, | 444 &last_dir_content_url, |
| 429 &first_missing_parent_path), | 445 &first_missing_parent_path)); |
| 430 GDataFileSystem::FOUND_INVALID); | |
| 431 | 446 |
| 432 // Existing folder. | 447 // Existing folder. |
| 433 EXPECT_EQ( | 448 EXPECT_EQ( |
| 449 GDataFileSystem::DIRECTORY_ALREADY_PRESENT, |
| 434 file_system_->FindFirstMissingParentDirectory( | 450 file_system_->FindFirstMissingParentDirectory( |
| 435 FilePath("gdata/Directory 1"), | 451 FilePath(FILE_PATH_LITERAL("gdata/Directory 1")), |
| 436 &last_dir_content_url, | 452 &last_dir_content_url, |
| 437 &first_missing_parent_path), | 453 &first_missing_parent_path)); |
| 438 GDataFileSystem::DIRECTORY_ALREADY_PRESENT); | |
| 439 } | 454 } |
| 440 | 455 |
| 441 } // namespace gdata | 456 } // namespace gdata |
| OLD | NEW |