OLD | NEW |
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 "components/copresence/rpc/rpc_handler.h" | 5 #include "components/copresence/rpc/rpc_handler.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 private: | 76 private: |
77 std::vector<Directive> added_directives_; | 77 std::vector<Directive> added_directives_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); | 79 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); |
80 }; | 80 }; |
81 | 81 |
82 } // namespace | 82 } // namespace |
83 | 83 |
84 class RpcHandlerTest : public testing::Test, public CopresenceClientDelegate { | 84 class RpcHandlerTest : public testing::Test, public CopresenceClientDelegate { |
85 public: | 85 public: |
86 RpcHandlerTest() : rpc_handler_(this), status_(SUCCESS) { | 86 RpcHandlerTest() : rpc_handler_(this), status_(SUCCESS), api_key_("API key") { |
87 rpc_handler_.server_post_callback_ = | 87 rpc_handler_.server_post_callback_ = |
88 base::Bind(&RpcHandlerTest::CaptureHttpPost, base::Unretained(this)); | 88 base::Bind(&RpcHandlerTest::CaptureHttpPost, base::Unretained(this)); |
89 rpc_handler_.device_id_ = "Device ID"; | 89 rpc_handler_.device_id_ = "Device ID"; |
| 90 |
| 91 fingerprint_.set_platform_version("Version String"); |
90 } | 92 } |
91 | 93 |
92 void CaptureHttpPost( | 94 void CaptureHttpPost( |
93 net::URLRequestContextGetter* url_context_getter, | 95 net::URLRequestContextGetter* url_context_getter, |
94 const std::string& rpc_name, | 96 const std::string& rpc_name, |
95 scoped_ptr<MessageLite> request_proto, | 97 scoped_ptr<MessageLite> request_proto, |
96 const RpcHandler::PostCleanupCallback& response_callback) { | 98 const RpcHandler::PostCleanupCallback& response_callback) { |
97 rpc_name_ = rpc_name; | 99 rpc_name_ = rpc_name; |
98 request_proto_ = request_proto.Pass(); | 100 request_proto_ = request_proto.Pass(); |
99 } | 101 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 const std::string& subscription_id, | 162 const std::string& subscription_id, |
161 const std::vector<Message>& messages) OVERRIDE { | 163 const std::vector<Message>& messages) OVERRIDE { |
162 // app_id is unused for now, pending a server fix. | 164 // app_id is unused for now, pending a server fix. |
163 messages_by_subscription_[subscription_id] = messages; | 165 messages_by_subscription_[subscription_id] = messages; |
164 } | 166 } |
165 | 167 |
166 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE { | 168 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE { |
167 return NULL; | 169 return NULL; |
168 } | 170 } |
169 | 171 |
170 virtual const std::string GetPlatformVersionString() const OVERRIDE { | 172 virtual const DeviceFingerprint& GetDeviceFingerprint() const OVERRIDE { |
171 return "Version String"; | 173 return fingerprint_; |
| 174 } |
| 175 |
| 176 virtual const std::string& GetAPIKey() const OVERRIDE { |
| 177 return api_key_; |
172 } | 178 } |
173 | 179 |
174 virtual WhispernetClient* GetWhispernetClient() OVERRIDE { | 180 virtual WhispernetClient* GetWhispernetClient() OVERRIDE { |
175 return NULL; | 181 return NULL; |
176 } | 182 } |
177 | 183 |
178 protected: | 184 protected: |
179 // For rpc_handler_.invalid_audio_token_cache_ | 185 // For rpc_handler_.invalid_audio_token_cache_ |
180 base::MessageLoop message_loop_; | 186 base::MessageLoop message_loop_; |
181 | 187 |
182 RpcHandler rpc_handler_; | 188 RpcHandler rpc_handler_; |
| 189 CopresenceStatus status_; |
| 190 std::string api_key_; |
| 191 DeviceFingerprint fingerprint_; |
183 | 192 |
184 std::string rpc_name_; | 193 std::string rpc_name_; |
185 scoped_ptr<MessageLite> request_proto_; | 194 scoped_ptr<MessageLite> request_proto_; |
186 CopresenceStatus status_; | |
187 std::map<std::string, std::vector<Message> > messages_by_subscription_; | 195 std::map<std::string, std::vector<Message> > messages_by_subscription_; |
188 }; | 196 }; |
189 | 197 |
190 TEST_F(RpcHandlerTest, Initialize) { | 198 TEST_F(RpcHandlerTest, Initialize) { |
191 SetDeviceId(""); | 199 SetDeviceId(""); |
192 rpc_handler_.Initialize(RpcHandler::SuccessCallback()); | 200 rpc_handler_.Initialize(RpcHandler::SuccessCallback()); |
193 RegisterDeviceRequest* registration = | 201 RegisterDeviceRequest* registration = |
194 static_cast<RegisterDeviceRequest*>(request_proto_.get()); | 202 static_cast<RegisterDeviceRequest*>(request_proto_.get()); |
195 Identity identity = registration->device_identifiers().registrant(); | 203 Identity identity = registration->device_identifiers().registrant(); |
196 EXPECT_EQ(CHROME, identity.type()); | 204 EXPECT_EQ(CHROME, identity.type()); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 messages_by_subscription_["Subscription 2"][1].payload()); | 378 messages_by_subscription_["Subscription 2"][1].payload()); |
371 | 379 |
372 ASSERT_EQ(2U, directive_handler->added_directives().size()); | 380 ASSERT_EQ(2U, directive_handler->added_directives().size()); |
373 EXPECT_EQ("Subscription 1", | 381 EXPECT_EQ("Subscription 1", |
374 directive_handler->added_directives()[0].subscription_id()); | 382 directive_handler->added_directives()[0].subscription_id()); |
375 EXPECT_EQ("Subscription 2", | 383 EXPECT_EQ("Subscription 2", |
376 directive_handler->added_directives()[1].subscription_id()); | 384 directive_handler->added_directives()[1].subscription_id()); |
377 } | 385 } |
378 | 386 |
379 } // namespace copresence | 387 } // namespace copresence |
OLD | NEW |