| 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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 report.reset(new ReportRequest); | 249 report.reset(new ReportRequest); |
| 250 AddMessageWithStrategy(report.get(), SCAN_ONLY); | 250 AddMessageWithStrategy(report.get(), SCAN_ONLY); |
| 251 AddSubscriptionWithStrategy(report.get(), BROADCAST_AND_SCAN); | 251 AddSubscriptionWithStrategy(report.get(), BROADCAST_AND_SCAN); |
| 252 rpc_handler_.SendReportRequest(report.Pass()); | 252 rpc_handler_.SendReportRequest(report.Pass()); |
| 253 token_technology = &GetTokenTechnologyFromReport(); | 253 token_technology = &GetTokenTechnologyFromReport(); |
| 254 EXPECT_EQ(TRANSMIT, token_technology->instruction_type(0)); | 254 EXPECT_EQ(TRANSMIT, token_technology->instruction_type(0)); |
| 255 EXPECT_EQ(RECEIVE, token_technology->instruction_type(1)); | 255 EXPECT_EQ(RECEIVE, token_technology->instruction_type(1)); |
| 256 } | 256 } |
| 257 #endif | 257 #endif |
| 258 | 258 |
| 259 TEST_F(RpcHandlerTest, AllowOptedOutMessages) { | |
| 260 // Request with no filter specified. | |
| 261 scoped_ptr<ReportRequest> report(new ReportRequest); | |
| 262 report->mutable_manage_messages_request()->add_message_to_publish() | |
| 263 ->set_id("message"); | |
| 264 report->mutable_manage_subscriptions_request()->add_subscription() | |
| 265 ->set_id("subscription"); | |
| 266 rpc_handler_.SendReportRequest(report.Pass()); | |
| 267 const OptInStateFilter& filter = | |
| 268 GetMessagesPublished().Get(0).opt_in_state_filter(); | |
| 269 ASSERT_EQ(2, filter.allowed_opt_in_state_size()); | |
| 270 EXPECT_EQ(OPTED_IN, filter.allowed_opt_in_state(0)); | |
| 271 EXPECT_EQ(OPTED_OUT, filter.allowed_opt_in_state(1)); | |
| 272 EXPECT_EQ(2, GetSubscriptionsSent().Get(0).opt_in_state_filter() | |
| 273 .allowed_opt_in_state_size()); | |
| 274 | |
| 275 // Request with filters already specified. | |
| 276 report.reset(new ReportRequest); | |
| 277 report->mutable_manage_messages_request()->add_message_to_publish() | |
| 278 ->mutable_opt_in_state_filter()->add_allowed_opt_in_state(OPTED_IN); | |
| 279 report->mutable_manage_subscriptions_request()->add_subscription() | |
| 280 ->mutable_opt_in_state_filter()->add_allowed_opt_in_state(OPTED_OUT); | |
| 281 rpc_handler_.SendReportRequest(report.Pass()); | |
| 282 const OptInStateFilter& publish_filter = | |
| 283 GetMessagesPublished().Get(0).opt_in_state_filter(); | |
| 284 ASSERT_EQ(1, publish_filter.allowed_opt_in_state_size()); | |
| 285 EXPECT_EQ(OPTED_IN, publish_filter.allowed_opt_in_state(0)); | |
| 286 const OptInStateFilter& subscription_filter = | |
| 287 GetSubscriptionsSent().Get(0).opt_in_state_filter(); | |
| 288 ASSERT_EQ(1, subscription_filter.allowed_opt_in_state_size()); | |
| 289 EXPECT_EQ(OPTED_OUT, subscription_filter.allowed_opt_in_state(0)); | |
| 290 } | |
| 291 | |
| 292 TEST_F(RpcHandlerTest, CreateRequestHeader) { | 259 TEST_F(RpcHandlerTest, CreateRequestHeader) { |
| 293 SetDeviceId("CreateRequestHeader Device ID"); | 260 SetDeviceId("CreateRequestHeader Device ID"); |
| 294 rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest), | 261 rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest), |
| 295 "CreateRequestHeader App ID", | 262 "CreateRequestHeader App ID", |
| 296 StatusCallback()); | 263 StatusCallback()); |
| 297 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_); | 264 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_); |
| 298 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); | 265 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); |
| 299 EXPECT_EQ(kChromeVersion, | 266 EXPECT_EQ(kChromeVersion, |
| 300 report->header().framework_version().version_name()); | 267 report->header().framework_version().version_name()); |
| 301 EXPECT_EQ("CreateRequestHeader App ID", | 268 EXPECT_EQ("CreateRequestHeader App ID", |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 messages_by_subscription_["Subscription 2"][1].payload()); | 345 messages_by_subscription_["Subscription 2"][1].payload()); |
| 379 | 346 |
| 380 ASSERT_EQ(2U, directive_handler->added_directives().size()); | 347 ASSERT_EQ(2U, directive_handler->added_directives().size()); |
| 381 EXPECT_EQ("Subscription 1", | 348 EXPECT_EQ("Subscription 1", |
| 382 directive_handler->added_directives()[0].subscription_id()); | 349 directive_handler->added_directives()[0].subscription_id()); |
| 383 EXPECT_EQ("Subscription 2", | 350 EXPECT_EQ("Subscription 2", |
| 384 directive_handler->added_directives()[1].subscription_id()); | 351 directive_handler->added_directives()[1].subscription_id()); |
| 385 } | 352 } |
| 386 | 353 |
| 387 } // namespace copresence | 354 } // namespace copresence |
| OLD | NEW |