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

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

Issue 764673003: Adding CopresenceState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing overzealous DCHECK Created 6 years 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
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/memory/scoped_ptr.h"
6 #include "base/values.h" 7 #include "base/values.h"
7 #include "chrome/browser/extensions/api/copresence/copresence_api.h" 8 #include "chrome/browser/extensions/api/copresence/copresence_api.h"
8 #include "chrome/browser/extensions/extension_api_unittest.h" 9 #include "chrome/browser/extensions/extension_api_unittest.h"
9 #include "chrome/browser/extensions/extension_function_test_utils.h" 10 #include "chrome/browser/extensions/extension_function_test_utils.h"
11 #include "components/copresence/copresence_state_impl.h"
10 #include "components/copresence/proto/data.pb.h" 12 #include "components/copresence/proto/data.pb.h"
11 #include "components/copresence/proto/rpcs.pb.h" 13 #include "components/copresence/proto/rpcs.pb.h"
12 #include "components/copresence/public/copresence_manager.h" 14 #include "components/copresence/public/copresence_manager.h"
13 15
14 using base::ListValue; 16 using base::ListValue;
15 using copresence::AUDIO_CONFIGURATION_AUDIBLE; 17 using copresence::AUDIO_CONFIGURATION_AUDIBLE;
16 using copresence::AUDIO_CONFIGURATION_UNKNOWN; 18 using copresence::AUDIO_CONFIGURATION_UNKNOWN;
17 using copresence::BROADCAST_ONLY; 19 using copresence::BROADCAST_ONLY;
18 using copresence::CopresenceDelegate; 20 using copresence::CopresenceDelegate;
19 using copresence::CopresenceManager; 21 using copresence::CopresenceManager;
22 using copresence::CopresenceState;
23 using copresence::CopresenceStateImpl;
20 using copresence::FAIL; 24 using copresence::FAIL;
21 using copresence::PublishedMessage; 25 using copresence::PublishedMessage;
22 using copresence::ReportRequest; 26 using copresence::ReportRequest;
23 using copresence::SCAN_ONLY; 27 using copresence::SCAN_ONLY;
24 using copresence::Subscription; 28 using copresence::Subscription;
25 using google::protobuf::RepeatedPtrField; 29 using google::protobuf::RepeatedPtrField;
26 30
27 namespace test_utils = extension_function_test_utils; 31 namespace test_utils = extension_function_test_utils;
28 32
29 namespace extensions { 33 namespace extensions {
(...skipping 30 matching lines...) Expand all
60 64
61 template <typename T> 65 template <typename T>
62 bool GetOnly(const RepeatedPtrField<T>& things, T* out) { 66 bool GetOnly(const RepeatedPtrField<T>& things, T* out) {
63 if (things.size() != 1) 67 if (things.size() != 1)
64 return false; 68 return false;
65 69
66 *out = things.Get(0); 70 *out = things.Get(0);
67 return true; 71 return true;
68 } 72 }
69 73
70 class MockCopresenceManager : public CopresenceManager { 74 class FakeCopresenceManager : public CopresenceManager {
71 public: 75 public:
72 explicit MockCopresenceManager(CopresenceDelegate* delegate) 76 explicit FakeCopresenceManager(CopresenceDelegate* delegate)
73 : delegate_(delegate) {} 77 : delegate_(delegate),
74 ~MockCopresenceManager() override {} 78 // TODO(ckehoe): Use a StubCopresenceState here.
79 state_(new CopresenceStateImpl) {}
rkc 2014/12/18 18:12:09 Why aren't we using a stub here at the moment?
Charlie 2014/12/19 03:53:33 Because Andrew doesn't want me to spend a lot of t
Charlie 2014/12/19 07:06:44 Nevermind, I realized we actually don't need this
80 ~FakeCopresenceManager() override {}
75 81
82 // CopresenceManager overrides.
83 CopresenceState* state() override { return state_.get(); }
76 void ExecuteReportRequest( 84 void ExecuteReportRequest(
77 const ReportRequest& request, 85 const ReportRequest& request,
78 const std::string& app_id, 86 const std::string& app_id,
79 const std::string& /* auth_token */, 87 const std::string& /* auth_token */,
80 const copresence::StatusCallback& status_callback) override { 88 const copresence::StatusCallback& status_callback) override {
81 request_ = request; 89 request_ = request;
82 app_id_ = app_id; 90 app_id_ = app_id;
83 status_callback.Run(copresence::SUCCESS); 91 status_callback.Run(copresence::SUCCESS);
84 } 92 }
85 93
86 CopresenceDelegate* delegate_; 94 CopresenceDelegate* delegate_;
95 scoped_ptr<CopresenceStateImpl> state_;
87 96
88 ReportRequest request_; 97 ReportRequest request_;
89 std::string app_id_; 98 std::string app_id_;
90 }; 99 };
91 100
92 class CopresenceApiUnittest : public ExtensionApiUnittest { 101 class CopresenceApiUnittest : public ExtensionApiUnittest {
93 public: 102 public:
94 CopresenceApiUnittest() {} 103 CopresenceApiUnittest() {}
95 ~CopresenceApiUnittest() override {} 104 ~CopresenceApiUnittest() override {}
96 105
97 void SetUp() override { 106 void SetUp() override {
98 ExtensionApiUnittest::SetUp(); 107 ExtensionApiUnittest::SetUp();
99 108
100 CopresenceService* service = 109 CopresenceService* service =
101 CopresenceService::GetFactoryInstance()->Get(profile()); 110 CopresenceService::GetFactoryInstance()->Get(profile());
102 copresence_manager_ = new MockCopresenceManager(service); 111 copresence_manager_ = new FakeCopresenceManager(service);
103 service->set_manager_for_testing( 112 service->set_manager_for_testing(
104 make_scoped_ptr<CopresenceManager>(copresence_manager_)); 113 make_scoped_ptr<CopresenceManager>(copresence_manager_));
105 } 114 }
106 115
107 // Takes ownership of the operation_list. 116 // Takes ownership of the operation_list.
108 bool ExecuteOperations(ListValue* operation_list) { 117 bool ExecuteOperations(ListValue* operation_list) {
109 scoped_ptr<ListValue> args_list(new ListValue); 118 scoped_ptr<ListValue> args_list(new ListValue);
110 args_list->Append(operation_list); 119 args_list->Append(operation_list);
111 120
112 scoped_refptr<UIThreadExtensionFunction> function = 121 scoped_refptr<UIThreadExtensionFunction> function =
(...skipping 14 matching lines...) Expand all
127 136
128 const ReportRequest& request_sent() const { 137 const ReportRequest& request_sent() const {
129 return copresence_manager_->request_; 138 return copresence_manager_->request_;
130 } 139 }
131 140
132 const std::string& app_id_sent() const { 141 const std::string& app_id_sent() const {
133 return copresence_manager_->app_id_; 142 return copresence_manager_->app_id_;
134 } 143 }
135 144
136 void clear_app_id() { 145 void clear_app_id() {
137 copresence_manager_->app_id_ = ""; 146 copresence_manager_->app_id_.clear();
138 } 147 }
139 148
140 CopresenceDelegate* delegate() { 149 CopresenceDelegate* delegate() {
141 return copresence_manager_->delegate_; 150 return copresence_manager_->delegate_;
142 } 151 }
143 152
144 protected: 153 protected:
145 MockCopresenceManager* copresence_manager_; 154 FakeCopresenceManager* copresence_manager_;
146 }; 155 };
147 156
148 TEST_F(CopresenceApiUnittest, Publish) { 157 TEST_F(CopresenceApiUnittest, Publish) {
149 scoped_ptr<PublishOperation> publish(CreatePublish("pub")); 158 scoped_ptr<PublishOperation> publish(CreatePublish("pub"));
150 publish->strategies.reset(new Strategy); 159 publish->strategies.reset(new Strategy);
151 publish->strategies->only_broadcast.reset(new bool(true)); // Default 160 publish->strategies->only_broadcast.reset(new bool(true)); // Default
152 161
153 scoped_ptr<Operation> operation(new Operation); 162 scoped_ptr<Operation> operation(new Operation);
154 operation->publish = publish.Pass(); 163 operation->publish = publish.Pass();
155 164
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 scoped_ptr<Operation> multi_operation(new Operation); 291 scoped_ptr<Operation> multi_operation(new Operation);
283 multi_operation->publish.reset(CreatePublish("pub")); 292 multi_operation->publish.reset(CreatePublish("pub"));
284 multi_operation->subscribe.reset(CreateSubscribe("sub")); 293 multi_operation->subscribe.reset(CreateSubscribe("sub"));
285 294
286 EXPECT_FALSE(ExecuteOperation(multi_operation.Pass())); 295 EXPECT_FALSE(ExecuteOperation(multi_operation.Pass()));
287 } 296 }
288 297
289 } // namespace extensions 298 } // namespace extensions
290 299
291 // TODO(ckehoe): add tests for auth tokens and api key functionality 300 // TODO(ckehoe): add tests for auth tokens and api key functionality
OLDNEW
« no previous file with comments | « no previous file | components/copresence.gypi » ('j') | components/copresence/copresence_state_impl.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698