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

Side by Side Diff: components/copresence/rpc/rpc_handler_unittest.cc

Issue 459903006: Setting OptInStateFilter for publishes and subscribes (b/16324352) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mem
Patch Set: Merging to head Created 6 years, 4 months 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
« no previous file with comments | « components/copresence/rpc/rpc_handler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "components/copresence/handlers/directive_handler.h" 14 #include "components/copresence/handlers/directive_handler.h"
15 #include "components/copresence/proto/data.pb.h" 15 #include "components/copresence/proto/data.pb.h"
16 #include "components/copresence/proto/enums.pb.h" 16 #include "components/copresence/proto/enums.pb.h"
17 #include "components/copresence/proto/rpcs.pb.h" 17 #include "components/copresence/proto/rpcs.pb.h"
18 #include "net/http/http_status_code.h" 18 #include "net/http/http_status_code.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using google::protobuf::MessageLite; 21 using google::protobuf::MessageLite;
22 using google::protobuf::RepeatedPtrField;
22 23
23 namespace copresence { 24 namespace copresence {
24 25
25 namespace { 26 namespace {
26 27
27 void AddMessageWithStrategy(ReportRequest* report, 28 void AddMessageWithStrategy(ReportRequest* report,
28 BroadcastScanConfiguration strategy) { 29 BroadcastScanConfiguration strategy) {
29 report->mutable_manage_messages_request()->add_message_to_publish() 30 report->mutable_manage_messages_request()->add_message_to_publish()
30 ->mutable_token_exchange_strategy()->set_broadcast_scan_configuration( 31 ->mutable_token_exchange_strategy()->set_broadcast_scan_configuration(
31 strategy); 32 strategy);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 scoped_ptr<MessageLite> request_proto, 95 scoped_ptr<MessageLite> request_proto,
95 const RpcHandler::PostCleanupCallback& response_callback) { 96 const RpcHandler::PostCleanupCallback& response_callback) {
96 rpc_name_ = rpc_name; 97 rpc_name_ = rpc_name;
97 request_proto_ = request_proto.Pass(); 98 request_proto_ = request_proto.Pass();
98 } 99 }
99 100
100 void CaptureStatus(CopresenceStatus status) { 101 void CaptureStatus(CopresenceStatus status) {
101 status_ = status; 102 status_ = status;
102 } 103 }
103 104
105 inline const ReportRequest* GetReportSent() {
106 return static_cast<ReportRequest*>(request_proto_.get());
107 }
108
104 // TODO(ckehoe): Fix this on Windows. See rpc_handler.cc. 109 // TODO(ckehoe): Fix this on Windows. See rpc_handler.cc.
105 #ifndef OS_WIN 110 #ifndef OS_WIN
106 const TokenTechnology& GetTokenTechnologyFromReport() { 111 const TokenTechnology& GetTokenTechnologyFromReport() {
107 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); 112 return GetReportSent()->update_signals_request().state().capabilities()
108 return report->update_signals_request().state().capabilities()
109 .token_technology(0); 113 .token_technology(0);
110 } 114 }
111 #endif 115 #endif
112 116
117 const RepeatedPtrField<PublishedMessage>& GetMessagesPublished() {
118 return GetReportSent()->manage_messages_request().message_to_publish();
119 }
120
121 const RepeatedPtrField<Subscription>& GetSubscriptionsSent() {
122 return GetReportSent()->manage_subscriptions_request().subscription();
123 }
124
113 void SetDeviceId(const std::string& device_id) { 125 void SetDeviceId(const std::string& device_id) {
114 rpc_handler_.device_id_ = device_id; 126 rpc_handler_.device_id_ = device_id;
115 } 127 }
116 128
117 const std::string& GetDeviceId() { 129 const std::string& GetDeviceId() {
118 return rpc_handler_.device_id_; 130 return rpc_handler_.device_id_;
119 } 131 }
120 132
121 void AddInvalidToken(const std::string& token) { 133 void AddInvalidToken(const std::string& token) {
122 rpc_handler_.invalid_audio_token_cache_.Add(token, true); 134 rpc_handler_.invalid_audio_token_cache_.Add(token, true);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 report.reset(new ReportRequest); 240 report.reset(new ReportRequest);
229 AddMessageWithStrategy(report.get(), SCAN_ONLY); 241 AddMessageWithStrategy(report.get(), SCAN_ONLY);
230 AddSubscriptionWithStrategy(report.get(), BROADCAST_AND_SCAN); 242 AddSubscriptionWithStrategy(report.get(), BROADCAST_AND_SCAN);
231 rpc_handler_.SendReportRequest(report.Pass()); 243 rpc_handler_.SendReportRequest(report.Pass());
232 token_technology = &GetTokenTechnologyFromReport(); 244 token_technology = &GetTokenTechnologyFromReport();
233 EXPECT_EQ(TRANSMIT, token_technology->instruction_type(0)); 245 EXPECT_EQ(TRANSMIT, token_technology->instruction_type(0));
234 EXPECT_EQ(RECEIVE, token_technology->instruction_type(1)); 246 EXPECT_EQ(RECEIVE, token_technology->instruction_type(1));
235 } 247 }
236 #endif 248 #endif
237 249
250 TEST_F(RpcHandlerTest, AllowOptedOutMessages) {
251 // Request with no filter specified.
252 scoped_ptr<ReportRequest> report(new ReportRequest);
253 report->mutable_manage_messages_request()->add_message_to_publish()
254 ->set_id("message");
255 report->mutable_manage_subscriptions_request()->add_subscription()
256 ->set_id("subscription");
257 rpc_handler_.SendReportRequest(report.Pass());
258 const OptInStateFilter& filter =
259 GetMessagesPublished().Get(0).opt_in_state_filter();
260 ASSERT_EQ(2, filter.allowed_opt_in_state_size());
261 EXPECT_EQ(OPTED_IN, filter.allowed_opt_in_state(0));
262 EXPECT_EQ(OPTED_OUT, filter.allowed_opt_in_state(1));
263 EXPECT_EQ(2, GetSubscriptionsSent().Get(0).opt_in_state_filter()
264 .allowed_opt_in_state_size());
265
266 // Request with filters already specified.
267 report.reset(new ReportRequest);
268 report->mutable_manage_messages_request()->add_message_to_publish()
269 ->mutable_opt_in_state_filter()->add_allowed_opt_in_state(OPTED_IN);
270 report->mutable_manage_subscriptions_request()->add_subscription()
271 ->mutable_opt_in_state_filter()->add_allowed_opt_in_state(OPTED_OUT);
272 rpc_handler_.SendReportRequest(report.Pass());
273 const OptInStateFilter& publish_filter =
274 GetMessagesPublished().Get(0).opt_in_state_filter();
275 ASSERT_EQ(1, publish_filter.allowed_opt_in_state_size());
276 EXPECT_EQ(OPTED_IN, publish_filter.allowed_opt_in_state(0));
277 const OptInStateFilter& subscription_filter =
278 GetSubscriptionsSent().Get(0).opt_in_state_filter();
279 ASSERT_EQ(1, subscription_filter.allowed_opt_in_state_size());
280 EXPECT_EQ(OPTED_OUT, subscription_filter.allowed_opt_in_state(0));
281 }
282
238 TEST_F(RpcHandlerTest, CreateRequestHeader) { 283 TEST_F(RpcHandlerTest, CreateRequestHeader) {
239 SetDeviceId("CreateRequestHeader Device ID"); 284 SetDeviceId("CreateRequestHeader Device ID");
240 rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest), 285 rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest),
241 "CreateRequestHeader App ID", 286 "CreateRequestHeader App ID",
242 StatusCallback()); 287 StatusCallback());
243 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_); 288 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_);
244 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); 289 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get());
245 EXPECT_TRUE(report->header().has_framework_version()); 290 EXPECT_TRUE(report->header().has_framework_version());
246 EXPECT_EQ("CreateRequestHeader App ID", 291 EXPECT_EQ("CreateRequestHeader App ID",
247 report->header().client_version().client()); 292 report->header().client_version().client());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 messages_by_subscription_["Subscription 2"][1].payload()); 370 messages_by_subscription_["Subscription 2"][1].payload());
326 371
327 ASSERT_EQ(2U, directive_handler->added_directives().size()); 372 ASSERT_EQ(2U, directive_handler->added_directives().size());
328 EXPECT_EQ("Subscription 1", 373 EXPECT_EQ("Subscription 1",
329 directive_handler->added_directives()[0].subscription_id()); 374 directive_handler->added_directives()[0].subscription_id());
330 EXPECT_EQ("Subscription 2", 375 EXPECT_EQ("Subscription 2",
331 directive_handler->added_directives()[1].subscription_id()); 376 directive_handler->added_directives()[1].subscription_id());
332 } 377 }
333 378
334 } // namespace copresence 379 } // namespace copresence
OLDNEW
« no previous file with comments | « components/copresence/rpc/rpc_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698