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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 153 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
154 | 154 |
155 FileError error = FILE_ERROR_FAILED; | 155 FileError error = FILE_ERROR_FAILED; |
156 change_list_loader_->LoadIfNeeded( | 156 change_list_loader_->LoadIfNeeded( |
157 google_apis::test_util::CreateCopyResultCallback(&error)); | 157 google_apis::test_util::CreateCopyResultCallback(&error)); |
158 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 158 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
159 base::RunLoop().RunUntilIdle(); | 159 base::RunLoop().RunUntilIdle(); |
160 EXPECT_EQ(FILE_ERROR_OK, error); | 160 EXPECT_EQ(FILE_ERROR_OK, error); |
161 | 161 |
162 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 162 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
163 EXPECT_LT(0, metadata_->GetLargestChangestamp()); | 163 int64 changestamp = 0; |
| 164 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 165 EXPECT_LT(0, changestamp); |
164 EXPECT_EQ(1, drive_service_->resource_list_load_count()); | 166 EXPECT_EQ(1, drive_service_->resource_list_load_count()); |
165 EXPECT_EQ(1, drive_service_->about_resource_load_count()); | 167 EXPECT_EQ(1, drive_service_->about_resource_load_count()); |
166 EXPECT_EQ(1, observer.initial_load_complete_count()); | 168 EXPECT_EQ(1, observer.initial_load_complete_count()); |
167 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 169 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
168 EXPECT_TRUE(observer.changed_directories().empty()); | 170 EXPECT_TRUE(observer.changed_directories().empty()); |
169 | 171 |
170 base::FilePath file_path = | 172 base::FilePath file_path = |
171 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 173 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
172 ResourceEntry entry; | 174 ResourceEntry entry; |
173 EXPECT_EQ(FILE_ERROR_OK, | 175 EXPECT_EQ(FILE_ERROR_OK, |
(...skipping 30 matching lines...) Expand all Loading... |
204 change_list_loader_->LoadIfNeeded( | 206 change_list_loader_->LoadIfNeeded( |
205 google_apis::test_util::CreateCopyResultCallback(&error)); | 207 google_apis::test_util::CreateCopyResultCallback(&error)); |
206 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 208 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
207 base::RunLoop().RunUntilIdle(); | 209 base::RunLoop().RunUntilIdle(); |
208 EXPECT_EQ(FILE_ERROR_OK, error); | 210 EXPECT_EQ(FILE_ERROR_OK, error); |
209 EXPECT_EQ(previous_resource_list_load_count, | 211 EXPECT_EQ(previous_resource_list_load_count, |
210 drive_service_->resource_list_load_count()); | 212 drive_service_->resource_list_load_count()); |
211 EXPECT_EQ(1, observer.initial_load_complete_count()); | 213 EXPECT_EQ(1, observer.initial_load_complete_count()); |
212 | 214 |
213 // Update should be checked by Load(). | 215 // Update should be checked by Load(). |
214 EXPECT_EQ(drive_service_->about_resource().largest_change_id(), | 216 int64 changestamp = 0; |
215 metadata_->GetLargestChangestamp()); | 217 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 218 EXPECT_EQ(drive_service_->about_resource().largest_change_id(), changestamp); |
216 EXPECT_EQ(1, drive_service_->change_list_load_count()); | 219 EXPECT_EQ(1, drive_service_->change_list_load_count()); |
217 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 220 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
218 EXPECT_EQ(1U, observer.changed_directories().count( | 221 EXPECT_EQ(1U, observer.changed_directories().count( |
219 util::GetDriveMyDriveRootPath())); | 222 util::GetDriveMyDriveRootPath())); |
220 | 223 |
221 base::FilePath file_path = | 224 base::FilePath file_path = |
222 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 225 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
223 ResourceEntry entry; | 226 ResourceEntry entry; |
224 EXPECT_EQ(FILE_ERROR_OK, | 227 EXPECT_EQ(FILE_ERROR_OK, |
225 metadata_->GetResourceEntryByPath(file_path, &entry)); | 228 metadata_->GetResourceEntryByPath(file_path, &entry)); |
226 } | 229 } |
227 | 230 |
228 TEST_F(ChangeListLoaderTest, CheckForUpdates) { | 231 TEST_F(ChangeListLoaderTest, CheckForUpdates) { |
229 // CheckForUpdates() results in no-op before load. | 232 // CheckForUpdates() results in no-op before load. |
230 FileError check_for_updates_error = FILE_ERROR_FAILED; | 233 FileError check_for_updates_error = FILE_ERROR_FAILED; |
231 change_list_loader_->CheckForUpdates( | 234 change_list_loader_->CheckForUpdates( |
232 google_apis::test_util::CreateCopyResultCallback( | 235 google_apis::test_util::CreateCopyResultCallback( |
233 &check_for_updates_error)); | 236 &check_for_updates_error)); |
234 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 237 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
235 base::RunLoop().RunUntilIdle(); | 238 base::RunLoop().RunUntilIdle(); |
236 EXPECT_EQ(FILE_ERROR_FAILED, | 239 EXPECT_EQ(FILE_ERROR_FAILED, |
237 check_for_updates_error); // Callback was not run. | 240 check_for_updates_error); // Callback was not run. |
238 EXPECT_EQ(0, metadata_->GetLargestChangestamp()); | 241 int64 changestamp = 0; |
| 242 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 243 EXPECT_EQ(0, changestamp); |
239 EXPECT_EQ(0, drive_service_->resource_list_load_count()); | 244 EXPECT_EQ(0, drive_service_->resource_list_load_count()); |
240 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 245 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
241 | 246 |
242 // Start initial load. | 247 // Start initial load. |
243 FileError load_error = FILE_ERROR_FAILED; | 248 FileError load_error = FILE_ERROR_FAILED; |
244 change_list_loader_->LoadIfNeeded( | 249 change_list_loader_->LoadIfNeeded( |
245 google_apis::test_util::CreateCopyResultCallback(&load_error)); | 250 google_apis::test_util::CreateCopyResultCallback(&load_error)); |
246 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 251 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
247 | 252 |
248 // CheckForUpdates() while loading. | 253 // CheckForUpdates() while loading. |
249 change_list_loader_->CheckForUpdates( | 254 change_list_loader_->CheckForUpdates( |
250 google_apis::test_util::CreateCopyResultCallback( | 255 google_apis::test_util::CreateCopyResultCallback( |
251 &check_for_updates_error)); | 256 &check_for_updates_error)); |
252 | 257 |
253 base::RunLoop().RunUntilIdle(); | 258 base::RunLoop().RunUntilIdle(); |
254 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 259 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
255 EXPECT_EQ(FILE_ERROR_OK, load_error); | 260 EXPECT_EQ(FILE_ERROR_OK, load_error); |
256 EXPECT_EQ(FILE_ERROR_OK, check_for_updates_error); | 261 EXPECT_EQ(FILE_ERROR_OK, check_for_updates_error); |
257 EXPECT_LT(0, metadata_->GetLargestChangestamp()); | 262 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 263 EXPECT_LT(0, changestamp); |
258 EXPECT_EQ(1, drive_service_->resource_list_load_count()); | 264 EXPECT_EQ(1, drive_service_->resource_list_load_count()); |
259 | 265 |
260 int64 previous_changestamp = metadata_->GetLargestChangestamp(); | 266 int64 previous_changestamp = 0; |
| 267 EXPECT_EQ(FILE_ERROR_OK, |
| 268 metadata_->GetLargestChangestamp(&previous_changestamp)); |
261 // CheckForUpdates() results in no update. | 269 // CheckForUpdates() results in no update. |
262 change_list_loader_->CheckForUpdates( | 270 change_list_loader_->CheckForUpdates( |
263 google_apis::test_util::CreateCopyResultCallback( | 271 google_apis::test_util::CreateCopyResultCallback( |
264 &check_for_updates_error)); | 272 &check_for_updates_error)); |
265 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 273 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
266 base::RunLoop().RunUntilIdle(); | 274 base::RunLoop().RunUntilIdle(); |
267 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 275 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
268 EXPECT_EQ(previous_changestamp, metadata_->GetLargestChangestamp()); | 276 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 277 EXPECT_EQ(previous_changestamp, changestamp); |
269 | 278 |
270 // Add a file to the service. | 279 // Add a file to the service. |
271 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); | 280 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); |
272 ASSERT_TRUE(gdata_entry); | 281 ASSERT_TRUE(gdata_entry); |
273 | 282 |
274 // CheckForUpdates() results in update. | 283 // CheckForUpdates() results in update. |
275 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 284 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
276 change_list_loader_->CheckForUpdates( | 285 change_list_loader_->CheckForUpdates( |
277 google_apis::test_util::CreateCopyResultCallback( | 286 google_apis::test_util::CreateCopyResultCallback( |
278 &check_for_updates_error)); | 287 &check_for_updates_error)); |
279 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 288 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
280 base::RunLoop().RunUntilIdle(); | 289 base::RunLoop().RunUntilIdle(); |
281 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 290 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
282 EXPECT_LT(previous_changestamp, metadata_->GetLargestChangestamp()); | 291 EXPECT_EQ(FILE_ERROR_OK, metadata_->GetLargestChangestamp(&changestamp)); |
| 292 EXPECT_LT(previous_changestamp, changestamp); |
283 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 293 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
284 EXPECT_EQ(1U, observer.changed_directories().count( | 294 EXPECT_EQ(1U, observer.changed_directories().count( |
285 util::GetDriveMyDriveRootPath())); | 295 util::GetDriveMyDriveRootPath())); |
286 | 296 |
287 // The new file is found in the local metadata. | 297 // The new file is found in the local metadata. |
288 base::FilePath new_file_path = | 298 base::FilePath new_file_path = |
289 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 299 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
290 ResourceEntry entry; | 300 ResourceEntry entry; |
291 EXPECT_EQ(FILE_ERROR_OK, | 301 EXPECT_EQ(FILE_ERROR_OK, |
292 metadata_->GetResourceEntryByPath(new_file_path, &entry)); | 302 metadata_->GetResourceEntryByPath(new_file_path, &entry)); |
(...skipping 26 matching lines...) Expand all Loading... |
319 | 329 |
320 // Unlock the loader, this should resume the pending udpate. | 330 // Unlock the loader, this should resume the pending udpate. |
321 lock.reset(); | 331 lock.reset(); |
322 base::RunLoop().RunUntilIdle(); | 332 base::RunLoop().RunUntilIdle(); |
323 EXPECT_EQ(1U, observer.changed_directories().count( | 333 EXPECT_EQ(1U, observer.changed_directories().count( |
324 util::GetDriveMyDriveRootPath())); | 334 util::GetDriveMyDriveRootPath())); |
325 } | 335 } |
326 | 336 |
327 } // namespace internal | 337 } // namespace internal |
328 } // namespace drive | 338 } // namespace drive |
OLD | NEW |