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

Side by Side Diff: chrome/browser/chromeos/drive/file_system_unittest.cc

Issue 343073003: Files.app: Provide detailed change information on onDirectoryChanged event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 5 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/drive/file_system.h" 5 #include "chrome/browser/chromeos/drive/file_system.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/prefs/testing_pref_service.h" 16 #include "base/prefs/testing_pref_service.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "chrome/browser/chromeos/drive/change_list_loader.h" 18 #include "chrome/browser/chromeos/drive/change_list_loader.h"
19 #include "chrome/browser/chromeos/drive/drive.pb.h" 19 #include "chrome/browser/chromeos/drive/drive.pb.h"
20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h" 20 #include "chrome/browser/chromeos/drive/fake_free_disk_space_getter.h"
21 #include "chrome/browser/chromeos/drive/file_change.h"
21 #include "chrome/browser/chromeos/drive/file_system_observer.h" 22 #include "chrome/browser/chromeos/drive/file_system_observer.h"
22 #include "chrome/browser/chromeos/drive/file_system_util.h" 23 #include "chrome/browser/chromeos/drive/file_system_util.h"
23 #include "chrome/browser/chromeos/drive/job_scheduler.h" 24 #include "chrome/browser/chromeos/drive/job_scheduler.h"
24 #include "chrome/browser/chromeos/drive/sync_client.h" 25 #include "chrome/browser/chromeos/drive/sync_client.h"
25 #include "chrome/browser/chromeos/drive/test_util.h" 26 #include "chrome/browser/chromeos/drive/test_util.h"
26 #include "chrome/browser/drive/drive_api_util.h" 27 #include "chrome/browser/drive/drive_api_util.h"
27 #include "chrome/browser/drive/event_logger.h" 28 #include "chrome/browser/drive/event_logger.h"
28 #include "chrome/browser/drive/fake_drive_service.h" 29 #include "chrome/browser/drive/fake_drive_service.h"
29 #include "chrome/browser/drive/test_util.h" 30 #include "chrome/browser/drive/test_util.h"
30 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
(...skipping 27 matching lines...) Expand all
58 public: 59 public:
59 MockDirectoryChangeObserver() {} 60 MockDirectoryChangeObserver() {}
60 virtual ~MockDirectoryChangeObserver() {} 61 virtual ~MockDirectoryChangeObserver() {}
61 62
62 // FileSystemObserver overrides. 63 // FileSystemObserver overrides.
63 virtual void OnDirectoryChanged( 64 virtual void OnDirectoryChanged(
64 const base::FilePath& directory_path) OVERRIDE { 65 const base::FilePath& directory_path) OVERRIDE {
65 changed_directories_.push_back(directory_path); 66 changed_directories_.push_back(directory_path);
66 } 67 }
67 68
69 virtual void OnFileChanged(const FileChange& new_file_change) OVERRIDE {
70 changed_files_.Apply(new_file_change);
71 }
72
68 const std::vector<base::FilePath>& changed_directories() const { 73 const std::vector<base::FilePath>& changed_directories() const {
69 return changed_directories_; 74 return changed_directories_;
70 } 75 }
71 76
77 const FileChange& changed_files() const { return changed_files_; }
78
72 private: 79 private:
73 std::vector<base::FilePath> changed_directories_; 80 std::vector<base::FilePath> changed_directories_;
81 FileChange changed_files_;
74 DISALLOW_COPY_AND_ASSIGN(MockDirectoryChangeObserver); 82 DISALLOW_COPY_AND_ASSIGN(MockDirectoryChangeObserver);
75 }; 83 };
76 84
77 } // namespace 85 } // namespace
78 86
79 class FileSystemTest : public testing::Test { 87 class FileSystemTest : public testing::Test {
80 protected: 88 protected:
81 virtual void SetUp() OVERRIDE { 89 virtual void SetUp() OVERRIDE {
82 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 90 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
83 pref_service_.reset(new TestingPrefServiceSimple); 91 pref_service_.reset(new TestingPrefServiceSimple);
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 // To test it, call CheckForUpdates and verify it does try to check 706 // To test it, call CheckForUpdates and verify it does try to check
699 // updates, which will cause directory changes. 707 // updates, which will cause directory changes.
700 fake_drive_service_->set_offline(false); 708 fake_drive_service_->set_offline(false);
701 709
702 file_system_->CheckForUpdates(); 710 file_system_->CheckForUpdates();
703 711
704 test_util::RunBlockingPoolTask(); 712 test_util::RunBlockingPoolTask();
705 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count()); 713 EXPECT_EQ(1, fake_drive_service_->about_resource_load_count());
706 EXPECT_EQ(1, fake_drive_service_->change_list_load_count()); 714 EXPECT_EQ(1, fake_drive_service_->change_list_load_count());
707 715
708 ASSERT_LE(1u, mock_directory_observer_->changed_directories().size()); 716 ASSERT_LE(0u, mock_directory_observer_->changed_directories().size());
717 ASSERT_LE(1u, mock_directory_observer_->changed_files().size());
709 } 718 }
710 719
711 TEST_F(FileSystemTest, ReadDirectoryWhileRefreshing) { 720 TEST_F(FileSystemTest, ReadDirectoryWhileRefreshing) {
712 // Use old timestamp so the fast fetch will be performed. 721 // Use old timestamp so the fast fetch will be performed.
713 ASSERT_NO_FATAL_FAILURE(SetUpTestFileSystem(USE_OLD_TIMESTAMP)); 722 ASSERT_NO_FATAL_FAILURE(SetUpTestFileSystem(USE_OLD_TIMESTAMP));
714 723
715 // The list of resources in "drive/root/Dir1" should be fetched. 724 // The list of resources in "drive/root/Dir1" should be fetched.
716 EXPECT_TRUE(ReadDirectorySync(base::FilePath( 725 EXPECT_TRUE(ReadDirectorySync(base::FilePath(
717 FILE_PATH_LITERAL("drive/root/Dir1")))); 726 FILE_PATH_LITERAL("drive/root/Dir1"))));
718 EXPECT_EQ(1, fake_drive_service_->directory_load_count()); 727 EXPECT_EQ(1, fake_drive_service_->directory_load_count());
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 file_system_->Unpin(file_path, 806 file_system_->Unpin(file_path,
798 google_apis::test_util::CreateCopyResultCallback(&error)); 807 google_apis::test_util::CreateCopyResultCallback(&error));
799 test_util::RunBlockingPoolTask(); 808 test_util::RunBlockingPoolTask();
800 EXPECT_EQ(FILE_ERROR_OK, error); 809 EXPECT_EQ(FILE_ERROR_OK, error);
801 810
802 entry = GetResourceEntrySync(file_path); 811 entry = GetResourceEntrySync(file_path);
803 ASSERT_TRUE(entry); 812 ASSERT_TRUE(entry);
804 EXPECT_FALSE(entry->file_specific_info().cache_state().is_pinned()); 813 EXPECT_FALSE(entry->file_specific_info().cache_state().is_pinned());
805 814
806 // Pinned file gets synced and it results in entry state changes. 815 // Pinned file gets synced and it results in entry state changes.
807 ASSERT_EQ(1u, mock_directory_observer_->changed_directories().size()); 816 ASSERT_EQ(0u, mock_directory_observer_->changed_directories().size());
808 EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("drive/root")), 817 ASSERT_EQ(1u, mock_directory_observer_->changed_files().size());
809 mock_directory_observer_->changed_directories()[0]); 818 EXPECT_EQ(1u,
819 mock_directory_observer_->changed_files().CountDirectory(
820 base::FilePath(FILE_PATH_LITERAL("drive/root"))));
810 } 821 }
811 822
812 TEST_F(FileSystemTest, PinAndUnpin_NotSynced) { 823 TEST_F(FileSystemTest, PinAndUnpin_NotSynced) {
813 ASSERT_TRUE(LoadFullResourceList()); 824 ASSERT_TRUE(LoadFullResourceList());
814 825
815 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt")); 826 base::FilePath file_path(FILE_PATH_LITERAL("drive/root/File 1.txt"));
816 827
817 // Get the file info. 828 // Get the file info.
818 scoped_ptr<ResourceEntry> entry(GetResourceEntrySync(file_path)); 829 scoped_ptr<ResourceEntry> entry(GetResourceEntrySync(file_path));
819 ASSERT_TRUE(entry); 830 ASSERT_TRUE(entry);
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 kEmbedOrigin, 916 kEmbedOrigin,
906 google_apis::test_util::CreateCopyResultCallback(&error, &share_url)); 917 google_apis::test_util::CreateCopyResultCallback(&error, &share_url));
907 test_util::RunBlockingPoolTask(); 918 test_util::RunBlockingPoolTask();
908 919
909 // Verify the share url to the sharing dialog. 920 // Verify the share url to the sharing dialog.
910 EXPECT_EQ(FILE_ERROR_OK, error); 921 EXPECT_EQ(FILE_ERROR_OK, error);
911 EXPECT_TRUE(share_url.is_valid()); 922 EXPECT_TRUE(share_url.is_valid());
912 } 923 }
913 924
914 } // namespace drive 925 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_system_observer.h ('k') | chrome/browser/chromeos/drive/sync/entry_revert_performer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698