| Index: chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| diff --git a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| index 7817d9efc74c3a751fd961a6580801b902e8cc01..84741a6fd1c980689454111b135a8ec900f0d298 100644
|
| --- a/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| +++ b/chrome/browser/chromeos/gdata/gdata_file_system_unittest.cc
|
| @@ -8,6 +8,8 @@
|
| #include "base/file_path.h"
|
| #include "base/file_util.h"
|
| #include "base/json/json_file_value_serializer.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/message_loop.h"
|
| #include "base/path_service.h"
|
| #include "base/string16.h"
|
| @@ -15,6 +17,7 @@
|
| #include "base/utf_string_conversions.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
|
| +#include "chrome/browser/chromeos/gdata/gdata_mock.h"
|
| #include "chrome/browser/chromeos/gdata/gdata_parser.h"
|
| #include "chrome/common/chrome_paths.h"
|
| #include "chrome/test/base/testing_profile.h"
|
| @@ -39,9 +42,22 @@ class GDataFileSystemTest : public testing::Test {
|
| : ui_thread_(content::BrowserThread::UI, &message_loop_) {
|
| }
|
|
|
| - virtual void SetUp() {
|
| + virtual void SetUp() OVERRIDE {
|
| + callback_helper_ = new CallbackHelper;
|
| profile_.reset(new TestingProfile);
|
| file_system_ = GDataFileSystemFactory::GetForProfile(profile_.get());
|
| +
|
| + // Allocate and keep a weak pointer to the mock.
|
| + mock_doc_service_ = new MockDocumentsService;
|
| + EXPECT_CALL(*mock_doc_service_, Initialize(profile_.get())).Times(1);
|
| +
|
| + // Pass the service for the filesystem to own.
|
| + scoped_ptr<DocumentsServiceInterface> service(mock_doc_service_);
|
| + file_system_->ReplaceDocumentsService(service.Pass());
|
| + }
|
| +
|
| + virtual void TearDown() OVERRIDE {
|
| + EXPECT_CALL(*mock_doc_service_, CancelAll()).Times(1);
|
| }
|
|
|
| // Loads test json file as root ("/gdata") element.
|
| @@ -139,10 +155,33 @@ class GDataFileSystemTest : public testing::Test {
|
| return value;
|
| }
|
|
|
| + // This is used as a helper for registering callbacks that need to be
|
| + // RefCountedThreadSafe, and a place where we can fetch results from various
|
| + // operations.
|
| + class CallbackHelper
|
| + : public base::RefCountedThreadSafe<CallbackHelper> {
|
| + public:
|
| + CallbackHelper() : last_error_(base::PLATFORM_FILE_OK) {}
|
| + virtual ~CallbackHelper() {}
|
| + virtual void GetFileCallback(base::PlatformFileError error,
|
| + const FilePath& file_path) {
|
| + last_error_ = error;
|
| + download_path_ = file_path;
|
| + }
|
| + virtual void FileOperationCallback(base::PlatformFileError error) {
|
| + last_error_ = error;
|
| + }
|
| +
|
| + base::PlatformFileError last_error_;
|
| + FilePath download_path_;
|
| + };
|
| +
|
| MessageLoopForUI message_loop_;
|
| content::TestBrowserThread ui_thread_;
|
| scoped_ptr<TestingProfile> profile_;
|
| + scoped_refptr<CallbackHelper> callback_helper_;
|
| GDataFileSystem* file_system_;
|
| + MockDocumentsService* mock_doc_service_;
|
| };
|
|
|
|
|
| @@ -426,7 +465,7 @@ TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) {
|
| EXPECT_FALSE(last_dir_content_url.is_empty()); // non-root directory.
|
|
|
| // Missing two folders on the path.
|
| - FilePath dir_path3 = dir_path2.Append(FILE_PATH_LITERAL("Another Foder"));
|
| + FilePath dir_path3 = dir_path2.Append(FILE_PATH_LITERAL("Another Folder"));
|
| EXPECT_EQ(
|
| GDataFileSystem::FOUND_MISSING,
|
| file_system_->FindFirstMissingParentDirectory(dir_path3,
|
| @@ -453,9 +492,6 @@ TEST_F(GDataFileSystemTest, FindFirstMissingParentDirectory) {
|
| &first_missing_parent_path));
|
| }
|
|
|
| -// TODO(satorux): Write a test for GetFile() once DocumentsService is
|
| -// mockable.
|
| -
|
| TEST_F(GDataFileSystemTest, GetGDataFileInfoFromPath) {
|
| LoadRootFeedDocument("root_feed.json");
|
|
|
| @@ -470,4 +506,38 @@ TEST_F(GDataFileSystemTest, GetGDataFileInfoFromPath) {
|
| ASSERT_TRUE(non_existent == NULL);
|
| }
|
|
|
| +// Create a directory through the document service
|
| +TEST_F(GDataFileSystemTest, CreateDirectoryWithService) {
|
| + LoadRootFeedDocument("root_feed.json");
|
| + EXPECT_CALL(*mock_doc_service_,
|
| + CreateDirectory(_, "Sample Directory Title", _)).Times(1);
|
| +
|
| + // Set last error so it's not a valid error code.
|
| + callback_helper_->last_error_ = static_cast<base::PlatformFileError>(1);
|
| + file_system_->CreateDirectory(
|
| + FilePath(FILE_PATH_LITERAL("gdata/Sample Directory Title")),
|
| + false, // is_exclusive
|
| + true, // is_recursive
|
| + base::Bind(&CallbackHelper::FileOperationCallback,
|
| + callback_helper_.get()));
|
| + // TODO(gspencer): Uncomment this when we get a blob that
|
| + // works that can be returned from the mock.
|
| + // EXPECT_EQ(base::PLATFORM_FILE_OK, callback_helper_->last_error_);
|
| +}
|
| +
|
| +TEST_F(GDataFileSystemTest, GetFile) {
|
| + LoadRootFeedDocument("root_feed.json");
|
| +
|
| + GDataFileSystem::GetFileCallback callback =
|
| + base::Bind(&CallbackHelper::GetFileCallback,
|
| + callback_helper_.get());
|
| +
|
| + EXPECT_CALL(*mock_doc_service_,
|
| + DownloadFile(GURL("https://file_content_url/"), _));
|
| +
|
| + FilePath file_in_root(FILE_PATH_LITERAL("gdata/File 1.txt"));
|
| + file_system_->GetFile(file_in_root, callback);
|
| + EXPECT_STREQ("file_content_url/",
|
| + callback_helper_->download_path_.value().c_str());
|
| +}
|
| } // namespace gdata
|
|
|