OLD | NEW |
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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 change_list_loader_->LoadIfNeeded( | 157 change_list_loader_->LoadIfNeeded( |
158 google_apis::test_util::CreateCopyResultCallback(&error)); | 158 google_apis::test_util::CreateCopyResultCallback(&error)); |
159 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 159 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
160 base::RunLoop().RunUntilIdle(); | 160 base::RunLoop().RunUntilIdle(); |
161 EXPECT_EQ(FILE_ERROR_OK, error); | 161 EXPECT_EQ(FILE_ERROR_OK, error); |
162 | 162 |
163 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 163 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
164 int64 changestamp = 0; | 164 int64 changestamp = 0; |
165 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 165 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
166 EXPECT_LT(0, changestamp); | 166 EXPECT_LT(0, changestamp); |
167 EXPECT_EQ(1, drive_service_->resource_list_load_count()); | 167 EXPECT_EQ(1, drive_service_->file_list_load_count()); |
168 EXPECT_EQ(1, drive_service_->about_resource_load_count()); | 168 EXPECT_EQ(1, drive_service_->about_resource_load_count()); |
169 EXPECT_EQ(1, observer.initial_load_complete_count()); | 169 EXPECT_EQ(1, observer.initial_load_complete_count()); |
170 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 170 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
171 EXPECT_TRUE(observer.changed_directories().empty()); | 171 EXPECT_TRUE(observer.changed_directories().empty()); |
172 | 172 |
173 base::FilePath file_path = | 173 base::FilePath file_path = |
174 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 174 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
175 ResourceEntry entry; | 175 ResourceEntry entry; |
176 EXPECT_EQ(FILE_ERROR_OK, | 176 EXPECT_EQ(FILE_ERROR_OK, |
177 metadata_->GetResourceEntryByPath(file_path, &entry)); | 177 metadata_->GetResourceEntryByPath(file_path, &entry)); |
(...skipping 15 matching lines...) Expand all Loading... |
193 scheduler_.get(), | 193 scheduler_.get(), |
194 about_resource_loader_.get(), | 194 about_resource_loader_.get(), |
195 loader_controller_.get())); | 195 loader_controller_.get())); |
196 | 196 |
197 // Add a file to the service. | 197 // Add a file to the service. |
198 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); | 198 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); |
199 ASSERT_TRUE(gdata_entry); | 199 ASSERT_TRUE(gdata_entry); |
200 | 200 |
201 // Start loading. Because local metadata is available, the load results in | 201 // Start loading. Because local metadata is available, the load results in |
202 // returning FILE_ERROR_OK without fetching full list of resources. | 202 // returning FILE_ERROR_OK without fetching full list of resources. |
203 const int previous_resource_list_load_count = | 203 const int previous_file_list_load_count = |
204 drive_service_->resource_list_load_count(); | 204 drive_service_->file_list_load_count(); |
205 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 205 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
206 | 206 |
207 change_list_loader_->LoadIfNeeded( | 207 change_list_loader_->LoadIfNeeded( |
208 google_apis::test_util::CreateCopyResultCallback(&error)); | 208 google_apis::test_util::CreateCopyResultCallback(&error)); |
209 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 209 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
210 base::RunLoop().RunUntilIdle(); | 210 base::RunLoop().RunUntilIdle(); |
211 EXPECT_EQ(FILE_ERROR_OK, error); | 211 EXPECT_EQ(FILE_ERROR_OK, error); |
212 EXPECT_EQ(previous_resource_list_load_count, | 212 EXPECT_EQ(previous_file_list_load_count, |
213 drive_service_->resource_list_load_count()); | 213 drive_service_->file_list_load_count()); |
214 EXPECT_EQ(1, observer.initial_load_complete_count()); | 214 EXPECT_EQ(1, observer.initial_load_complete_count()); |
215 | 215 |
216 // Update should be checked by Load(). | 216 // Update should be checked by Load(). |
217 int64 changestamp = 0; | 217 int64 changestamp = 0; |
218 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 218 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
219 EXPECT_EQ(drive_service_->about_resource().largest_change_id(), changestamp); | 219 EXPECT_EQ(drive_service_->about_resource().largest_change_id(), changestamp); |
220 EXPECT_EQ(1, drive_service_->change_list_load_count()); | 220 EXPECT_EQ(1, drive_service_->change_list_load_count()); |
221 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 221 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
222 EXPECT_EQ(1U, observer.changed_directories().count( | 222 EXPECT_EQ(1U, observer.changed_directories().count( |
223 util::GetDriveMyDriveRootPath())); | 223 util::GetDriveMyDriveRootPath())); |
(...skipping 11 matching lines...) Expand all Loading... |
235 change_list_loader_->CheckForUpdates( | 235 change_list_loader_->CheckForUpdates( |
236 google_apis::test_util::CreateCopyResultCallback( | 236 google_apis::test_util::CreateCopyResultCallback( |
237 &check_for_updates_error)); | 237 &check_for_updates_error)); |
238 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 238 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
239 base::RunLoop().RunUntilIdle(); | 239 base::RunLoop().RunUntilIdle(); |
240 EXPECT_EQ(FILE_ERROR_FAILED, | 240 EXPECT_EQ(FILE_ERROR_FAILED, |
241 check_for_updates_error); // Callback was not run. | 241 check_for_updates_error); // Callback was not run. |
242 int64 changestamp = 0; | 242 int64 changestamp = 0; |
243 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 243 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
244 EXPECT_EQ(0, changestamp); | 244 EXPECT_EQ(0, changestamp); |
245 EXPECT_EQ(0, drive_service_->resource_list_load_count()); | 245 EXPECT_EQ(0, drive_service_->file_list_load_count()); |
246 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 246 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
247 | 247 |
248 // Start initial load. | 248 // Start initial load. |
249 FileError load_error = FILE_ERROR_FAILED; | 249 FileError load_error = FILE_ERROR_FAILED; |
250 change_list_loader_->LoadIfNeeded( | 250 change_list_loader_->LoadIfNeeded( |
251 google_apis::test_util::CreateCopyResultCallback(&load_error)); | 251 google_apis::test_util::CreateCopyResultCallback(&load_error)); |
252 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 252 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
253 | 253 |
254 // CheckForUpdates() while loading. | 254 // CheckForUpdates() while loading. |
255 change_list_loader_->CheckForUpdates( | 255 change_list_loader_->CheckForUpdates( |
256 google_apis::test_util::CreateCopyResultCallback( | 256 google_apis::test_util::CreateCopyResultCallback( |
257 &check_for_updates_error)); | 257 &check_for_updates_error)); |
258 | 258 |
259 base::RunLoop().RunUntilIdle(); | 259 base::RunLoop().RunUntilIdle(); |
260 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 260 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
261 EXPECT_EQ(FILE_ERROR_OK, load_error); | 261 EXPECT_EQ(FILE_ERROR_OK, load_error); |
262 EXPECT_EQ(FILE_ERROR_OK, check_for_updates_error); | 262 EXPECT_EQ(FILE_ERROR_OK, check_for_updates_error); |
263 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); | 263 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
264 EXPECT_LT(0, changestamp); | 264 EXPECT_LT(0, changestamp); |
265 EXPECT_EQ(1, drive_service_->resource_list_load_count()); | 265 EXPECT_EQ(1, drive_service_->file_list_load_count()); |
266 | 266 |
267 int64 previous_changestamp = 0; | 267 int64 previous_changestamp = 0; |
268 EXPECT_EQ(FILE_ERROR_OK, | 268 EXPECT_EQ(FILE_ERROR_OK, |
269 metadata_->GetLargestChangestamp(&previous_changestamp)); | 269 metadata_->GetLargestChangestamp(&previous_changestamp)); |
270 // CheckForUpdates() results in no update. | 270 // CheckForUpdates() results in no update. |
271 change_list_loader_->CheckForUpdates( | 271 change_list_loader_->CheckForUpdates( |
272 google_apis::test_util::CreateCopyResultCallback( | 272 google_apis::test_util::CreateCopyResultCallback( |
273 &check_for_updates_error)); | 273 &check_for_updates_error)); |
274 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 274 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
275 base::RunLoop().RunUntilIdle(); | 275 base::RunLoop().RunUntilIdle(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 // Unlock the loader, this should resume the pending udpate. | 331 // Unlock the loader, this should resume the pending udpate. |
332 lock.reset(); | 332 lock.reset(); |
333 base::RunLoop().RunUntilIdle(); | 333 base::RunLoop().RunUntilIdle(); |
334 EXPECT_EQ(1U, observer.changed_directories().count( | 334 EXPECT_EQ(1U, observer.changed_directories().count( |
335 util::GetDriveMyDriveRootPath())); | 335 util::GetDriveMyDriveRootPath())); |
336 } | 336 } |
337 | 337 |
338 } // namespace internal | 338 } // namespace internal |
339 } // namespace drive | 339 } // namespace drive |
OLD | NEW |