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

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

Issue 9582037: Make document service an interface (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Upload after merge Created 8 years, 9 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
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_mock.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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/bind.h"
8 #include "base/file_path.h"
9 #include "base/file_util.h"
10 #include "base/location.h"
11 #include "base/json/json_file_value_serializer.h"
12 #include "base/message_loop_proxy.h"
13 #include "base/path_service.h"
14 #include "base/platform_file.h"
15 #include "chrome/common/chrome_paths.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17
18 using ::testing::_;
19 using ::testing::Invoke;
20
21 namespace gdata {
22
23 namespace {
24
25 static Value* LoadJSONFile(const std::string& filename) {
26 FilePath path;
27 std::string error;
28 PathService::Get(chrome::DIR_TEST_DATA, &path);
29 path = path.AppendASCII("chromeos")
30 .AppendASCII("gdata")
31 .AppendASCII(filename.c_str());
32 EXPECT_TRUE(file_util::PathExists(path)) <<
33 "Couldn't find " << path.value();
34
35 JSONFileValueSerializer serializer(path);
36 Value* value = serializer.Deserialize(NULL, &error);
37 EXPECT_TRUE(value) <<
38 "Parse error " << path.value() << ": " << error;
39 return value;
40 }
41
42 } // namespace
43
44 MockDocumentsService::MockDocumentsService() {
45 ON_CALL(*this, Authenticate(_))
46 .WillByDefault(Invoke(this, &MockDocumentsService::AuthenticateStub));
47 ON_CALL(*this, GetDocuments(_, _))
48 .WillByDefault(Invoke(this, &MockDocumentsService::GetDocumentsStub));
49 ON_CALL(*this, DeleteDocument(_, _))
50 .WillByDefault(Invoke(this, &MockDocumentsService::DeleteDocumentStub));
51 ON_CALL(*this, DownloadDocument(_, _, _))
52 .WillByDefault(Invoke(this, &MockDocumentsService::DownloadDocumentStub));
53 ON_CALL(*this, CreateDirectory(_, _, _))
54 .WillByDefault(Invoke(this, &MockDocumentsService::CreateDirectoryStub));
55 ON_CALL(*this, DownloadFile(_, _))
56 .WillByDefault(Invoke(this, &MockDocumentsService::DownloadFileStub));
57
58 // Fill in the default values for mock feeds.
59 feed_data_.reset(LoadJSONFile("basic_feed.json"));
60 directory_data_.reset(LoadJSONFile("subdir_feed.json"));
61 }
62
63 MockDocumentsService::~MockDocumentsService() {}
64
65 void MockDocumentsService::AuthenticateStub(
66 const AuthStatusCallback& callback) {
67 base::MessageLoopProxy::current()->PostTask(
68 FROM_HERE,
69 base::Bind(callback, HTTP_SUCCESS, "my_auth_token"));
70 }
71
72 void MockDocumentsService::GetDocumentsStub(
73 const GURL& feed_url,
74 const GetDataCallback& callback) {
75 base::MessageLoopProxy::current()->PostTask(
76 FROM_HERE,
77 base::Bind(callback, HTTP_SUCCESS, base::Passed(&feed_data_)));
78 }
79
80 void MockDocumentsService::DeleteDocumentStub(
81 const GURL& document_url,
82 const EntryActionCallback& callback) {
83 base::MessageLoopProxy::current()->PostTask(
84 FROM_HERE,
85 base::Bind(callback, HTTP_SUCCESS, document_url));
86 }
87
88 void MockDocumentsService::DownloadDocumentStub(
89 const GURL& content_url,
90 DocumentExportFormat format,
91 const DownloadActionCallback& callback) {
92 base::MessageLoopProxy::current()->PostTask(
93 FROM_HERE,
94 base::Bind(callback, HTTP_SUCCESS, content_url,
95 FilePath(content_url.host() + content_url.path())));
96 }
97
98 void MockDocumentsService::CreateDirectoryStub(
99 const GURL& parent_content_url,
100 const FilePath::StringType& directory_name,
101 const GetDataCallback& callback) {
102 base::MessageLoopProxy::current()->PostTask(
103 FROM_HERE,
104 base::Bind(callback, HTTP_SUCCESS, base::Passed(&directory_data_)));
105 }
106
107 void MockDocumentsService::DownloadFileStub(
108 const GURL& content_url,
109 const DownloadActionCallback& callback) {
110 base::MessageLoopProxy::current()->PostTask(
111 FROM_HERE,
112 base::Bind(callback, HTTP_SUCCESS, content_url, FilePath(
113 content_url.host() + content_url.path())));
114 }
115
116 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_mock.h ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698