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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc

Issue 10182009: gdata: Remove GDataFileSystem::GetFileFromCacheByPath() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better solution Created 8 years, 8 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 <errno.h> 5 #include <errno.h>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 expected_error_ = expected_error; 357 expected_error_ = expected_error;
358 expected_file_extension_ = expected_file_extension; 358 expected_file_extension_ = expected_file_extension;
359 359
360 file_system_->GetFileFromCacheByResourceIdAndMd5(resource_id, md5, 360 file_system_->GetFileFromCacheByResourceIdAndMd5(resource_id, md5,
361 base::Bind(&GDataFileSystemTest::VerifyGetFromCache, 361 base::Bind(&GDataFileSystemTest::VerifyGetFromCache,
362 base::Unretained(this))); 362 base::Unretained(this)));
363 363
364 RunAllPendingForIO(); 364 RunAllPendingForIO();
365 } 365 }
366 366
367 void TestGetFileFromCacheByPath(const FilePath& gdata_file_path,
368 base::PlatformFileError expected_error) {
369 expected_error_ = expected_error;
370 expected_file_extension_.clear();
371
372 file_system_->GetFileFromCacheByPath(gdata_file_path,
373 base::Bind(&GDataFileSystemTest::VerifyGetFromCache,
374 base::Unretained(this)));
375
376 RunAllPendingForIO();
377 }
378
379 void VerifyGetFromCache(base::PlatformFileError error, 367 void VerifyGetFromCache(base::PlatformFileError error,
380 const std::string& resource_id, 368 const std::string& resource_id,
381 const std::string& md5, 369 const std::string& md5,
382 const FilePath& gdata_file_path, 370 const FilePath& gdata_file_path,
383 const FilePath& cache_file_path) { 371 const FilePath& cache_file_path) {
384 ++num_callback_invocations_; 372 ++num_callback_invocations_;
385 373
386 EXPECT_EQ(expected_error_, error); 374 EXPECT_EQ(expected_error_, error);
387 375
388 if (error == base::PLATFORM_FILE_OK) { 376 if (error == base::PLATFORM_FILE_OK) {
(...skipping 2229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2618 ASSERT_TRUE(entry != NULL); 2606 ASSERT_TRUE(entry != NULL);
2619 EXPECT_EQ("https://file1_link_self/file:2_file_resource_id", 2607 EXPECT_EQ("https://file1_link_self/file:2_file_resource_id",
2620 entry->edit_url().spec()); 2608 entry->edit_url().spec());
2621 EXPECT_EQ("https://file_content_url/", entry->content_url().spec()); 2609 EXPECT_EQ("https://file_content_url/", entry->content_url().spec());
2622 2610
2623 GDataEntry* non_existent = file_system_->GetGDataEntryByPath( 2611 GDataEntry* non_existent = file_system_->GetGDataEntryByPath(
2624 FilePath(FILE_PATH_LITERAL("gdata/Nonexistent.txt"))); 2612 FilePath(FILE_PATH_LITERAL("gdata/Nonexistent.txt")));
2625 ASSERT_TRUE(non_existent == NULL); 2613 ASSERT_TRUE(non_existent == NULL);
2626 } 2614 }
2627 2615
2628 TEST_F(GDataFileSystemTest, GetFileFromCacheByPath) {
2629 EXPECT_CALL(*mock_sync_client_, OnCacheInitialized()).Times(1);
2630
2631 LoadRootFeedDocument("root_feed.json");
2632
2633 // First make sure the file exists in GData.
2634 FilePath gdata_file_path = FilePath(FILE_PATH_LITERAL("gdata/File 1.txt"));
2635 GDataFile* file = NULL;
2636 { // Lock to call GetGDataEntryByPath.
2637 base::AutoLock lock(file_system_->lock_);
2638 GDataEntry* entry =
2639 file_system_->GetGDataEntryByPath(gdata_file_path);
2640 ASSERT_TRUE(entry != NULL);
2641 file = entry->AsGDataFile();
2642 ASSERT_TRUE(file != NULL);
2643 }
2644
2645 // A file that exists in GData but not in cache.
2646 num_callback_invocations_ = 0;
2647 TestGetFileFromCacheByPath(
2648 gdata_file_path, base::PLATFORM_FILE_ERROR_NOT_FOUND);
2649 EXPECT_EQ(1, num_callback_invocations_);
2650
2651 // Store a file corresponding to resource and md5 of "gdata/File 1.txt" to
2652 // cache.
2653 num_callback_invocations_ = 0;
2654 TestStoreToCache(file->resource_id(), file->file_md5(),
2655 GetTestFilePath("root_feed.json"), base::PLATFORM_FILE_OK,
2656 GDataFile::CACHE_STATE_PRESENT,
2657 GDataRootDirectory::CACHE_TYPE_TMP);
2658 EXPECT_EQ(1, num_callback_invocations_);
2659
2660 // Now the file should exist in cache.
2661 num_callback_invocations_ = 0;
2662 TestGetFileFromCacheByPath(gdata_file_path, base::PLATFORM_FILE_OK);
2663 EXPECT_EQ(1, num_callback_invocations_);
2664
2665 // A file that doesn't exist in gdata.
2666 num_callback_invocations_ = 0;
2667 TestGetFileFromCacheByPath(
2668 FilePath(FILE_PATH_LITERAL("gdata/Nonexistent.txt")),
2669 base::PLATFORM_FILE_ERROR_NOT_FOUND);
2670 EXPECT_EQ(1, num_callback_invocations_);
2671 }
2672
2673 // Create a directory through the document service 2616 // Create a directory through the document service
2674 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) { 2617 TEST_F(GDataFileSystemTest, CreateDirectoryWithService) {
2675 LoadRootFeedDocument("root_feed.json"); 2618 LoadRootFeedDocument("root_feed.json");
2676 EXPECT_CALL(*mock_doc_service_, 2619 EXPECT_CALL(*mock_doc_service_,
2677 CreateDirectory(_, "Sample Directory Title", _)).Times(1); 2620 CreateDirectory(_, "Sample Directory Title", _)).Times(1);
2678 2621
2679 // Set last error so it's not a valid error code. 2622 // Set last error so it's not a valid error code.
2680 callback_helper_->last_error_ = static_cast<base::PlatformFileError>(1); 2623 callback_helper_->last_error_ = static_cast<base::PlatformFileError>(1);
2681 file_system_->CreateDirectory( 2624 file_system_->CreateDirectory(
2682 FilePath(FILE_PATH_LITERAL("gdata/Sample Directory Title")), 2625 FilePath(FILE_PATH_LITERAL("gdata/Sample Directory Title")),
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3025 2968
3026 // Verify account meta feed is saved to cache. 2969 // Verify account meta feed is saved to cache.
3027 RunAllPendingForIO(); 2970 RunAllPendingForIO();
3028 FilePath path = file_system_->cache_paths_[ 2971 FilePath path = file_system_->cache_paths_[
3029 GDataRootDirectory::CACHE_TYPE_META].Append( 2972 GDataRootDirectory::CACHE_TYPE_META].Append(
3030 FILE_PATH_LITERAL("account_metadata.json")); 2973 FILE_PATH_LITERAL("account_metadata.json"));
3031 EXPECT_TRUE(file_util::PathExists(path)); 2974 EXPECT_TRUE(file_util::PathExists(path));
3032 } 2975 }
3033 2976
3034 } // namespace gdata 2977 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_file_system.cc ('k') | chrome/browser/chromeos/gdata/mock_gdata_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698