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

Side by Side Diff: chrome/browser/extensions/api/copresence/copresence_api_unittest.cc

Issue 824593003: Revert of Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 12 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 | « no previous file | components/components_tests.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_writer.h" 5 #include "base/json/json_writer.h"
6 #include "base/values.h" 6 #include "base/values.h"
7 #include "chrome/browser/extensions/api/copresence/copresence_api.h" 7 #include "chrome/browser/extensions/api/copresence/copresence_api.h"
8 #include "chrome/browser/extensions/extension_api_unittest.h" 8 #include "chrome/browser/extensions/extension_api_unittest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 9 #include "chrome/browser/extensions/extension_function_test_utils.h"
10 #include "components/copresence/proto/data.pb.h" 10 #include "components/copresence/proto/data.pb.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 60
61 template <typename T> 61 template <typename T>
62 bool GetOnly(const RepeatedPtrField<T>& things, T* out) { 62 bool GetOnly(const RepeatedPtrField<T>& things, T* out) {
63 if (things.size() != 1) 63 if (things.size() != 1)
64 return false; 64 return false;
65 65
66 *out = things.Get(0); 66 *out = things.Get(0);
67 return true; 67 return true;
68 } 68 }
69 69
70 class FakeCopresenceManager : public CopresenceManager { 70 class MockCopresenceManager : public CopresenceManager {
71 public: 71 public:
72 explicit FakeCopresenceManager(CopresenceDelegate* delegate) 72 explicit MockCopresenceManager(CopresenceDelegate* delegate)
73 : delegate_(delegate) {} 73 : delegate_(delegate) {}
74 ~FakeCopresenceManager() override {} 74 ~MockCopresenceManager() override {}
75 75
76 // CopresenceManager overrides.
77 copresence::CopresenceState* state() override {
78 NOTREACHED();
79 return nullptr;
80 }
81 void ExecuteReportRequest( 76 void ExecuteReportRequest(
82 const ReportRequest& request, 77 const ReportRequest& request,
83 const std::string& app_id, 78 const std::string& app_id,
84 const std::string& /* auth_token */, 79 const std::string& /* auth_token */,
85 const copresence::StatusCallback& status_callback) override { 80 const copresence::StatusCallback& status_callback) override {
86 request_ = request; 81 request_ = request;
87 app_id_ = app_id; 82 app_id_ = app_id;
88 status_callback.Run(copresence::SUCCESS); 83 status_callback.Run(copresence::SUCCESS);
89 } 84 }
90 85
91 CopresenceDelegate* delegate_; 86 CopresenceDelegate* delegate_;
92 87
93 ReportRequest request_; 88 ReportRequest request_;
94 std::string app_id_; 89 std::string app_id_;
95 }; 90 };
96 91
97 class CopresenceApiUnittest : public ExtensionApiUnittest { 92 class CopresenceApiUnittest : public ExtensionApiUnittest {
98 public: 93 public:
99 CopresenceApiUnittest() {} 94 CopresenceApiUnittest() {}
100 ~CopresenceApiUnittest() override {} 95 ~CopresenceApiUnittest() override {}
101 96
102 void SetUp() override { 97 void SetUp() override {
103 ExtensionApiUnittest::SetUp(); 98 ExtensionApiUnittest::SetUp();
104 99
105 CopresenceService* service = 100 CopresenceService* service =
106 CopresenceService::GetFactoryInstance()->Get(profile()); 101 CopresenceService::GetFactoryInstance()->Get(profile());
107 copresence_manager_ = new FakeCopresenceManager(service); 102 copresence_manager_ = new MockCopresenceManager(service);
108 service->set_manager_for_testing( 103 service->set_manager_for_testing(
109 make_scoped_ptr<CopresenceManager>(copresence_manager_)); 104 make_scoped_ptr<CopresenceManager>(copresence_manager_));
110 } 105 }
111 106
112 // Takes ownership of the operation_list. 107 // Takes ownership of the operation_list.
113 bool ExecuteOperations(ListValue* operation_list) { 108 bool ExecuteOperations(ListValue* operation_list) {
114 scoped_ptr<ListValue> args_list(new ListValue); 109 scoped_ptr<ListValue> args_list(new ListValue);
115 args_list->Append(operation_list); 110 args_list->Append(operation_list);
116 111
117 scoped_refptr<UIThreadExtensionFunction> function = 112 scoped_refptr<UIThreadExtensionFunction> function =
(...skipping 14 matching lines...) Expand all
132 127
133 const ReportRequest& request_sent() const { 128 const ReportRequest& request_sent() const {
134 return copresence_manager_->request_; 129 return copresence_manager_->request_;
135 } 130 }
136 131
137 const std::string& app_id_sent() const { 132 const std::string& app_id_sent() const {
138 return copresence_manager_->app_id_; 133 return copresence_manager_->app_id_;
139 } 134 }
140 135
141 void clear_app_id() { 136 void clear_app_id() {
142 copresence_manager_->app_id_.clear(); 137 copresence_manager_->app_id_ = "";
143 } 138 }
144 139
145 CopresenceDelegate* delegate() { 140 CopresenceDelegate* delegate() {
146 return copresence_manager_->delegate_; 141 return copresence_manager_->delegate_;
147 } 142 }
148 143
149 protected: 144 protected:
150 FakeCopresenceManager* copresence_manager_; 145 MockCopresenceManager* copresence_manager_;
151 }; 146 };
152 147
153 TEST_F(CopresenceApiUnittest, Publish) { 148 TEST_F(CopresenceApiUnittest, Publish) {
154 scoped_ptr<PublishOperation> publish(CreatePublish("pub")); 149 scoped_ptr<PublishOperation> publish(CreatePublish("pub"));
155 publish->strategies.reset(new Strategy); 150 publish->strategies.reset(new Strategy);
156 publish->strategies->only_broadcast.reset(new bool(true)); // Default 151 publish->strategies->only_broadcast.reset(new bool(true)); // Default
157 152
158 scoped_ptr<Operation> operation(new Operation); 153 scoped_ptr<Operation> operation(new Operation);
159 operation->publish = publish.Pass(); 154 operation->publish = publish.Pass();
160 155
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 scoped_ptr<Operation> multi_operation(new Operation); 282 scoped_ptr<Operation> multi_operation(new Operation);
288 multi_operation->publish.reset(CreatePublish("pub")); 283 multi_operation->publish.reset(CreatePublish("pub"));
289 multi_operation->subscribe.reset(CreateSubscribe("sub")); 284 multi_operation->subscribe.reset(CreateSubscribe("sub"));
290 285
291 EXPECT_FALSE(ExecuteOperation(multi_operation.Pass())); 286 EXPECT_FALSE(ExecuteOperation(multi_operation.Pass()));
292 } 287 }
293 288
294 } // namespace extensions 289 } // namespace extensions
295 290
296 // TODO(ckehoe): add tests for auth tokens and api key functionality 291 // TODO(ckehoe): add tests for auth tokens and api key functionality
OLDNEW
« no previous file with comments | « no previous file | components/components_tests.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698