Chromium Code Reviews| 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 13 matching lines...) Expand all Loading... | |
| 24 namespace copresence { | 24 namespace copresence { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kChromeVersion[] = "Chrome Version String"; | 28 const char kChromeVersion[] = "Chrome Version String"; |
| 29 | 29 |
| 30 void CreateSubscribedMessage(const std::vector<std::string>& subscription_ids, | 30 void CreateSubscribedMessage(const std::vector<std::string>& subscription_ids, |
| 31 const std::string& message_string, | 31 const std::string& message_string, |
| 32 SubscribedMessage* message_proto) { | 32 SubscribedMessage* message_proto) { |
| 33 message_proto->mutable_published_message()->set_payload(message_string); | 33 message_proto->mutable_published_message()->set_payload(message_string); |
| 34 for (std::vector<std::string>::const_iterator subscription_id = | 34 for (const std::string& subscription_id :subscription_ids) { |
|
rkc
2014/10/01 03:48:32
space after :
Charlie
2014/10/06 19:09:56
Done.
| |
| 35 subscription_ids.begin(); | 35 message_proto->add_subscription_id(subscription_id); |
| 36 subscription_id != subscription_ids.end(); | |
| 37 ++subscription_id) { | |
| 38 message_proto->add_subscription_id(*subscription_id); | |
| 39 } | 36 } |
| 40 } | 37 } |
| 41 | 38 |
| 42 // TODO(ckehoe): Make DirectiveHandler an interface. | 39 // TODO(ckehoe): Make DirectiveHandler an interface. |
| 43 class FakeDirectiveHandler : public DirectiveHandler { | 40 class FakeDirectiveHandler : public DirectiveHandler { |
| 44 public: | 41 public: |
| 45 FakeDirectiveHandler() {} | 42 FakeDirectiveHandler() {} |
| 46 virtual ~FakeDirectiveHandler() {} | 43 virtual ~FakeDirectiveHandler() {} |
| 47 | 44 |
| 48 const std::vector<Directive>& added_directives() const { | 45 const std::vector<Directive>& added_directives() const { |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 TEST_F(RpcHandlerTest, ReportTokens) { | 204 TEST_F(RpcHandlerTest, ReportTokens) { |
| 208 std::vector<AudioToken> test_tokens; | 205 std::vector<AudioToken> test_tokens; |
| 209 test_tokens.push_back(AudioToken("token 1", false)); | 206 test_tokens.push_back(AudioToken("token 1", false)); |
| 210 test_tokens.push_back(AudioToken("token 2", true)); | 207 test_tokens.push_back(AudioToken("token 2", true)); |
| 211 test_tokens.push_back(AudioToken("token 3", false)); | 208 test_tokens.push_back(AudioToken("token 3", false)); |
| 212 AddInvalidToken("token 2"); | 209 AddInvalidToken("token 2"); |
| 213 | 210 |
| 214 rpc_handler_.ReportTokens(test_tokens); | 211 rpc_handler_.ReportTokens(test_tokens); |
| 215 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_); | 212 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_); |
| 216 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); | 213 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); |
| 217 google::protobuf::RepeatedPtrField<TokenObservation> tokens_sent = | 214 RepeatedPtrField<TokenObservation> tokens_sent = |
| 218 report->update_signals_request().token_observation(); | 215 report->update_signals_request().token_observation(); |
| 219 ASSERT_EQ(2, tokens_sent.size()); | 216 ASSERT_EQ(2, tokens_sent.size()); |
| 220 EXPECT_EQ("token 1", tokens_sent.Get(0).token_id()); | 217 EXPECT_EQ("token 1", tokens_sent.Get(0).token_id()); |
| 221 EXPECT_EQ("token 3", tokens_sent.Get(1).token_id()); | 218 EXPECT_EQ("token 3", tokens_sent.Get(1).token_id()); |
| 222 } | 219 } |
| 223 | 220 |
| 224 TEST_F(RpcHandlerTest, ReportResponseHandler) { | 221 TEST_F(RpcHandlerTest, ReportResponseHandler) { |
| 225 // Fail on HTTP status != 200. | 222 // Fail on HTTP status != 200. |
| 226 ReportResponse empty_response; | 223 ReportResponse empty_response; |
| 227 empty_response.mutable_header()->mutable_status()->set_code(OK); | 224 empty_response.mutable_header()->mutable_status()->set_code(OK); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 messages_by_subscription_["Subscription 2"][1].payload()); | 273 messages_by_subscription_["Subscription 2"][1].payload()); |
| 277 | 274 |
| 278 ASSERT_EQ(2U, directive_handler->added_directives().size()); | 275 ASSERT_EQ(2U, directive_handler->added_directives().size()); |
| 279 EXPECT_EQ("Subscription 1", | 276 EXPECT_EQ("Subscription 1", |
| 280 directive_handler->added_directives()[0].subscription_id()); | 277 directive_handler->added_directives()[0].subscription_id()); |
| 281 EXPECT_EQ("Subscription 2", | 278 EXPECT_EQ("Subscription 2", |
| 282 directive_handler->added_directives()[1].subscription_id()); | 279 directive_handler->added_directives()[1].subscription_id()); |
| 283 } | 280 } |
| 284 | 281 |
| 285 } // namespace copresence | 282 } // namespace copresence |
| OLD | NEW |