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

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

Issue 304183005: drive: Always use last_modified stored in ResourceEntry (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_cache.h" 5 #include "chrome/browser/chromeos/drive/file_cache.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // Prepare a file. 351 // Prepare a file.
352 base::FilePath src_file; 352 base::FilePath src_file;
353 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &src_file)); 353 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir_.path(), &src_file));
354 354
355 const std::string id = "id"; 355 const std::string id = "id";
356 ResourceEntry entry; 356 ResourceEntry entry;
357 entry.set_local_id(id); 357 entry.set_local_id(id);
358 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->PutEntry(entry)); 358 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->PutEntry(entry));
359 ASSERT_EQ(FILE_ERROR_OK, cache_->Store(id, "md5", src_file, 359 ASSERT_EQ(FILE_ERROR_OK, cache_->Store(id, "md5", src_file,
360 FileCache::FILE_OPERATION_COPY)); 360 FileCache::FILE_OPERATION_COPY));
361 EXPECT_EQ(0, entry.file_info().last_modified());
361 362
362 // Entry is not dirty nor opened. 363 // Entry is not dirty nor opened.
363 EXPECT_FALSE(cache_->IsOpenedForWrite(id)); 364 EXPECT_FALSE(cache_->IsOpenedForWrite(id));
364 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); 365 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry));
365 EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty()); 366 EXPECT_FALSE(entry.file_specific_info().cache_state().is_dirty());
366 367
367 // Open (1). 368 // Open (1).
368 scoped_ptr<base::ScopedClosureRunner> file_closer1; 369 scoped_ptr<base::ScopedClosureRunner> file_closer1;
369 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(id, &file_closer1)); 370 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(id, &file_closer1));
370 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); 371 EXPECT_TRUE(cache_->IsOpenedForWrite(id));
371 372
372 // Entry is dirty. 373 // Entry is dirty.
373 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry)); 374 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry));
374 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty()); 375 EXPECT_TRUE(entry.file_specific_info().cache_state().is_dirty());
375 376
376 // Open (2). 377 // Open (2).
377 scoped_ptr<base::ScopedClosureRunner> file_closer2; 378 scoped_ptr<base::ScopedClosureRunner> file_closer2;
378 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(id, &file_closer2)); 379 EXPECT_EQ(FILE_ERROR_OK, cache_->OpenForWrite(id, &file_closer2));
379 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); 380 EXPECT_TRUE(cache_->IsOpenedForWrite(id));
380 381
381 // Close (1). 382 // Close (1).
382 file_closer1.reset(); 383 file_closer1.reset();
383 EXPECT_TRUE(cache_->IsOpenedForWrite(id)); 384 EXPECT_TRUE(cache_->IsOpenedForWrite(id));
384 385
386 // last_modified is updated.
387 EXPECT_EQ(FILE_ERROR_OK, metadata_storage_->GetEntry(id, &entry));
388 EXPECT_NE(0, entry.file_info().last_modified());
389
385 // Close (2). 390 // Close (2).
386 file_closer2.reset(); 391 file_closer2.reset();
387 EXPECT_FALSE(cache_->IsOpenedForWrite(id)); 392 EXPECT_FALSE(cache_->IsOpenedForWrite(id));
388 393
389 // Try to open non-existent file. 394 // Try to open non-existent file.
390 EXPECT_EQ(FILE_ERROR_NOT_FOUND, 395 EXPECT_EQ(FILE_ERROR_NOT_FOUND,
391 cache_->OpenForWrite("nonexistent_id", &file_closer1)); 396 cache_->OpenForWrite("nonexistent_id", &file_closer1));
392 } 397 }
393 398
394 TEST_F(FileCacheTest, UpdateMd5) { 399 TEST_F(FileCacheTest, UpdateMd5) {
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 547
543 // Clear cache. 548 // Clear cache.
544 EXPECT_TRUE(cache_->ClearAll()); 549 EXPECT_TRUE(cache_->ClearAll());
545 550
546 // Verify that the cache is removed. 551 // Verify that the cache is removed.
547 EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_)); 552 EXPECT_TRUE(base::IsDirectoryEmpty(cache_files_dir_));
548 } 553 }
549 554
550 } // namespace internal 555 } // namespace internal
551 } // namespace drive 556 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/file_cache.cc ('k') | chrome/browser/chromeos/drive/file_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698