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

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

Issue 469883002: Using API key specified from js (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding fingerprint test 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
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 using google::protobuf::RepeatedPtrField;
23 23
24 namespace copresence { 24 namespace copresence {
25 25
26 namespace { 26 namespace {
27 27
28 const char kChromeVersion[] = "Chrome Version String";
29
28 void AddMessageWithStrategy(ReportRequest* report, 30 void AddMessageWithStrategy(ReportRequest* report,
29 BroadcastScanConfiguration strategy) { 31 BroadcastScanConfiguration strategy) {
30 report->mutable_manage_messages_request()->add_message_to_publish() 32 report->mutable_manage_messages_request()->add_message_to_publish()
31 ->mutable_token_exchange_strategy()->set_broadcast_scan_configuration( 33 ->mutable_token_exchange_strategy()->set_broadcast_scan_configuration(
32 strategy); 34 strategy);
33 } 35 }
34 36
35 void AddSubscriptionWithStrategy(ReportRequest* report, 37 void AddSubscriptionWithStrategy(ReportRequest* report,
36 BroadcastScanConfiguration strategy) { 38 BroadcastScanConfiguration strategy) {
37 report->mutable_manage_subscriptions_request()->add_subscription() 39 report->mutable_manage_subscriptions_request()->add_subscription()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 private: 78 private:
77 std::vector<Directive> added_directives_; 79 std::vector<Directive> added_directives_;
78 80
79 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler); 81 DISALLOW_COPY_AND_ASSIGN(FakeDirectiveHandler);
80 }; 82 };
81 83
82 } // namespace 84 } // namespace
83 85
84 class RpcHandlerTest : public testing::Test, public CopresenceClientDelegate { 86 class RpcHandlerTest : public testing::Test, public CopresenceClientDelegate {
85 public: 87 public:
86 RpcHandlerTest() : rpc_handler_(this), status_(SUCCESS) { 88 RpcHandlerTest() : rpc_handler_(this), status_(SUCCESS), api_key_("API key") {
87 rpc_handler_.server_post_callback_ = 89 rpc_handler_.server_post_callback_ =
88 base::Bind(&RpcHandlerTest::CaptureHttpPost, base::Unretained(this)); 90 base::Bind(&RpcHandlerTest::CaptureHttpPost, base::Unretained(this));
89 rpc_handler_.device_id_ = "Device ID"; 91 rpc_handler_.device_id_ = "Device ID";
92
93 fingerprint_.set_platform_version(kChromeVersion);
90 } 94 }
91 95
92 void CaptureHttpPost( 96 void CaptureHttpPost(
93 net::URLRequestContextGetter* url_context_getter, 97 net::URLRequestContextGetter* url_context_getter,
94 const std::string& rpc_name, 98 const std::string& rpc_name,
95 scoped_ptr<MessageLite> request_proto, 99 scoped_ptr<MessageLite> request_proto,
96 const RpcHandler::PostCleanupCallback& response_callback) { 100 const RpcHandler::PostCleanupCallback& response_callback) {
97 rpc_name_ = rpc_name; 101 rpc_name_ = rpc_name;
98 request_proto_ = request_proto.Pass(); 102 request_proto_ = request_proto.Pass();
99 } 103 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const std::string& subscription_id, 164 const std::string& subscription_id,
161 const std::vector<Message>& messages) OVERRIDE { 165 const std::vector<Message>& messages) OVERRIDE {
162 // app_id is unused for now, pending a server fix. 166 // app_id is unused for now, pending a server fix.
163 messages_by_subscription_[subscription_id] = messages; 167 messages_by_subscription_[subscription_id] = messages;
164 } 168 }
165 169
166 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE { 170 virtual net::URLRequestContextGetter* GetRequestContext() const OVERRIDE {
167 return NULL; 171 return NULL;
168 } 172 }
169 173
170 virtual const std::string GetPlatformVersionString() const OVERRIDE { 174 virtual const DeviceFingerprint& GetDeviceFingerprint() const OVERRIDE {
171 return "Version String"; 175 return fingerprint_;
176 }
177
178 virtual const std::string& GetAPIKey() const OVERRIDE {
179 return api_key_;
172 } 180 }
173 181
174 virtual WhispernetClient* GetWhispernetClient() OVERRIDE { 182 virtual WhispernetClient* GetWhispernetClient() OVERRIDE {
175 return NULL; 183 return NULL;
176 } 184 }
177 185
178 protected: 186 protected:
179 // For rpc_handler_.invalid_audio_token_cache_ 187 // For rpc_handler_.invalid_audio_token_cache_
180 base::MessageLoop message_loop_; 188 base::MessageLoop message_loop_;
181 189
182 RpcHandler rpc_handler_; 190 RpcHandler rpc_handler_;
191 CopresenceStatus status_;
192 std::string api_key_;
193 DeviceFingerprint fingerprint_;
183 194
184 std::string rpc_name_; 195 std::string rpc_name_;
185 scoped_ptr<MessageLite> request_proto_; 196 scoped_ptr<MessageLite> request_proto_;
186 CopresenceStatus status_;
187 std::map<std::string, std::vector<Message> > messages_by_subscription_; 197 std::map<std::string, std::vector<Message> > messages_by_subscription_;
188 }; 198 };
189 199
190 TEST_F(RpcHandlerTest, Initialize) { 200 TEST_F(RpcHandlerTest, Initialize) {
191 SetDeviceId(""); 201 SetDeviceId("");
192 rpc_handler_.Initialize(RpcHandler::SuccessCallback()); 202 rpc_handler_.Initialize(RpcHandler::SuccessCallback());
193 RegisterDeviceRequest* registration = 203 RegisterDeviceRequest* registration =
194 static_cast<RegisterDeviceRequest*>(request_proto_.get()); 204 static_cast<RegisterDeviceRequest*>(request_proto_.get());
195 Identity identity = registration->device_identifiers().registrant(); 205 Identity identity = registration->device_identifiers().registrant();
196 EXPECT_EQ(CHROME, identity.type()); 206 EXPECT_EQ(CHROME, identity.type());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 EXPECT_EQ(OPTED_OUT, subscription_filter.allowed_opt_in_state(0)); 290 EXPECT_EQ(OPTED_OUT, subscription_filter.allowed_opt_in_state(0));
281 } 291 }
282 292
283 TEST_F(RpcHandlerTest, CreateRequestHeader) { 293 TEST_F(RpcHandlerTest, CreateRequestHeader) {
284 SetDeviceId("CreateRequestHeader Device ID"); 294 SetDeviceId("CreateRequestHeader Device ID");
285 rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest), 295 rpc_handler_.SendReportRequest(make_scoped_ptr(new ReportRequest),
286 "CreateRequestHeader App ID", 296 "CreateRequestHeader App ID",
287 StatusCallback()); 297 StatusCallback());
288 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_); 298 EXPECT_EQ(RpcHandler::kReportRequestRpcName, rpc_name_);
289 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get()); 299 ReportRequest* report = static_cast<ReportRequest*>(request_proto_.get());
290 EXPECT_TRUE(report->header().has_framework_version()); 300 EXPECT_EQ(kChromeVersion,
301 report->header().framework_version().version_name());
291 EXPECT_EQ("CreateRequestHeader App ID", 302 EXPECT_EQ("CreateRequestHeader App ID",
292 report->header().client_version().client()); 303 report->header().client_version().client());
293 EXPECT_EQ("CreateRequestHeader Device ID", 304 EXPECT_EQ("CreateRequestHeader Device ID",
294 report->header().registered_device_id()); 305 report->header().registered_device_id());
306 EXPECT_EQ(CHROME_PLATFORM_TYPE,
307 report->header().device_fingerprint().type());
295 } 308 }
296 309
297 // TODO(ckehoe): Renable these after https://codereview.chromium.org/453203002/ 310 // TODO(ckehoe): Renable these after https://codereview.chromium.org/453203002/
298 // lands. 311 // lands.
299 #define MAYBE_ReportTokens DISABLED_ReportTokens 312 #define MAYBE_ReportTokens DISABLED_ReportTokens
300 313
301 TEST_F(RpcHandlerTest, MAYBE_ReportTokens) { 314 TEST_F(RpcHandlerTest, MAYBE_ReportTokens) {
302 std::vector<AudioToken> test_tokens; 315 std::vector<AudioToken> test_tokens;
303 test_tokens.push_back(AudioToken("token 1", false)); 316 test_tokens.push_back(AudioToken("token 1", false));
304 test_tokens.push_back(AudioToken("token 2", true)); 317 test_tokens.push_back(AudioToken("token 2", true));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 messages_by_subscription_["Subscription 2"][1].payload()); 383 messages_by_subscription_["Subscription 2"][1].payload());
371 384
372 ASSERT_EQ(2U, directive_handler->added_directives().size()); 385 ASSERT_EQ(2U, directive_handler->added_directives().size());
373 EXPECT_EQ("Subscription 1", 386 EXPECT_EQ("Subscription 1",
374 directive_handler->added_directives()[0].subscription_id()); 387 directive_handler->added_directives()[0].subscription_id());
375 EXPECT_EQ("Subscription 2", 388 EXPECT_EQ("Subscription 2",
376 directive_handler->added_directives()[1].subscription_id()); 389 directive_handler->added_directives()[1].subscription_id());
377 } 390 }
378 391
379 } // namespace copresence 392 } // namespace copresence
OLDNEW
« components/copresence/rpc/rpc_handler.cc ('K') | « components/copresence/rpc/rpc_handler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698