Index: components/copresence/rpc/rpc_handler_unittest.cc |
diff --git a/components/copresence/rpc/rpc_handler_unittest.cc b/components/copresence/rpc/rpc_handler_unittest.cc |
index ced8e3c7bfe8a83bea46fbef9ae1dd6143a1d5e0..bcdace5254d61b84b0254c476ab1167382b18914 100644 |
--- a/components/copresence/rpc/rpc_handler_unittest.cc |
+++ b/components/copresence/rpc/rpc_handler_unittest.cc |
@@ -19,6 +19,7 @@ |
#include "testing/gtest/include/gtest/gtest.h" |
using google::protobuf::MessageLite; |
+using google::protobuf::RepeatedPtrField; |
namespace copresence { |
@@ -101,15 +102,26 @@ class RpcHandlerTest : public testing::Test, public CopresenceClientDelegate { |
status_ = status; |
} |
+ inline const ReportRequest* GetReportSent() { |
+ return static_cast<ReportRequest*>(request_proto_.get()); |
+ } |
+ |
// TODO(ckehoe): Fix this on Windows. See rpc_handler.cc. |
#ifndef OS_WIN |
const TokenTechnology& GetTokenTechnologyFromReport() { |
- ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); |
- return report->update_signals_request().state().capabilities() |
+ return GetReportSent()->update_signals_request().state().capabilities() |
.token_technology(0); |
} |
#endif |
+ const RepeatedPtrField<PublishedMessage>& GetMessagesPublished() { |
+ return GetReportSent()->manage_messages_request().message_to_publish(); |
+ } |
+ |
+ const RepeatedPtrField<Subscription>& GetSubscriptionsSent() { |
+ return GetReportSent()->manage_subscriptions_request().subscription(); |
+ } |
+ |
void SetDeviceId(const std::string& device_id) { |
rpc_handler_.device_id_ = device_id; |
} |
@@ -235,6 +247,39 @@ TEST_F(RpcHandlerTest, GetDeviceCapabilities) { |
} |
#endif |
+TEST_F(RpcHandlerTest, AllowOptedOutMessages) { |
+ // Request with no filter specified. |
+ scoped_ptr<ReportRequest> report(new ReportRequest); |
+ report->mutable_manage_messages_request()->add_message_to_publish() |
+ ->set_id("message"); |
+ report->mutable_manage_subscriptions_request()->add_subscription() |
+ ->set_id("subscription"); |
+ rpc_handler_.SendReportRequest(report.Pass()); |
+ const OptInStateFilter& filter = |
+ GetMessagesPublished().Get(0).opt_in_state_filter(); |
+ ASSERT_EQ(2, filter.allowed_opt_in_state_size()); |
+ EXPECT_EQ(OPTED_IN, filter.allowed_opt_in_state(0)); |
+ EXPECT_EQ(OPTED_OUT, filter.allowed_opt_in_state(1)); |
+ EXPECT_EQ(2, GetSubscriptionsSent().Get(0).opt_in_state_filter() |
+ .allowed_opt_in_state_size()); |
+ |
+ // Request with filters already specified. |
+ report.reset(new ReportRequest); |
+ report->mutable_manage_messages_request()->add_message_to_publish() |
+ ->mutable_opt_in_state_filter()->add_allowed_opt_in_state(OPTED_IN); |
+ report->mutable_manage_subscriptions_request()->add_subscription() |
+ ->mutable_opt_in_state_filter()->add_allowed_opt_in_state(OPTED_OUT); |
+ rpc_handler_.SendReportRequest(report.Pass()); |
+ const OptInStateFilter& publish_filter = |
+ GetMessagesPublished().Get(0).opt_in_state_filter(); |
+ ASSERT_EQ(1, publish_filter.allowed_opt_in_state_size()); |
+ EXPECT_EQ(OPTED_IN, publish_filter.allowed_opt_in_state(0)); |
+ const OptInStateFilter& subscription_filter = |
+ GetSubscriptionsSent().Get(0).opt_in_state_filter(); |
+ ASSERT_EQ(1, subscription_filter.allowed_opt_in_state_size()); |
+ EXPECT_EQ(OPTED_OUT, subscription_filter.allowed_opt_in_state(0)); |
+} |
+ |
TEST_F(RpcHandlerTest, CreateRequestHeader) { |
SetDeviceId("CreateRequestHeader Device ID"); |
rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest), |