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

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

Issue 150113002: drive: Also lock SearchOperation when locking ChangeListLoader (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/change_list_loader.h" 5 #include "chrome/browser/chromeos/drive/change_list_loader.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 metadata_.reset(new ResourceMetadata( 93 metadata_.reset(new ResourceMetadata(
94 metadata_storage_.get(), base::MessageLoopProxy::current().get())); 94 metadata_storage_.get(), base::MessageLoopProxy::current().get()));
95 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize()); 95 ASSERT_EQ(FILE_ERROR_OK, metadata_->Initialize());
96 96
97 cache_.reset(new FileCache(metadata_storage_.get(), 97 cache_.reset(new FileCache(metadata_storage_.get(),
98 temp_dir_.path(), 98 temp_dir_.path(),
99 base::MessageLoopProxy::current().get(), 99 base::MessageLoopProxy::current().get(),
100 NULL /* free_disk_space_getter */)); 100 NULL /* free_disk_space_getter */));
101 ASSERT_TRUE(cache_->Initialize()); 101 ASSERT_TRUE(cache_->Initialize());
102 102
103 loader_controller_.reset(new LoaderController);
103 change_list_loader_.reset( 104 change_list_loader_.reset(
104 new ChangeListLoader(base::MessageLoopProxy::current().get(), 105 new ChangeListLoader(base::MessageLoopProxy::current().get(),
105 metadata_.get(), 106 metadata_.get(),
106 scheduler_.get(), 107 scheduler_.get(),
107 drive_service_.get())); 108 drive_service_.get(),
109 loader_controller_.get()));
108 } 110 }
109 111
110 // Adds a new file to the root directory of the service. 112 // Adds a new file to the root directory of the service.
111 scoped_ptr<google_apis::ResourceEntry> AddNewFile(const std::string& title) { 113 scoped_ptr<google_apis::ResourceEntry> AddNewFile(const std::string& title) {
112 google_apis::GDataErrorCode error = google_apis::GDATA_FILE_ERROR; 114 google_apis::GDataErrorCode error = google_apis::GDATA_FILE_ERROR;
113 scoped_ptr<google_apis::ResourceEntry> entry; 115 scoped_ptr<google_apis::ResourceEntry> entry;
114 drive_service_->AddNewFile( 116 drive_service_->AddNewFile(
115 "text/plain", 117 "text/plain",
116 "content text", 118 "content text",
117 drive_service_->GetRootResourceId(), 119 drive_service_->GetRootResourceId(),
118 title, 120 title,
119 false, // shared_with_me 121 false, // shared_with_me
120 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 122 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
121 base::RunLoop().RunUntilIdle(); 123 base::RunLoop().RunUntilIdle();
122 EXPECT_EQ(google_apis::HTTP_CREATED, error); 124 EXPECT_EQ(google_apis::HTTP_CREATED, error);
123 return entry.Pass(); 125 return entry.Pass();
124 } 126 }
125 127
126 content::TestBrowserThreadBundle thread_bundle_; 128 content::TestBrowserThreadBundle thread_bundle_;
127 base::ScopedTempDir temp_dir_; 129 base::ScopedTempDir temp_dir_;
128 scoped_ptr<TestingPrefServiceSimple> pref_service_; 130 scoped_ptr<TestingPrefServiceSimple> pref_service_;
129 scoped_ptr<FakeDriveService> drive_service_; 131 scoped_ptr<FakeDriveService> drive_service_;
130 scoped_ptr<JobScheduler> scheduler_; 132 scoped_ptr<JobScheduler> scheduler_;
131 scoped_ptr<ResourceMetadataStorage, 133 scoped_ptr<ResourceMetadataStorage,
132 test_util::DestroyHelperForTests> metadata_storage_; 134 test_util::DestroyHelperForTests> metadata_storage_;
133 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; 135 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_;
134 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; 136 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_;
137 scoped_ptr<LoaderController> loader_controller_;
135 scoped_ptr<ChangeListLoader> change_list_loader_; 138 scoped_ptr<ChangeListLoader> change_list_loader_;
136 }; 139 };
137 140
138 TEST_F(ChangeListLoaderTest, Load) { 141 TEST_F(ChangeListLoaderTest, Load) {
139 EXPECT_FALSE(change_list_loader_->IsRefreshing()); 142 EXPECT_FALSE(change_list_loader_->IsRefreshing());
140 143
141 // Start initial load. 144 // Start initial load.
142 TestChangeListLoaderObserver observer(change_list_loader_.get()); 145 TestChangeListLoaderObserver observer(change_list_loader_.get());
143 146
144 EXPECT_EQ(0, drive_service_->about_resource_load_count()); 147 EXPECT_EQ(0, drive_service_->about_resource_load_count());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 change_list_loader_->LoadForTesting( 189 change_list_loader_->LoadForTesting(
187 google_apis::test_util::CreateCopyResultCallback(&error)); 190 google_apis::test_util::CreateCopyResultCallback(&error));
188 base::RunLoop().RunUntilIdle(); 191 base::RunLoop().RunUntilIdle();
189 EXPECT_EQ(FILE_ERROR_OK, error); 192 EXPECT_EQ(FILE_ERROR_OK, error);
190 193
191 // Reset loader. 194 // Reset loader.
192 change_list_loader_.reset( 195 change_list_loader_.reset(
193 new ChangeListLoader(base::MessageLoopProxy::current().get(), 196 new ChangeListLoader(base::MessageLoopProxy::current().get(),
194 metadata_.get(), 197 metadata_.get(),
195 scheduler_.get(), 198 scheduler_.get(),
196 drive_service_.get())); 199 drive_service_.get(),
200 loader_controller_.get()));
197 201
198 // Add a file to the service. 202 // Add a file to the service.
199 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); 203 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File");
200 ASSERT_TRUE(gdata_entry); 204 ASSERT_TRUE(gdata_entry);
201 205
202 // Start loading. Because local metadata is available, the load results in 206 // Start loading. Because local metadata is available, the load results in
203 // returning FILE_ERROR_OK without fetching full list of resources. 207 // returning FILE_ERROR_OK without fetching full list of resources.
204 const int previous_resource_list_load_count = 208 const int previous_resource_list_load_count =
205 drive_service_->resource_list_load_count(); 209 drive_service_->resource_list_load_count();
206 TestChangeListLoaderObserver observer(change_list_loader_.get()); 210 TestChangeListLoaderObserver observer(change_list_loader_.get());
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 change_list_loader_->LoadForTesting( 437 change_list_loader_->LoadForTesting(
434 google_apis::test_util::CreateCopyResultCallback(&error)); 438 google_apis::test_util::CreateCopyResultCallback(&error));
435 base::RunLoop().RunUntilIdle(); 439 base::RunLoop().RunUntilIdle();
436 EXPECT_EQ(FILE_ERROR_OK, error); 440 EXPECT_EQ(FILE_ERROR_OK, error);
437 441
438 // Add a new file. 442 // Add a new file.
439 scoped_ptr<google_apis::ResourceEntry> file = AddNewFile("New File"); 443 scoped_ptr<google_apis::ResourceEntry> file = AddNewFile("New File");
440 ASSERT_TRUE(file); 444 ASSERT_TRUE(file);
441 445
442 // Lock the loader. 446 // Lock the loader.
443 scoped_ptr<base::ScopedClosureRunner> lock = change_list_loader_->GetLock(); 447 scoped_ptr<base::ScopedClosureRunner> lock = loader_controller_->GetLock();
444 448
445 // Start update. 449 // Start update.
446 TestChangeListLoaderObserver observer(change_list_loader_.get()); 450 TestChangeListLoaderObserver observer(change_list_loader_.get());
447 FileError check_for_updates_error = FILE_ERROR_FAILED; 451 FileError check_for_updates_error = FILE_ERROR_FAILED;
448 change_list_loader_->CheckForUpdates( 452 change_list_loader_->CheckForUpdates(
449 google_apis::test_util::CreateCopyResultCallback( 453 google_apis::test_util::CreateCopyResultCallback(
450 &check_for_updates_error)); 454 &check_for_updates_error));
451 base::RunLoop().RunUntilIdle(); 455 base::RunLoop().RunUntilIdle();
452 456
453 // Update is pending due to the lock. 457 // Update is pending due to the lock.
454 EXPECT_TRUE(observer.changed_directories().empty()); 458 EXPECT_TRUE(observer.changed_directories().empty());
455 459
456 // Unlock the loader, this should resume the pending udpate. 460 // Unlock the loader, this should resume the pending udpate.
457 lock.reset(); 461 lock.reset();
458 base::RunLoop().RunUntilIdle(); 462 base::RunLoop().RunUntilIdle();
459 EXPECT_EQ(1U, observer.changed_directories().count( 463 EXPECT_EQ(1U, observer.changed_directories().count(
460 util::GetDriveMyDriveRootPath())); 464 util::GetDriveMyDriveRootPath()));
461 } 465 }
462 466
463 } // namespace internal 467 } // namespace internal
464 } // namespace drive 468 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/change_list_loader.cc ('k') | chrome/browser/chromeos/drive/file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698