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