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/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" |
11 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" | 11 #include "chrome/browser/chromeos/drive/change_list_loader_observer.h" |
12 #include "chrome/browser/chromeos/drive/change_list_processor.h" | |
13 #include "chrome/browser/chromeos/drive/file_cache.h" | 12 #include "chrome/browser/chromeos/drive/file_cache.h" |
14 #include "chrome/browser/chromeos/drive/file_system_util.h" | 13 #include "chrome/browser/chromeos/drive/file_system_util.h" |
15 #include "chrome/browser/chromeos/drive/job_scheduler.h" | 14 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
16 #include "chrome/browser/chromeos/drive/resource_metadata.h" | 15 #include "chrome/browser/chromeos/drive/resource_metadata.h" |
17 #include "chrome/browser/chromeos/drive/test_util.h" | 16 #include "chrome/browser/chromeos/drive/test_util.h" |
18 #include "chrome/browser/drive/fake_drive_service.h" | 17 #include "chrome/browser/drive/fake_drive_service.h" |
19 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
20 #include "google_apis/drive/test_util.h" | 19 #include "google_apis/drive/test_util.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
22 | 21 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 scoped_ptr<TestingPrefServiceSimple> pref_service_; | 126 scoped_ptr<TestingPrefServiceSimple> pref_service_; |
128 scoped_ptr<FakeDriveService> drive_service_; | 127 scoped_ptr<FakeDriveService> drive_service_; |
129 scoped_ptr<JobScheduler> scheduler_; | 128 scoped_ptr<JobScheduler> scheduler_; |
130 scoped_ptr<ResourceMetadataStorage, | 129 scoped_ptr<ResourceMetadataStorage, |
131 test_util::DestroyHelperForTests> metadata_storage_; | 130 test_util::DestroyHelperForTests> metadata_storage_; |
132 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; | 131 scoped_ptr<ResourceMetadata, test_util::DestroyHelperForTests> metadata_; |
133 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; | 132 scoped_ptr<FileCache, test_util::DestroyHelperForTests> cache_; |
134 scoped_ptr<ChangeListLoader> change_list_loader_; | 133 scoped_ptr<ChangeListLoader> change_list_loader_; |
135 }; | 134 }; |
136 | 135 |
137 TEST_F(ChangeListLoaderTest, LoadIfNeeded) { | 136 TEST_F(ChangeListLoaderTest, Load) { |
138 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 137 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
139 | 138 |
140 // Start initial load. | 139 // Start initial load. |
141 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 140 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
142 | 141 |
143 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 142 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
144 | 143 |
145 FileError error = FILE_ERROR_FAILED; | 144 FileError error = FILE_ERROR_FAILED; |
146 change_list_loader_->LoadIfNeeded( | 145 change_list_loader_->LoadForTesting( |
147 DirectoryFetchInfo(), | |
148 google_apis::test_util::CreateCopyResultCallback(&error)); | 146 google_apis::test_util::CreateCopyResultCallback(&error)); |
149 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 147 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
150 base::RunLoop().RunUntilIdle(); | 148 base::RunLoop().RunUntilIdle(); |
151 EXPECT_EQ(FILE_ERROR_OK, error); | 149 EXPECT_EQ(FILE_ERROR_OK, error); |
152 | 150 |
153 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 151 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
154 EXPECT_LT(0, metadata_->GetLargestChangestamp()); | 152 EXPECT_LT(0, metadata_->GetLargestChangestamp()); |
155 EXPECT_EQ(1, drive_service_->resource_list_load_count()); | 153 EXPECT_EQ(1, drive_service_->resource_list_load_count()); |
156 EXPECT_EQ(1, drive_service_->about_resource_load_count()); | 154 EXPECT_EQ(1, drive_service_->about_resource_load_count()); |
157 EXPECT_EQ(1, observer.initial_load_complete_count()); | 155 EXPECT_EQ(1, observer.initial_load_complete_count()); |
158 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 156 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
159 EXPECT_TRUE(observer.changed_directories().empty()); | 157 EXPECT_TRUE(observer.changed_directories().empty()); |
160 | 158 |
161 base::FilePath file_path = | 159 base::FilePath file_path = |
162 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 160 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
163 ResourceEntry entry; | 161 ResourceEntry entry; |
164 EXPECT_EQ(FILE_ERROR_OK, | 162 EXPECT_EQ(FILE_ERROR_OK, |
165 metadata_->GetResourceEntryByPath(file_path, &entry)); | 163 metadata_->GetResourceEntryByPath(file_path, &entry)); |
166 | 164 |
167 // Reload. This should result in no-op. | 165 // Reload. This should result in no-op. |
168 int64 previous_changestamp = metadata_->GetLargestChangestamp(); | 166 int64 previous_changestamp = metadata_->GetLargestChangestamp(); |
169 int previous_resource_list_load_count = | 167 int previous_resource_list_load_count = |
170 drive_service_->resource_list_load_count(); | 168 drive_service_->resource_list_load_count(); |
171 change_list_loader_->LoadIfNeeded( | 169 change_list_loader_->LoadForTesting( |
172 DirectoryFetchInfo(), | |
173 google_apis::test_util::CreateCopyResultCallback(&error)); | 170 google_apis::test_util::CreateCopyResultCallback(&error)); |
174 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | |
175 base::RunLoop().RunUntilIdle(); | 171 base::RunLoop().RunUntilIdle(); |
176 EXPECT_EQ(FILE_ERROR_OK, error); | 172 EXPECT_EQ(FILE_ERROR_OK, error); |
177 | 173 |
178 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 174 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
179 // Cached value is used. | 175 // Cached value is used. |
180 EXPECT_EQ(1, drive_service_->about_resource_load_count()); | |
181 EXPECT_EQ(previous_changestamp, metadata_->GetLargestChangestamp()); | 176 EXPECT_EQ(previous_changestamp, metadata_->GetLargestChangestamp()); |
182 EXPECT_EQ(previous_resource_list_load_count, | 177 EXPECT_EQ(previous_resource_list_load_count, |
183 drive_service_->resource_list_load_count()); | 178 drive_service_->resource_list_load_count()); |
184 } | 179 } |
185 | 180 |
186 TEST_F(ChangeListLoaderTest, LoadIfNeeded_LocalMetadataAvailable) { | 181 TEST_F(ChangeListLoaderTest, Load_LocalMetadataAvailable) { |
187 // Prepare metadata. | 182 // Prepare metadata. |
188 FileError error = FILE_ERROR_FAILED; | 183 FileError error = FILE_ERROR_FAILED; |
189 change_list_loader_->LoadIfNeeded( | 184 change_list_loader_->LoadForTesting( |
190 DirectoryFetchInfo(), | |
191 google_apis::test_util::CreateCopyResultCallback(&error)); | 185 google_apis::test_util::CreateCopyResultCallback(&error)); |
192 base::RunLoop().RunUntilIdle(); | 186 base::RunLoop().RunUntilIdle(); |
193 EXPECT_EQ(FILE_ERROR_OK, error); | 187 EXPECT_EQ(FILE_ERROR_OK, error); |
194 | 188 |
195 // Reset loader. | 189 // Reset loader. |
196 change_list_loader_.reset( | 190 change_list_loader_.reset( |
197 new ChangeListLoader(base::MessageLoopProxy::current().get(), | 191 new ChangeListLoader(base::MessageLoopProxy::current().get(), |
198 metadata_.get(), | 192 metadata_.get(), |
199 scheduler_.get(), | 193 scheduler_.get(), |
200 drive_service_.get())); | 194 drive_service_.get())); |
201 | 195 |
202 // Add a file to the service. | 196 // Add a file to the service. |
203 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); | 197 scoped_ptr<google_apis::ResourceEntry> gdata_entry = AddNewFile("New File"); |
204 ASSERT_TRUE(gdata_entry); | 198 ASSERT_TRUE(gdata_entry); |
205 | 199 |
206 // Start loading. Because local metadata is available, the load results in | 200 // Start loading. Because local metadata is available, the load results in |
207 // returning FILE_ERROR_OK without fetching full list of resources. | 201 // returning FILE_ERROR_OK without fetching full list of resources. |
208 const int previous_resource_list_load_count = | 202 const int previous_resource_list_load_count = |
209 drive_service_->resource_list_load_count(); | 203 drive_service_->resource_list_load_count(); |
210 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 204 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
211 | 205 |
212 change_list_loader_->LoadIfNeeded( | 206 change_list_loader_->LoadForTesting( |
213 DirectoryFetchInfo(), | |
214 google_apis::test_util::CreateCopyResultCallback(&error)); | 207 google_apis::test_util::CreateCopyResultCallback(&error)); |
215 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 208 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
216 base::RunLoop().RunUntilIdle(); | 209 base::RunLoop().RunUntilIdle(); |
217 EXPECT_EQ(FILE_ERROR_OK, error); | 210 EXPECT_EQ(FILE_ERROR_OK, error); |
218 EXPECT_EQ(previous_resource_list_load_count, | 211 EXPECT_EQ(previous_resource_list_load_count, |
219 drive_service_->resource_list_load_count()); | 212 drive_service_->resource_list_load_count()); |
220 EXPECT_EQ(1, observer.initial_load_complete_count()); | 213 EXPECT_EQ(1, observer.initial_load_complete_count()); |
221 | 214 |
222 // Update should be checked by LoadIfNeeded(). | 215 // Update should be checked by Load(). |
223 EXPECT_EQ(drive_service_->largest_changestamp(), | 216 EXPECT_EQ(drive_service_->largest_changestamp(), |
224 metadata_->GetLargestChangestamp()); | 217 metadata_->GetLargestChangestamp()); |
225 EXPECT_EQ(1, drive_service_->change_list_load_count()); | 218 EXPECT_EQ(1, drive_service_->change_list_load_count()); |
226 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 219 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
227 EXPECT_EQ(1U, observer.changed_directories().count( | 220 EXPECT_EQ(1U, observer.changed_directories().count( |
228 util::GetDriveMyDriveRootPath())); | 221 util::GetDriveMyDriveRootPath())); |
229 | 222 |
230 base::FilePath file_path = | 223 base::FilePath file_path = |
231 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 224 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
232 ResourceEntry entry; | 225 ResourceEntry entry; |
233 EXPECT_EQ(FILE_ERROR_OK, | 226 EXPECT_EQ(FILE_ERROR_OK, |
234 metadata_->GetResourceEntryByPath(file_path, &entry)); | 227 metadata_->GetResourceEntryByPath(file_path, &entry)); |
235 } | 228 } |
236 | 229 |
237 TEST_F(ChangeListLoaderTest, LoadIfNeeded_MyDrive) { | 230 TEST_F(ChangeListLoaderTest, LoadDirectoryIfNeeded_MyDrive) { |
238 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 231 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
239 | 232 |
240 // Emulate the slowness of GetAllResourceList(). | 233 // Emulate the slowness of GetAllResourceList(). |
241 drive_service_->set_never_return_all_resource_list(true); | 234 drive_service_->set_never_return_all_resource_list(true); |
242 | 235 |
243 // Load grand root. | 236 // Load grand root. |
244 FileError error = FILE_ERROR_FAILED; | 237 FileError error = FILE_ERROR_FAILED; |
245 change_list_loader_->LoadIfNeeded( | 238 change_list_loader_->LoadDirectoryIfNeeded( |
246 DirectoryFetchInfo(util::kDriveGrandRootLocalId, 0), | 239 util::GetDriveGrandRootPath(), |
247 google_apis::test_util::CreateCopyResultCallback(&error)); | 240 google_apis::test_util::CreateCopyResultCallback(&error)); |
248 base::RunLoop().RunUntilIdle(); | 241 base::RunLoop().RunUntilIdle(); |
249 EXPECT_EQ(FILE_ERROR_OK, error); | 242 EXPECT_EQ(FILE_ERROR_OK, error); |
250 EXPECT_EQ(1U, observer.changed_directories().count( | 243 EXPECT_EQ(1U, observer.changed_directories().count( |
251 util::GetDriveGrandRootPath())); | 244 util::GetDriveGrandRootPath())); |
252 observer.clear_changed_directories(); | 245 observer.clear_changed_directories(); |
253 | 246 |
254 // GetAllResourceList() was called. | 247 // GetAllResourceList() was called. |
255 EXPECT_EQ(1, drive_service_->blocked_resource_list_load_count()); | 248 EXPECT_EQ(1, drive_service_->blocked_resource_list_load_count()); |
256 | 249 |
257 // My Drive is present in the local metadata, but its child is not. | 250 // My Drive is present in the local metadata, but its child is not. |
258 ResourceEntry entry; | 251 ResourceEntry entry; |
259 EXPECT_EQ(FILE_ERROR_OK, | 252 EXPECT_EQ(FILE_ERROR_OK, |
260 metadata_->GetResourceEntryByPath(util::GetDriveMyDriveRootPath(), | 253 metadata_->GetResourceEntryByPath(util::GetDriveMyDriveRootPath(), |
261 &entry)); | 254 &entry)); |
262 const int64 mydrive_changestamp = | |
263 entry.directory_specific_info().changestamp(); | |
264 | 255 |
265 base::FilePath file_path = | 256 base::FilePath file_path = |
266 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 257 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
267 EXPECT_EQ(FILE_ERROR_NOT_FOUND, | 258 EXPECT_EQ(FILE_ERROR_NOT_FOUND, |
268 metadata_->GetResourceEntryByPath(file_path, &entry)); | 259 metadata_->GetResourceEntryByPath(file_path, &entry)); |
269 | 260 |
270 // Load My Drive. | 261 // Load My Drive. |
271 change_list_loader_->LoadIfNeeded( | 262 change_list_loader_->LoadDirectoryIfNeeded( |
272 DirectoryFetchInfo(drive_service_->GetRootResourceId(), | 263 util::GetDriveMyDriveRootPath(), |
273 mydrive_changestamp), | |
274 google_apis::test_util::CreateCopyResultCallback(&error)); | 264 google_apis::test_util::CreateCopyResultCallback(&error)); |
275 base::RunLoop().RunUntilIdle(); | 265 base::RunLoop().RunUntilIdle(); |
276 EXPECT_EQ(FILE_ERROR_OK, error); | 266 EXPECT_EQ(FILE_ERROR_OK, error); |
277 EXPECT_EQ(1U, observer.changed_directories().count( | 267 EXPECT_EQ(1U, observer.changed_directories().count( |
278 util::GetDriveMyDriveRootPath())); | 268 util::GetDriveMyDriveRootPath())); |
279 | 269 |
280 // Now the file is present. | 270 // Now the file is present. |
281 EXPECT_EQ(FILE_ERROR_OK, | 271 EXPECT_EQ(FILE_ERROR_OK, |
282 metadata_->GetResourceEntryByPath(file_path, &entry)); | 272 metadata_->GetResourceEntryByPath(file_path, &entry)); |
283 } | 273 } |
284 | 274 |
285 TEST_F(ChangeListLoaderTest, LoadIfNeeded_NewDirectories) { | 275 TEST_F(ChangeListLoaderTest, LoadDirectoryIfNeeded_NewDirectories) { |
286 // Make local metadata up to date. | 276 // Make local metadata up to date. |
287 FileError error = FILE_ERROR_FAILED; | 277 FileError error = FILE_ERROR_FAILED; |
288 change_list_loader_->LoadIfNeeded( | 278 change_list_loader_->LoadForTesting( |
289 DirectoryFetchInfo(), | |
290 google_apis::test_util::CreateCopyResultCallback(&error)); | 279 google_apis::test_util::CreateCopyResultCallback(&error)); |
291 base::RunLoop().RunUntilIdle(); | 280 base::RunLoop().RunUntilIdle(); |
292 EXPECT_EQ(FILE_ERROR_OK, error); | 281 EXPECT_EQ(FILE_ERROR_OK, error); |
293 | 282 |
294 // Add a new file. | 283 // Add a new file. |
295 scoped_ptr<google_apis::ResourceEntry> file = AddNewFile("New File"); | 284 scoped_ptr<google_apis::ResourceEntry> file = AddNewFile("New File"); |
296 ASSERT_TRUE(file); | 285 ASSERT_TRUE(file); |
297 | 286 |
298 // Emulate the slowness of GetAllResourceList(). | 287 // Emulate the slowness of GetAllResourceList(). |
299 drive_service_->set_never_return_all_resource_list(true); | 288 drive_service_->set_never_return_all_resource_list(true); |
300 | 289 |
301 // Enter refreshing state. | 290 // Enter refreshing state. |
302 FileError check_for_updates_error = FILE_ERROR_FAILED; | 291 FileError check_for_updates_error = FILE_ERROR_FAILED; |
303 change_list_loader_->CheckForUpdates( | 292 change_list_loader_->CheckForUpdates( |
304 google_apis::test_util::CreateCopyResultCallback( | 293 google_apis::test_util::CreateCopyResultCallback( |
305 &check_for_updates_error)); | 294 &check_for_updates_error)); |
306 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 295 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
307 | 296 |
308 // Load My Drive. | 297 // Load My Drive. |
309 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 298 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
310 change_list_loader_->LoadIfNeeded( | 299 change_list_loader_->LoadDirectoryIfNeeded( |
311 DirectoryFetchInfo(drive_service_->GetRootResourceId(), | 300 util::GetDriveMyDriveRootPath(), |
312 metadata_->GetLargestChangestamp()), | |
313 google_apis::test_util::CreateCopyResultCallback(&error)); | 301 google_apis::test_util::CreateCopyResultCallback(&error)); |
314 base::RunLoop().RunUntilIdle(); | 302 base::RunLoop().RunUntilIdle(); |
315 EXPECT_EQ(FILE_ERROR_OK, error); | 303 EXPECT_EQ(FILE_ERROR_OK, error); |
316 EXPECT_EQ(1U, observer.changed_directories().count( | 304 EXPECT_EQ(1U, observer.changed_directories().count( |
317 util::GetDriveMyDriveRootPath())); | 305 util::GetDriveMyDriveRootPath())); |
318 | 306 |
319 // The new file is present in the local metadata. | 307 // The new file is present in the local metadata. |
320 base::FilePath file_path = | 308 base::FilePath file_path = |
321 util::GetDriveMyDriveRootPath().AppendASCII(file->title()); | 309 util::GetDriveMyDriveRootPath().AppendASCII(file->title()); |
322 ResourceEntry entry; | 310 ResourceEntry entry; |
323 EXPECT_EQ(FILE_ERROR_OK, | 311 EXPECT_EQ(FILE_ERROR_OK, |
324 metadata_->GetResourceEntryByPath(file_path, &entry)); | 312 metadata_->GetResourceEntryByPath(file_path, &entry)); |
325 } | 313 } |
326 | 314 |
327 TEST_F(ChangeListLoaderTest, LoadIfNeeded_MultipleCalls) { | 315 TEST_F(ChangeListLoaderTest, LoadDirectoryIfNeeded_MultipleCalls) { |
328 TestChangeListLoaderObserver observer(change_list_loader_.get()); | 316 TestChangeListLoaderObserver observer(change_list_loader_.get()); |
329 | 317 |
330 // Load grand root. | 318 // Load grand root. |
331 FileError error = FILE_ERROR_FAILED; | 319 FileError error = FILE_ERROR_FAILED; |
332 change_list_loader_->LoadIfNeeded( | 320 change_list_loader_->LoadDirectoryIfNeeded( |
333 DirectoryFetchInfo(util::kDriveGrandRootLocalId, 0), | 321 util::GetDriveGrandRootPath(), |
334 google_apis::test_util::CreateCopyResultCallback(&error)); | 322 google_apis::test_util::CreateCopyResultCallback(&error)); |
335 | 323 |
336 // Load grand root again without waiting for the result. | 324 // Load grand root again without waiting for the result. |
337 FileError error2 = FILE_ERROR_FAILED; | 325 FileError error2 = FILE_ERROR_FAILED; |
338 change_list_loader_->LoadIfNeeded( | 326 change_list_loader_->LoadDirectoryIfNeeded( |
339 DirectoryFetchInfo(util::kDriveGrandRootLocalId, 0), | 327 util::GetDriveGrandRootPath(), |
340 google_apis::test_util::CreateCopyResultCallback(&error2)); | 328 google_apis::test_util::CreateCopyResultCallback(&error2)); |
341 base::RunLoop().RunUntilIdle(); | 329 base::RunLoop().RunUntilIdle(); |
342 | 330 |
343 // Callback is called for each method call. | 331 // Callback is called for each method call. |
344 EXPECT_EQ(FILE_ERROR_OK, error); | 332 EXPECT_EQ(FILE_ERROR_OK, error); |
345 EXPECT_EQ(FILE_ERROR_OK, error2); | 333 EXPECT_EQ(FILE_ERROR_OK, error2); |
346 | 334 |
347 // No duplicated resource list load and observer events. | 335 // No duplicated resource list load and observer events. |
348 EXPECT_EQ(1, drive_service_->resource_list_load_count()); | 336 EXPECT_EQ(1, drive_service_->resource_list_load_count()); |
349 EXPECT_EQ(1, observer.initial_load_complete_count()); | 337 EXPECT_EQ(1, observer.initial_load_complete_count()); |
350 EXPECT_EQ(1, observer.load_from_server_complete_count()); | 338 EXPECT_EQ(1, observer.load_from_server_complete_count()); |
351 } | 339 } |
352 | 340 |
353 TEST_F(ChangeListLoaderTest, CheckForUpdates) { | 341 TEST_F(ChangeListLoaderTest, CheckForUpdates) { |
354 // CheckForUpdates() results in no-op before load. | 342 // CheckForUpdates() results in no-op before load. |
355 FileError check_for_updates_error = FILE_ERROR_FAILED; | 343 FileError check_for_updates_error = FILE_ERROR_FAILED; |
356 change_list_loader_->CheckForUpdates( | 344 change_list_loader_->CheckForUpdates( |
357 google_apis::test_util::CreateCopyResultCallback( | 345 google_apis::test_util::CreateCopyResultCallback( |
358 &check_for_updates_error)); | 346 &check_for_updates_error)); |
359 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 347 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
360 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
361 EXPECT_EQ(FILE_ERROR_FAILED, | 349 EXPECT_EQ(FILE_ERROR_FAILED, |
362 check_for_updates_error); // Callback was not run. | 350 check_for_updates_error); // Callback was not run. |
363 EXPECT_EQ(0, metadata_->GetLargestChangestamp()); | 351 EXPECT_EQ(0, metadata_->GetLargestChangestamp()); |
364 EXPECT_EQ(0, drive_service_->resource_list_load_count()); | 352 EXPECT_EQ(0, drive_service_->resource_list_load_count()); |
365 EXPECT_EQ(0, drive_service_->about_resource_load_count()); | 353 EXPECT_EQ(0, drive_service_->about_resource_load_count()); |
366 | 354 |
367 // Start initial load. | 355 // Start initial load. |
368 FileError load_error = FILE_ERROR_FAILED; | 356 FileError load_error = FILE_ERROR_FAILED; |
369 change_list_loader_->LoadIfNeeded( | 357 change_list_loader_->LoadForTesting( |
370 DirectoryFetchInfo(), | |
371 google_apis::test_util::CreateCopyResultCallback(&load_error)); | 358 google_apis::test_util::CreateCopyResultCallback(&load_error)); |
372 EXPECT_TRUE(change_list_loader_->IsRefreshing()); | 359 EXPECT_TRUE(change_list_loader_->IsRefreshing()); |
373 | 360 |
374 // CheckForUpdates() while loading. | 361 // CheckForUpdates() while loading. |
375 change_list_loader_->CheckForUpdates( | 362 change_list_loader_->CheckForUpdates( |
376 google_apis::test_util::CreateCopyResultCallback( | 363 google_apis::test_util::CreateCopyResultCallback( |
377 &check_for_updates_error)); | 364 &check_for_updates_error)); |
378 | 365 |
379 base::RunLoop().RunUntilIdle(); | 366 base::RunLoop().RunUntilIdle(); |
380 EXPECT_FALSE(change_list_loader_->IsRefreshing()); | 367 EXPECT_FALSE(change_list_loader_->IsRefreshing()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 // The new file is found in the local metadata. | 400 // The new file is found in the local metadata. |
414 base::FilePath new_file_path = | 401 base::FilePath new_file_path = |
415 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); | 402 util::GetDriveMyDriveRootPath().AppendASCII(gdata_entry->title()); |
416 ResourceEntry entry; | 403 ResourceEntry entry; |
417 EXPECT_EQ(FILE_ERROR_OK, | 404 EXPECT_EQ(FILE_ERROR_OK, |
418 metadata_->GetResourceEntryByPath(new_file_path, &entry)); | 405 metadata_->GetResourceEntryByPath(new_file_path, &entry)); |
419 } | 406 } |
420 | 407 |
421 } // namespace internal | 408 } // namespace internal |
422 } // namespace drive | 409 } // namespace drive |
OLD | NEW |