Chromium Code Reviews| Index: chrome/browser/chromeos/gdata/gdata_mock.cc |
| diff --git a/chrome/browser/chromeos/gdata/gdata_mock.cc b/chrome/browser/chromeos/gdata/gdata_mock.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..26f811ec3e59e254b96c6011d8df71b9f9818504 |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/gdata/gdata_mock.cc |
| @@ -0,0 +1,101 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/gdata/gdata_mock.h" |
| + |
| +#include "base/file_path.h" |
| +#include "base/file_util.h" |
| +#include "base/json/json_file_value_serializer.h" |
| +#include "base/path_service.h" |
| +#include "base/platform_file.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| + |
| +using ::testing::_; |
| +using ::testing::Invoke; |
| + |
| +namespace gdata { |
| + |
| +namespace { |
| + |
| +static Value* LoadJSONFile(const std::string& filename) { |
| + FilePath path; |
| + std::string error; |
| + PathService::Get(chrome::DIR_TEST_DATA, &path); |
| + path = path.AppendASCII("chromeos") |
| + .AppendASCII("gdata") |
| + .AppendASCII(filename.c_str()); |
| + EXPECT_TRUE(file_util::PathExists(path)) << |
| + "Couldn't find " << path.value(); |
| + |
| + JSONFileValueSerializer serializer(path); |
| + Value* value = serializer.Deserialize(NULL, &error); |
| + EXPECT_TRUE(value) << |
| + "Parse error " << path.value() << ": " << error; |
| + return value; |
| +} |
| + |
| +} // namespace |
| + |
| +MockDocumentsService::MockDocumentsService() { |
| + ON_CALL(*this, Authenticate(_)) |
| + .WillByDefault(Invoke(this, &MockDocumentsService::AuthenticateStub)); |
|
zel
2012/03/08 19:14:08
pass base::MessageLoopProxy::current() to all *Stu
|
| + ON_CALL(*this, GetDocuments(_, _)) |
| + .WillByDefault(Invoke(this, &MockDocumentsService::GetDocumentsStub)); |
| + ON_CALL(*this, DeleteDocument(_, _)) |
| + .WillByDefault(Invoke(this, &MockDocumentsService::DeleteDocumentStub)); |
| + ON_CALL(*this, DownloadDocument(_, _, _)) |
| + .WillByDefault(Invoke(this, &MockDocumentsService::DownloadDocumentStub)); |
| + ON_CALL(*this, CreateDirectory(_, _, _)) |
| + .WillByDefault(Invoke(this, &MockDocumentsService::CreateDirectoryStub)); |
| + ON_CALL(*this, DownloadFile(_, _)) |
| + .WillByDefault(Invoke(this, &MockDocumentsService::DownloadFileStub)); |
| + |
| + // Fill in the default values for mock feeds. |
| + feed_data_.reset(LoadJSONFile("basic_feed.json")); |
| + directory_data_.reset(LoadJSONFile("subdir_feed.json")); |
| +} |
| + |
| +MockDocumentsService::~MockDocumentsService() {} |
| + |
| +void MockDocumentsService::AuthenticateStub( |
| + const AuthStatusCallback& callback) { |
| + callback.Run(HTTP_SUCCESS, "my_auth_token"); |
| +} |
| + |
| +void MockDocumentsService::GetDocumentsStub( |
| + const GURL& feed_url, |
| + const GetDataCallback& callback) { |
| + callback.Run(HTTP_SUCCESS, feed_data_.Pass()); |
| +} |
| + |
| +void MockDocumentsService::DeleteDocumentStub( |
| + const GURL& document_url, |
| + const EntryActionCallback& callback) { |
| + callback.Run(HTTP_SUCCESS, document_url); |
| +} |
| + |
| +void MockDocumentsService::DownloadDocumentStub( |
| + const GURL& content_url, |
| + DocumentExportFormat format, |
| + const DownloadActionCallback& callback) { |
|
zel
2012/03/08 19:14:08
This and all other *Stub methods should be an asyn
Greg Spencer (Chromium)
2012/03/08 19:44:36
Excellent point, but I don't think I can pass the
zel
2012/03/08 21:02:38
I guess that would work too.
|
| + callback.Run(HTTP_SUCCESS, content_url, FilePath( |
| + content_url.host() + content_url.path())); |
| +} |
| + |
| +void MockDocumentsService::CreateDirectoryStub( |
| + const GURL& parent_content_url, |
| + const FilePath::StringType& directory_name, |
| + const GetDataCallback& callback) { |
| + callback.Run(HTTP_SUCCESS, directory_data_.Pass()); |
| +} |
| + |
| +void MockDocumentsService::DownloadFileStub( |
| + const GURL& content_url, |
| + const DownloadActionCallback& callback) { |
| + callback.Run(HTTP_SUCCESS, content_url, FilePath( |
| + content_url.host() + content_url.path())); |
| +} |
| + |
| +} // namespace gdata |