Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_files_unittest.cc

Issue 10827211: Replace GDataDirectory::TakeEntry with GDataDirectoryService::AddEntryToDirectory. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: better tests Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/gdata/gdata_files.h" 5 #include "chrome/browser/chromeos/gdata/gdata_files.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 14 matching lines...) Expand all
25 25
26 // See gdata.proto for the difference between the two URLs. 26 // See gdata.proto for the difference between the two URLs.
27 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/"; 27 const char kResumableEditMediaUrl[] = "http://resumable-edit-media/";
28 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/"; 28 const char kResumableCreateMediaUrl[] = "http://resumable-create-media/";
29 29
30 // Add a directory to |parent| and return that directory. The name and 30 // Add a directory to |parent| and return that directory. The name and
31 // resource_id are determined by the incrementing counter |sequence_id|. 31 // resource_id are determined by the incrementing counter |sequence_id|.
32 GDataDirectory* AddDirectory(GDataDirectory* parent, 32 GDataDirectory* AddDirectory(GDataDirectory* parent,
33 GDataDirectoryService* directory_service, 33 GDataDirectoryService* directory_service,
34 int sequence_id) { 34 int sequence_id) {
35 GDataDirectory* dir = new GDataDirectory(parent, directory_service); 35 GDataDirectory* dir = new GDataDirectory(NULL, directory_service);
36 const std::string dir_name = "dir" + base::IntToString(sequence_id); 36 const std::string dir_name = "dir" + base::IntToString(sequence_id);
37 const std::string resource_id = std::string("dir_resource_id:") + 37 const std::string resource_id = std::string("dir_resource_id:") +
38 dir_name; 38 dir_name;
39 dir->set_title(dir_name); 39 dir->set_title(dir_name);
40 dir->set_resource_id(resource_id); 40 dir->set_resource_id(resource_id);
41 GDataFileError error = GDATA_FILE_ERROR_FAILED; 41 GDataFileError error = GDATA_FILE_ERROR_FAILED;
42 directory_service->AddEntryToDirectory( 42 FilePath moved_file_path;
43 directory_service->MoveEntryToDirectory(
43 parent->GetFilePath(), 44 parent->GetFilePath(),
44 dir, 45 dir,
45 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 46 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
47 &error,
48 &moved_file_path));
46 test_util::RunBlockingPoolTask(); 49 test_util::RunBlockingPoolTask();
47 EXPECT_EQ(GDATA_FILE_OK, error); 50 EXPECT_EQ(GDATA_FILE_OK, error);
51 EXPECT_EQ(parent->GetFilePath().AppendASCII(dir_name), moved_file_path);
48 return dir; 52 return dir;
49 } 53 }
50 54
51 // Add a file to |parent| and return that file. The name and 55 // Add a file to |parent| and return that file. The name and
52 // resource_id are determined by the incrementing counter |sequence_id|. 56 // resource_id are determined by the incrementing counter |sequence_id|.
53 GDataFile* AddFile(GDataDirectory* parent, 57 GDataFile* AddFile(GDataDirectory* parent,
54 GDataDirectoryService* directory_service, 58 GDataDirectoryService* directory_service,
55 int sequence_id) { 59 int sequence_id) {
56 GDataFile* file = new GDataFile(parent, directory_service); 60 GDataFile* file = new GDataFile(NULL, directory_service);
57 const std::string title = "file" + base::IntToString(sequence_id); 61 const std::string title = "file" + base::IntToString(sequence_id);
58 const std::string resource_id = std::string("file_resource_id:") + 62 const std::string resource_id = std::string("file_resource_id:") +
59 title; 63 title;
60 file->set_title(title); 64 file->set_title(title);
61 file->set_resource_id(resource_id); 65 file->set_resource_id(resource_id);
62 file->set_file_md5(std::string("file_md5:") + title); 66 file->set_file_md5(std::string("file_md5:") + title);
63 GDataFileError error = GDATA_FILE_ERROR_FAILED; 67 GDataFileError error = GDATA_FILE_ERROR_FAILED;
64 directory_service->AddEntryToDirectory( 68 FilePath moved_file_path;
69 directory_service->MoveEntryToDirectory(
65 parent->GetFilePath(), 70 parent->GetFilePath(),
66 file, 71 file,
67 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 72 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
73 &error,
74 &moved_file_path));
68 test_util::RunBlockingPoolTask(); 75 test_util::RunBlockingPoolTask();
69 EXPECT_EQ(GDATA_FILE_OK, error); 76 EXPECT_EQ(GDATA_FILE_OK, error);
77 EXPECT_EQ(parent->GetFilePath().AppendASCII(title), moved_file_path);
70 return file; 78 return file;
71 } 79 }
72 80
73 // Creates the following files/directories 81 // Creates the following files/directories
74 // drive/dir1/ 82 // drive/dir1/
75 // drive/dir2/ 83 // drive/dir2/
76 // drive/dir1/dir3/ 84 // drive/dir1/dir3/
77 // drive/dir1/file4 85 // drive/dir1/file4
78 // drive/dir1/file5 86 // drive/dir1/file5
79 // drive/dir2/file6 87 // drive/dir2/file6
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // No file should be added to the root directory. 375 // No file should be added to the root directory.
368 ASSERT_TRUE(root->child_files().empty()); 376 ASSERT_TRUE(root->child_files().empty());
369 // Two directories ("empty", "dir") should be added to the root directory. 377 // Two directories ("empty", "dir") should be added to the root directory.
370 ASSERT_EQ(2U, root->child_directories().size()); 378 ASSERT_EQ(2U, root->child_directories().size());
371 // The origin should change to FROM_CACHE because we loaded from the cache. 379 // The origin should change to FROM_CACHE because we loaded from the cache.
372 ASSERT_EQ(FROM_CACHE, directory_service.origin()); 380 ASSERT_EQ(FROM_CACHE, directory_service.origin());
373 } 381 }
374 382
375 TEST(GDataDirectoryServiceTest, RefreshFile) { 383 TEST(GDataDirectoryServiceTest, RefreshFile) {
376 MessageLoopForUI message_loop; 384 MessageLoopForUI message_loop;
385 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
386 &message_loop);
387
377 GDataDirectoryService directory_service; 388 GDataDirectoryService directory_service;
378 GDataDirectory* root(directory_service.root());
379 // Add a directory to the file system. 389 // Add a directory to the file system.
380 GDataDirectory* directory_entry = new GDataDirectory(root, 390 GDataDirectory* directory_entry = new GDataDirectory(NULL,
381 &directory_service); 391 &directory_service);
382 directory_entry->set_resource_id("folder:directory_resource_id"); 392 directory_entry->set_resource_id("folder:directory_resource_id");
383 directory_entry->set_title("directory"); 393 directory_entry->set_title("directory");
384 directory_entry->SetBaseNameFromTitle(); 394 directory_entry->SetBaseNameFromTitle();
385 GDataFileError error = GDATA_FILE_ERROR_FAILED; 395 GDataFileError error = GDATA_FILE_ERROR_FAILED;
386 directory_service.AddEntryToDirectory( 396 FilePath moved_file_path;
387 FilePath(kGDataRootDirectory), 397 FilePath root_path(kGDataRootDirectory);
398 directory_service.MoveEntryToDirectory(
399 root_path,
388 directory_entry, 400 directory_entry,
389 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 401 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
402 &error,
403 &moved_file_path));
390 test_util::RunBlockingPoolTask(); 404 test_util::RunBlockingPoolTask();
391 ASSERT_EQ(GDATA_FILE_OK, error); 405 ASSERT_EQ(GDATA_FILE_OK, error);
406 EXPECT_EQ(root_path.AppendASCII(directory_entry->base_name()),
407 moved_file_path);
392 408
393 // Add a new file to the directory. 409 // Add a new file to the directory.
394 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service); 410 GDataFile* initial_file_entry = new GDataFile(NULL, &directory_service);
395 initial_file_entry->set_resource_id("file:file_resource_id"); 411 initial_file_entry->set_resource_id("file:file_resource_id");
396 initial_file_entry->set_title("file"); 412 initial_file_entry->set_title("file");
397 initial_file_entry->SetBaseNameFromTitle(); 413 initial_file_entry->SetBaseNameFromTitle();
398 directory_service.AddEntryToDirectory( 414 error = GDATA_FILE_ERROR_FAILED;
415 moved_file_path.clear();
416 directory_service.MoveEntryToDirectory(
399 directory_entry->GetFilePath(), 417 directory_entry->GetFilePath(),
400 initial_file_entry, 418 initial_file_entry,
401 base::Bind(&test_util::CopyErrorCodeFromFileOperationCallback, &error)); 419 base::Bind(&test_util::CopyResultsFromFileMoveCallback,
420 &error,
421 &moved_file_path));
402 test_util::RunBlockingPoolTask(); 422 test_util::RunBlockingPoolTask();
403 ASSERT_EQ(GDATA_FILE_OK, error); 423 ASSERT_EQ(GDATA_FILE_OK, error);
424 EXPECT_EQ(directory_entry->GetFilePath().AppendASCII(
425 initial_file_entry->base_name()), moved_file_path);
404 426
405 ASSERT_EQ(directory_entry, initial_file_entry->parent()); 427 ASSERT_EQ(directory_entry, initial_file_entry->parent());
406 428
407 // Initial file system state set, let's try refreshing entries. 429 // Initial file system state set, let's try refreshing entries.
408 430
409 // New value for the entry with resource id "file:file_resource_id". 431 // New value for the entry with resource id "file:file_resource_id".
410 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service); 432 GDataFile* new_file_entry = new GDataFile(NULL, &directory_service);
411 new_file_entry->set_resource_id("file:file_resource_id"); 433 new_file_entry->set_resource_id("file:file_resource_id");
412 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass()); 434 directory_service.RefreshFile(scoped_ptr<GDataFile>(new_file_entry).Pass());
413 // Root should have |new_file_entry|, not |initial_file_entry|. 435 // Root should have |new_file_entry|, not |initial_file_entry|.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 GDataDirectoryService directory_service2; 637 GDataDirectoryService directory_service2;
616 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists. 638 // InitFromDB should succeed with GDATA_FILE_OK as the db now exists.
617 directory_service2.InitFromDB(db_path, blocking_task_runner, 639 directory_service2.InitFromDB(db_path, blocking_task_runner,
618 base::Bind(&InitFromDBCallback, GDATA_FILE_OK)); 640 base::Bind(&InitFromDBCallback, GDATA_FILE_OK));
619 test_util::RunBlockingPoolTask(); 641 test_util::RunBlockingPoolTask();
620 642
621 VerifyDirectoryService(&directory_service2); 643 VerifyDirectoryService(&directory_service2);
622 } 644 }
623 645
624 } // namespace gdata 646 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698