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

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

Issue 19641009: drive: Add test for ChangeListLoader::LoadIfNeeded with non empty DirectoryFetchInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix int type Created 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/prefs/testing_pref_service.h" 9 #include "base/prefs/testing_pref_service.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 private: 60 private:
61 ChangeListLoader* loader_; 61 ChangeListLoader* loader_;
62 std::set<base::FilePath> changed_directories_; 62 std::set<base::FilePath> changed_directories_;
63 int load_from_server_complete_count_; 63 int load_from_server_complete_count_;
64 int initial_load_complete_count_; 64 int initial_load_complete_count_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(TestChangeListLoaderObserver); 66 DISALLOW_COPY_AND_ASSIGN(TestChangeListLoaderObserver);
67 }; 67 };
68 68
69 class TestDriveService : public FakeDriveService {
70 public:
71 TestDriveService() : never_return_all_resource_list_(false),
72 blocked_call_count_(0) {}
73
74 void set_never_return_all_resource_list(bool value) {
75 never_return_all_resource_list_ = value;
76 }
77
78 int blocked_call_count() const { return blocked_call_count_; }
79
80 // FakeDriveService override.
81 virtual google_apis::CancelCallback GetAllResourceList(
82 const google_apis::GetResourceListCallback& callback) OVERRIDE {
83 if (never_return_all_resource_list_) {
84 ++blocked_call_count_;
85 return google_apis::CancelCallback();
86 }
87 return FakeDriveService::GetAllResourceList(callback);
88 }
89
90 private:
91 // GetAllResourceList never returns result when this is set to true.
92 // Used to emulate the real server's slowness.
93 bool never_return_all_resource_list_;
94
95 int blocked_call_count_; // Number of blocked method calls.
96 };
97
69 class ChangeListLoaderTest : public testing::Test { 98 class ChangeListLoaderTest : public testing::Test {
70 protected: 99 protected:
71 virtual void SetUp() OVERRIDE { 100 virtual void SetUp() OVERRIDE {
72 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 101 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
73 pref_service_.reset(new TestingPrefServiceSimple); 102 pref_service_.reset(new TestingPrefServiceSimple);
74 test_util::RegisterDrivePrefs(pref_service_->registry()); 103 test_util::RegisterDrivePrefs(pref_service_->registry());
75 104
76 drive_service_.reset(new FakeDriveService); 105 drive_service_.reset(new TestDriveService);
77 ASSERT_TRUE(drive_service_->LoadResourceListForWapi( 106 ASSERT_TRUE(drive_service_->LoadResourceListForWapi(
78 "gdata/root_feed.json")); 107 "gdata/root_feed.json"));
79 ASSERT_TRUE(drive_service_->LoadAccountMetadataForWapi( 108 ASSERT_TRUE(drive_service_->LoadAccountMetadataForWapi(
80 "gdata/account_metadata.json")); 109 "gdata/account_metadata.json"));
81 110
82 scheduler_.reset(new JobScheduler(pref_service_.get(), 111 scheduler_.reset(new JobScheduler(pref_service_.get(),
83 drive_service_.get(), 112 drive_service_.get(),
84 base::MessageLoopProxy::current().get())); 113 base::MessageLoopProxy::current().get()));
85 metadata_storage_.reset(new ResourceMetadataStorage( 114 metadata_storage_.reset(new ResourceMetadataStorage(
86 temp_dir_.path(), base::MessageLoopProxy::current().get())); 115 temp_dir_.path(), base::MessageLoopProxy::current().get()));
(...skipping 27 matching lines...) Expand all
114 false, // shared_with_me 143 false, // shared_with_me
115 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); 144 google_apis::test_util::CreateCopyResultCallback(&error, &entry));
116 base::RunLoop().RunUntilIdle(); 145 base::RunLoop().RunUntilIdle();
117 EXPECT_EQ(google_apis::HTTP_CREATED, error); 146 EXPECT_EQ(google_apis::HTTP_CREATED, error);
118 return entry.Pass(); 147 return entry.Pass();
119 } 148 }
120 149
121 content::TestBrowserThreadBundle thread_bundle_; 150 content::TestBrowserThreadBundle thread_bundle_;
122 base::ScopedTempDir temp_dir_; 151 base::ScopedTempDir temp_dir_;
123 scoped_ptr<TestingPrefServiceSimple> pref_service_; 152 scoped_ptr<TestingPrefServiceSimple> pref_service_;
124 scoped_ptr<FakeDriveService> drive_service_; 153 scoped_ptr<TestDriveService> drive_service_;
125 scoped_ptr<JobScheduler> scheduler_; 154 scoped_ptr<JobScheduler> scheduler_;
126 scoped_ptr<ResourceMetadataStorage, 155 scoped_ptr<ResourceMetadataStorage,
127 test_util::DestroyHelperForTests> metadata_storage_; 156 test_util::DestroyHelperForTests> metadata_storage_;
128 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; 157 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_;
129 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; 158 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_;
130 scoped_ptr<ChangeListLoader> change_list_loader_; 159 scoped_ptr<ChangeListLoader> change_list_loader_;
131 }; 160 };
132 161
133 TEST_F(ChangeListLoaderTest, LoadIfNeeded) { 162 TEST_F(ChangeListLoaderTest, LoadIfNeeded) {
134 EXPECT_FALSE(change_list_loader_->IsRefreshing()); 163 EXPECT_FALSE(change_list_loader_->IsRefreshing());
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 EXPECT_EQ(1U, observer.changed_directories().count( 246 EXPECT_EQ(1U, observer.changed_directories().count(
218 util::GetDriveMyDriveRootPath())); 247 util::GetDriveMyDriveRootPath()));
219 248
220 base::FilePath file_path = 249 base::FilePath file_path =
221 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); 250 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title());
222 ResourceEntry entry; 251 ResourceEntry entry;
223 EXPECT_EQ(FILE_ERROR_OK, 252 EXPECT_EQ(FILE_ERROR_OK,
224 metadata_->GetResourceEntryByPath(file_path, &entry)); 253 metadata_->GetResourceEntryByPath(file_path, &entry));
225 } 254 }
226 255
256 TEST_F(ChangeListLoaderTest, LoadIfNeeded_MyDrive) {
257 // Emulate the slowness of GetAllResourceList().
258 drive_service_->set_never_return_all_resource_list(true);
259
260 // Load grand root.
261 FileError error = FILE_ERROR_FAILED;
262 change_list_loader_->LoadIfNeeded(
263 DirectoryFetchInfo(util::kDriveGrandRootSpecialResourceId, 0),
264 google_apis::test_util::CreateCopyResultCallback(&error));
265 base::RunLoop().RunUntilIdle();
266 EXPECT_EQ(FILE_ERROR_OK, error);
267
268 // GetAllResourceList() was called.
269 EXPECT_EQ(1, drive_service_->blocked_call_count());
270
271 // My Drive is present in the local metadata, but its child is not.
272 ResourceEntry entry;
273 EXPECT_EQ(FILE_ERROR_OK,
274 metadata_->GetResourceEntryByPath(util::GetDriveMyDriveRootPath(),
275 &entry));
276 const int64 mydrive_changestamp =
277 entry.directory_specific_info().changestamp();
278
279 base::FilePath file_path =
280 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
281 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
282 metadata_->GetResourceEntryByPath(file_path, &entry));
283
284 // Load My Drive.
285 change_list_loader_->LoadIfNeeded(
286 DirectoryFetchInfo(drive_service_->GetRootResourceId(),
287 mydrive_changestamp),
288 google_apis::test_util::CreateCopyResultCallback(&error));
289 base::RunLoop().RunUntilIdle();
290 EXPECT_EQ(FILE_ERROR_OK, error);
291
292 // Now the file is present.
293 EXPECT_EQ(FILE_ERROR_OK,
294 metadata_->GetResourceEntryByPath(file_path, &entry));
295 }
296
297 TEST_F(ChangeListLoaderTest, LoadIfNeeded_NewDirectories) {
298 // Make local metadata up to date.
299 FileError error = FILE_ERROR_FAILED;
300 change_list_loader_->LoadIfNeeded(
301 DirectoryFetchInfo(),
302 google_apis::test_util::CreateCopyResultCallback(&error));
303 base::RunLoop().RunUntilIdle();
304 EXPECT_EQ(FILE_ERROR_OK, error);
305
306 // Add a new file.
307 scoped_ptr<google_apis::ResourceEntry> file = AddNewFile("New File");
308 ASSERT_TRUE(file);
309
310 // Emulate the slowness of GetAllResourceList().
311 drive_service_->set_never_return_all_resource_list(true);
312
313 // Enter refreshing state.
314 FileError check_for_updates_error = FILE_ERROR_FAILED;
315 change_list_loader_->CheckForUpdates(
316 google_apis::test_util::CreateCopyResultCallback(
317 &check_for_updates_error));
318 EXPECT_TRUE(change_list_loader_->IsRefreshing());
319
320 // Load My Drive.
321 change_list_loader_->LoadIfNeeded(
322 DirectoryFetchInfo(drive_service_->GetRootResourceId(),
323 metadata_->GetLargestChangestamp()),
324 google_apis::test_util::CreateCopyResultCallback(&error));
325 base::RunLoop().RunUntilIdle();
326 EXPECT_EQ(FILE_ERROR_OK, error);
327
328 // The new file is present in the local metadata.
329 base::FilePath file_path =
330 util::GetDriveMyDriveRootPath().AppendASCII(file->title());
331 ResourceEntry entry;
332 EXPECT_EQ(FILE_ERROR_OK,
333 metadata_->GetResourceEntryByPath(file_path, &entry));
334 }
335
227 TEST_F(ChangeListLoaderTest, CheckForUpdates) { 336 TEST_F(ChangeListLoaderTest, CheckForUpdates) {
228 // CheckForUpdates() results in no-op before load. 337 // CheckForUpdates() results in no-op before load.
229 FileError check_for_updates_error = FILE_ERROR_FAILED; 338 FileError check_for_updates_error = FILE_ERROR_FAILED;
230 change_list_loader_->CheckForUpdates( 339 change_list_loader_->CheckForUpdates(
231 google_apis::test_util::CreateCopyResultCallback( 340 google_apis::test_util::CreateCopyResultCallback(
232 &check_for_updates_error)); 341 &check_for_updates_error));
233 EXPECT_FALSE(change_list_loader_->IsRefreshing()); 342 EXPECT_FALSE(change_list_loader_->IsRefreshing());
234 base::RunLoop().RunUntilIdle(); 343 base::RunLoop().RunUntilIdle();
235 EXPECT_EQ(FILE_ERROR_FAILED, 344 EXPECT_EQ(FILE_ERROR_FAILED,
236 check_for_updates_error); // Callback was not run. 345 check_for_updates_error); // Callback was not run.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // The new file is found in the local metadata. 395 // The new file is found in the local metadata.
287 base::FilePath new_file_path = 396 base::FilePath new_file_path =
288 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); 397 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title());
289 ResourceEntry entry; 398 ResourceEntry entry;
290 EXPECT_EQ(FILE_ERROR_OK, 399 EXPECT_EQ(FILE_ERROR_OK,
291 metadata_->GetResourceEntryByPath(new_file_path, &entry)); 400 metadata_->GetResourceEntryByPath(new_file_path, &entry));
292 } 401 }
293 402
294 } // namespace internal 403 } // namespace internal
295 } // namespace drive 404 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698