OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/gdata/gdata_mock.h" |
| 6 |
| 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" |
| 9 #include "base/json/json_file_value_serializer.h" |
| 10 #include "base/path_service.h" |
| 11 #include "base/platform_file.h" |
| 12 #include "chrome/common/chrome_paths.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 |
| 15 using ::testing::_; |
| 16 using ::testing::Invoke; |
| 17 |
| 18 namespace gdata { |
| 19 |
| 20 namespace { |
| 21 static Value* LoadJSONFile(const std::string& filename) { |
| 22 FilePath path; |
| 23 std::string error; |
| 24 PathService::Get(chrome::DIR_TEST_DATA, &path); |
| 25 path = path.AppendASCII("chromeos") |
| 26 .AppendASCII("gdata") |
| 27 .AppendASCII(filename.c_str()); |
| 28 EXPECT_TRUE(file_util::PathExists(path)) << |
| 29 "Couldn't find " << path.value(); |
| 30 |
| 31 JSONFileValueSerializer serializer(path); |
| 32 Value* value = serializer.Deserialize(NULL, &error); |
| 33 EXPECT_TRUE(value) << |
| 34 "Parse error " << path.value() << ": " << error; |
| 35 return value; |
| 36 } |
| 37 } // namespace |
| 38 |
| 39 MockDocumentsService::MockDocumentsService() { |
| 40 ON_CALL(*this, Authenticate(_)) |
| 41 .WillByDefault(Invoke(this, &MockDocumentsService::AuthenticateStub)); |
| 42 ON_CALL(*this, GetDocuments(_, _)) |
| 43 .WillByDefault(Invoke(this, &MockDocumentsService::GetDocumentsStub)); |
| 44 ON_CALL(*this, DeleteDocument(_, _)) |
| 45 .WillByDefault(Invoke(this, &MockDocumentsService::DeleteDocumentStub)); |
| 46 ON_CALL(*this, DownloadDocument(_, _, _)) |
| 47 .WillByDefault(Invoke(this, &MockDocumentsService::DownloadDocumentStub)); |
| 48 ON_CALL(*this, CreateDirectory(_, _, _)) |
| 49 .WillByDefault(Invoke(this, &MockDocumentsService::CreateDirectoryStub)); |
| 50 ON_CALL(*this, DownloadFile(_, _)) |
| 51 .WillByDefault(Invoke(this, &MockDocumentsService::DownloadFileStub)); |
| 52 |
| 53 // Fill in the default values for mock feeds. |
| 54 feed_data_.reset(LoadJSONFile("basic_feed.json")); |
| 55 directory_data_.reset(LoadJSONFile("subdir_feed.json")); |
| 56 } |
| 57 |
| 58 MockDocumentsService::~MockDocumentsService() {} |
| 59 |
| 60 void MockDocumentsService::AuthenticateStub( |
| 61 const AuthStatusCallback& callback) { |
| 62 callback.Run(HTTP_SUCCESS, "my_auth_token"); |
| 63 } |
| 64 |
| 65 void MockDocumentsService::GetDocumentsStub( |
| 66 const GURL& feed_url, |
| 67 const GetDataCallback& callback) { |
| 68 callback.Run(HTTP_SUCCESS, feed_data_.Pass()); |
| 69 } |
| 70 |
| 71 void MockDocumentsService::DeleteDocumentStub( |
| 72 const GURL& document_url, |
| 73 const EntryActionCallback& callback) { |
| 74 callback.Run(HTTP_SUCCESS, document_url); |
| 75 } |
| 76 |
| 77 void MockDocumentsService::DownloadDocumentStub( |
| 78 const GURL& content_url, |
| 79 DocumentExportFormat format, |
| 80 const DownloadActionCallback& callback) { |
| 81 callback.Run(HTTP_SUCCESS, content_url, FilePath( |
| 82 content_url.host() + content_url.path())); |
| 83 } |
| 84 |
| 85 void MockDocumentsService::CreateDirectoryStub( |
| 86 const GURL& parent_content_url, |
| 87 const FilePath::StringType& directory_name, |
| 88 const GetDataCallback& callback) { |
| 89 callback.Run(HTTP_SUCCESS, directory_data_.Pass()); |
| 90 } |
| 91 |
| 92 void MockDocumentsService::DownloadFileStub( |
| 93 const GURL& content_url, |
| 94 const DownloadActionCallback& callback) { |
| 95 callback.Run(HTTP_SUCCESS, content_url, FilePath( |
| 96 content_url.host() + content_url.path())); |
| 97 } |
| 98 |
| 99 } // namespace gdata |
OLD | NEW |