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

Side by Side Diff: chrome/browser/chromeos/drive/sync/entry_update_performer_unittest.cc

Issue 276313002: drive: Change FileCache::GetCacheEntry's return type to FileError (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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/sync/entry_update_performer.h" 5 #include "chrome/browser/chromeos/drive/sync/entry_update_performer.h"
6 6
7 #include "base/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/md5.h" 9 #include "base/md5.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 fake_service()->GetResourceEntry( 228 fake_service()->GetResourceEntry(
229 kResourceId, 229 kResourceId,
230 google_apis::test_util::CreateCopyResultCallback(&gdata_error, 230 google_apis::test_util::CreateCopyResultCallback(&gdata_error,
231 &server_entry)); 231 &server_entry));
232 test_util::RunBlockingPoolTask(); 232 test_util::RunBlockingPoolTask();
233 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error); 233 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
234 EXPECT_EQ(static_cast<int64>(kTestFileContent.size()), 234 EXPECT_EQ(static_cast<int64>(kTestFileContent.size()),
235 server_entry->file_size()); 235 server_entry->file_size());
236 236
237 // Make sure that the cache is no longer dirty. 237 // Make sure that the cache is no longer dirty.
238 bool success = false;
239 FileCacheEntry cache_entry; 238 FileCacheEntry cache_entry;
240 base::PostTaskAndReplyWithResult( 239 base::PostTaskAndReplyWithResult(
241 blocking_task_runner(), 240 blocking_task_runner(),
242 FROM_HERE, 241 FROM_HERE,
243 base::Bind(&FileCache::GetCacheEntry, 242 base::Bind(&FileCache::GetCacheEntry,
244 base::Unretained(cache()), 243 base::Unretained(cache()),
245 local_id, 244 local_id,
246 &cache_entry), 245 &cache_entry),
247 google_apis::test_util::CreateCopyResultCallback(&success)); 246 google_apis::test_util::CreateCopyResultCallback(&error));
248 test_util::RunBlockingPoolTask(); 247 test_util::RunBlockingPoolTask();
249 ASSERT_TRUE(success); 248 ASSERT_EQ(FILE_ERROR_OK, error);
250 EXPECT_FALSE(cache_entry.is_dirty()); 249 EXPECT_FALSE(cache_entry.is_dirty());
251 } 250 }
252 251
253 TEST_F(EntryUpdatePerformerTest, UpdateEntry_ContentUpdateMd5Check) { 252 TEST_F(EntryUpdatePerformerTest, UpdateEntry_ContentUpdateMd5Check) {
254 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); 253 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
255 const std::string kResourceId("file:2_file_resource_id"); 254 const std::string kResourceId("file:2_file_resource_id");
256 255
257 const std::string local_id = GetLocalId(kFilePath); 256 const std::string local_id = GetLocalId(kFilePath);
258 EXPECT_FALSE(local_id.empty()); 257 EXPECT_FALSE(local_id.empty());
259 258
(...skipping 22 matching lines...) Expand all
282 fake_service()->GetResourceEntry( 281 fake_service()->GetResourceEntry(
283 kResourceId, 282 kResourceId,
284 google_apis::test_util::CreateCopyResultCallback(&gdata_error, 283 google_apis::test_util::CreateCopyResultCallback(&gdata_error,
285 &server_entry)); 284 &server_entry));
286 test_util::RunBlockingPoolTask(); 285 test_util::RunBlockingPoolTask();
287 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error); 286 EXPECT_EQ(google_apis::HTTP_SUCCESS, gdata_error);
288 EXPECT_EQ(static_cast<int64>(kTestFileContent.size()), 287 EXPECT_EQ(static_cast<int64>(kTestFileContent.size()),
289 server_entry->file_size()); 288 server_entry->file_size());
290 289
291 // Make sure that the cache is no longer dirty. 290 // Make sure that the cache is no longer dirty.
292 bool success = false;
293 FileCacheEntry cache_entry; 291 FileCacheEntry cache_entry;
294 base::PostTaskAndReplyWithResult( 292 base::PostTaskAndReplyWithResult(
295 blocking_task_runner(), 293 blocking_task_runner(),
296 FROM_HERE, 294 FROM_HERE,
297 base::Bind(&FileCache::GetCacheEntry, 295 base::Bind(&FileCache::GetCacheEntry,
298 base::Unretained(cache()), 296 base::Unretained(cache()),
299 local_id, 297 local_id,
300 &cache_entry), 298 &cache_entry),
301 google_apis::test_util::CreateCopyResultCallback(&success)); 299 google_apis::test_util::CreateCopyResultCallback(&error));
302 test_util::RunBlockingPoolTask(); 300 test_util::RunBlockingPoolTask();
303 ASSERT_TRUE(success); 301 ASSERT_EQ(FILE_ERROR_OK, error);
304 EXPECT_FALSE(cache_entry.is_dirty()); 302 EXPECT_FALSE(cache_entry.is_dirty());
305 303
306 // Again mark the cache file dirty. 304 // Again mark the cache file dirty.
307 scoped_ptr<base::ScopedClosureRunner> file_closer; 305 scoped_ptr<base::ScopedClosureRunner> file_closer;
308 error = FILE_ERROR_FAILED; 306 error = FILE_ERROR_FAILED;
309 base::PostTaskAndReplyWithResult( 307 base::PostTaskAndReplyWithResult(
310 blocking_task_runner(), 308 blocking_task_runner(),
311 FROM_HERE, 309 FROM_HERE,
312 base::Bind(&FileCache::OpenForWrite, 310 base::Bind(&FileCache::OpenForWrite,
313 base::Unretained(cache()), 311 base::Unretained(cache()),
(...skipping 13 matching lines...) Expand all
327 local_id, 325 local_id,
328 ClientContext(USER_INITIATED), 326 ClientContext(USER_INITIATED),
329 google_apis::test_util::CreateCopyResultCallback(&error)); 327 google_apis::test_util::CreateCopyResultCallback(&error));
330 test_util::RunBlockingPoolTask(); 328 test_util::RunBlockingPoolTask();
331 EXPECT_EQ(FILE_ERROR_OK, error); 329 EXPECT_EQ(FILE_ERROR_OK, error);
332 330
333 EXPECT_EQ(original_changestamp, 331 EXPECT_EQ(original_changestamp,
334 fake_service()->about_resource().largest_change_id()); 332 fake_service()->about_resource().largest_change_id());
335 333
336 // Make sure that the cache is no longer dirty. 334 // Make sure that the cache is no longer dirty.
337 success = false;
338 base::PostTaskAndReplyWithResult( 335 base::PostTaskAndReplyWithResult(
339 blocking_task_runner(), 336 blocking_task_runner(),
340 FROM_HERE, 337 FROM_HERE,
341 base::Bind(&FileCache::GetCacheEntry, 338 base::Bind(&FileCache::GetCacheEntry,
342 base::Unretained(cache()), 339 base::Unretained(cache()),
343 local_id, 340 local_id,
344 &cache_entry), 341 &cache_entry),
345 google_apis::test_util::CreateCopyResultCallback(&success)); 342 google_apis::test_util::CreateCopyResultCallback(&error));
346 test_util::RunBlockingPoolTask(); 343 test_util::RunBlockingPoolTask();
347 ASSERT_TRUE(success); 344 ASSERT_EQ(FILE_ERROR_OK, error);
348 EXPECT_FALSE(cache_entry.is_dirty()); 345 EXPECT_FALSE(cache_entry.is_dirty());
349 } 346 }
350 347
351 TEST_F(EntryUpdatePerformerTest, UpdateEntry_OpenedForWrite) { 348 TEST_F(EntryUpdatePerformerTest, UpdateEntry_OpenedForWrite) {
352 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt")); 349 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/File 1.txt"));
353 const std::string kResourceId("file:2_file_resource_id"); 350 const std::string kResourceId("file:2_file_resource_id");
354 351
355 const std::string local_id = GetLocalId(kFilePath); 352 const std::string local_id = GetLocalId(kFilePath);
356 EXPECT_FALSE(local_id.empty()); 353 EXPECT_FALSE(local_id.empty());
357 354
(...skipping 17 matching lines...) Expand all
375 // Update. This should not clear the dirty bit. 372 // Update. This should not clear the dirty bit.
376 error = FILE_ERROR_FAILED; 373 error = FILE_ERROR_FAILED;
377 performer_->UpdateEntry( 374 performer_->UpdateEntry(
378 local_id, 375 local_id,
379 ClientContext(USER_INITIATED), 376 ClientContext(USER_INITIATED),
380 google_apis::test_util::CreateCopyResultCallback(&error)); 377 google_apis::test_util::CreateCopyResultCallback(&error));
381 test_util::RunBlockingPoolTask(); 378 test_util::RunBlockingPoolTask();
382 EXPECT_EQ(FILE_ERROR_OK, error); 379 EXPECT_EQ(FILE_ERROR_OK, error);
383 380
384 // Make sure that the cache is still dirty. 381 // Make sure that the cache is still dirty.
385 bool success = false;
386 FileCacheEntry cache_entry; 382 FileCacheEntry cache_entry;
387 base::PostTaskAndReplyWithResult( 383 base::PostTaskAndReplyWithResult(
388 blocking_task_runner(), 384 blocking_task_runner(),
389 FROM_HERE, 385 FROM_HERE,
390 base::Bind(&FileCache::GetCacheEntry, 386 base::Bind(&FileCache::GetCacheEntry,
391 base::Unretained(cache()), 387 base::Unretained(cache()),
392 local_id, 388 local_id,
393 &cache_entry), 389 &cache_entry),
394 google_apis::test_util::CreateCopyResultCallback(&success)); 390 google_apis::test_util::CreateCopyResultCallback(&error));
395 test_util::RunBlockingPoolTask(); 391 test_util::RunBlockingPoolTask();
396 EXPECT_TRUE(success); 392 EXPECT_EQ(FILE_ERROR_OK, error);
397 EXPECT_TRUE(cache_entry.is_dirty()); 393 EXPECT_TRUE(cache_entry.is_dirty());
398 394
399 // Close the file. 395 // Close the file.
400 file_closer.reset(); 396 file_closer.reset();
401 397
402 // Update. This should clear the dirty bit. 398 // Update. This should clear the dirty bit.
403 error = FILE_ERROR_FAILED; 399 error = FILE_ERROR_FAILED;
404 performer_->UpdateEntry( 400 performer_->UpdateEntry(
405 local_id, 401 local_id,
406 ClientContext(USER_INITIATED), 402 ClientContext(USER_INITIATED),
407 google_apis::test_util::CreateCopyResultCallback(&error)); 403 google_apis::test_util::CreateCopyResultCallback(&error));
408 test_util::RunBlockingPoolTask(); 404 test_util::RunBlockingPoolTask();
409 EXPECT_EQ(FILE_ERROR_OK, error); 405 EXPECT_EQ(FILE_ERROR_OK, error);
410 406
411 // Make sure that the cache is no longer dirty. 407 // Make sure that the cache is no longer dirty.
412 base::PostTaskAndReplyWithResult( 408 base::PostTaskAndReplyWithResult(
413 blocking_task_runner(), 409 blocking_task_runner(),
414 FROM_HERE, 410 FROM_HERE,
415 base::Bind(&FileCache::GetCacheEntry, 411 base::Bind(&FileCache::GetCacheEntry,
416 base::Unretained(cache()), 412 base::Unretained(cache()),
417 local_id, 413 local_id,
418 &cache_entry), 414 &cache_entry),
419 google_apis::test_util::CreateCopyResultCallback(&success)); 415 google_apis::test_util::CreateCopyResultCallback(&error));
420 test_util::RunBlockingPoolTask(); 416 test_util::RunBlockingPoolTask();
421 EXPECT_TRUE(success); 417 EXPECT_EQ(FILE_ERROR_OK, error);
422 EXPECT_FALSE(cache_entry.is_dirty()); 418 EXPECT_FALSE(cache_entry.is_dirty());
423 } 419 }
424 420
425 TEST_F(EntryUpdatePerformerTest, UpdateEntry_UploadNewFile) { 421 TEST_F(EntryUpdatePerformerTest, UpdateEntry_UploadNewFile) {
426 // Create a new file locally. 422 // Create a new file locally.
427 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); 423 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt"));
428 424
429 ResourceEntry parent; 425 ResourceEntry parent;
430 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath.DirName(), &parent)); 426 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath.DirName(), &parent));
431 427
(...skipping 24 matching lines...) Expand all
456 google_apis::test_util::CreateCopyResultCallback(&error)); 452 google_apis::test_util::CreateCopyResultCallback(&error));
457 test_util::RunBlockingPoolTask(); 453 test_util::RunBlockingPoolTask();
458 EXPECT_EQ(FILE_ERROR_OK, error); 454 EXPECT_EQ(FILE_ERROR_OK, error);
459 455
460 // The entry got a resource ID. 456 // The entry got a resource ID.
461 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); 457 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry));
462 EXPECT_FALSE(entry.resource_id().empty()); 458 EXPECT_FALSE(entry.resource_id().empty());
463 EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state()); 459 EXPECT_EQ(ResourceEntry::CLEAN, entry.metadata_edit_state());
464 460
465 // Make sure that the cache is no longer dirty. 461 // Make sure that the cache is no longer dirty.
466 bool success = false;
467 FileCacheEntry cache_entry; 462 FileCacheEntry cache_entry;
468 base::PostTaskAndReplyWithResult( 463 base::PostTaskAndReplyWithResult(
469 blocking_task_runner(), 464 blocking_task_runner(),
470 FROM_HERE, 465 FROM_HERE,
471 base::Bind(&FileCache::GetCacheEntry, 466 base::Bind(&FileCache::GetCacheEntry,
472 base::Unretained(cache()), 467 base::Unretained(cache()),
473 local_id, 468 local_id,
474 &cache_entry), 469 &cache_entry),
475 google_apis::test_util::CreateCopyResultCallback(&success)); 470 google_apis::test_util::CreateCopyResultCallback(&error));
476 test_util::RunBlockingPoolTask(); 471 test_util::RunBlockingPoolTask();
477 EXPECT_TRUE(success); 472 EXPECT_EQ(FILE_ERROR_OK, error);
478 EXPECT_FALSE(cache_entry.is_dirty()); 473 EXPECT_FALSE(cache_entry.is_dirty());
479 474
480 // Make sure that we really created a file. 475 // Make sure that we really created a file.
481 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR; 476 google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
482 scoped_ptr<google_apis::ResourceEntry> resource_entry; 477 scoped_ptr<google_apis::ResourceEntry> resource_entry;
483 fake_service()->GetResourceEntry( 478 fake_service()->GetResourceEntry(
484 entry.resource_id(), 479 entry.resource_id(),
485 google_apis::test_util::CreateCopyResultCallback(&status, 480 google_apis::test_util::CreateCopyResultCallback(&status,
486 &resource_entry)); 481 &resource_entry));
487 test_util::RunBlockingPoolTask(); 482 test_util::RunBlockingPoolTask();
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 google_apis::test_util::CreateCopyResultCallback(&status, 607 google_apis::test_util::CreateCopyResultCallback(&status,
613 &resource_entry)); 608 &resource_entry));
614 test_util::RunBlockingPoolTask(); 609 test_util::RunBlockingPoolTask();
615 EXPECT_EQ(google_apis::HTTP_SUCCESS, status); 610 EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
616 ASSERT_TRUE(resource_entry); 611 ASSERT_TRUE(resource_entry);
617 EXPECT_TRUE(resource_entry->is_folder()); 612 EXPECT_TRUE(resource_entry->is_folder());
618 } 613 }
619 614
620 } // namespace internal 615 } // namespace internal
621 } // namespace drive 616 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/sync/entry_update_performer.cc ('k') | chrome/browser/chromeos/drive/sync_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698