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

Side by Side Diff: google_apis/gcm/engine/checkin_request_unittest.cc

Issue 330733002: Move IdentityProvider usage from GCMDriverDesktop to GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix after sync Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « google_apis/gcm/engine/checkin_request.cc ('k') | google_apis/gcm/tools/mcs_probe.cc » ('j') | 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 <string> 5 #include <string>
6 #include <vector>
7 6
8 #include "google_apis/gcm/engine/checkin_request.h" 7 #include "google_apis/gcm/engine/checkin_request.h"
9 #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h" 8 #include "google_apis/gcm/monitoring/fake_gcm_stats_recorder.h"
10 #include "google_apis/gcm/protocol/checkin.pb.h" 9 #include "google_apis/gcm/protocol/checkin.pb.h"
11 #include "net/base/backoff_entry.h" 10 #include "net/base/backoff_entry.h"
12 #include "net/url_request/test_url_fetcher_factory.h" 11 #include "net/url_request/test_url_fetcher_factory.h"
13 #include "net/url_request/url_request_test_util.h" 12 #include "net/url_request/url_request_test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
15 14
16 namespace gcm { 15 namespace gcm {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 82
84 protected: 83 protected:
85 bool callback_called_; 84 bool callback_called_;
86 uint64 android_id_; 85 uint64 android_id_;
87 uint64 security_token_; 86 uint64 security_token_;
88 int checkin_device_type_; 87 int checkin_device_type_;
89 base::MessageLoop message_loop_; 88 base::MessageLoop message_loop_;
90 net::TestURLFetcherFactory url_fetcher_factory_; 89 net::TestURLFetcherFactory url_fetcher_factory_;
91 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; 90 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
92 checkin_proto::ChromeBuildProto chrome_build_proto_; 91 checkin_proto::ChromeBuildProto chrome_build_proto_;
93 std::vector<std::string> account_ids_;
94 scoped_ptr<CheckinRequest> request_; 92 scoped_ptr<CheckinRequest> request_;
95 FakeGCMStatsRecorder recorder_; 93 FakeGCMStatsRecorder recorder_;
96 }; 94 };
97 95
98 CheckinRequestTest::CheckinRequestTest() 96 CheckinRequestTest::CheckinRequestTest()
99 : callback_called_(false), 97 : callback_called_(false),
100 android_id_(kBlankAndroidId), 98 android_id_(kBlankAndroidId),
101 security_token_(kBlankSecurityToken), 99 security_token_(kBlankSecurityToken),
102 checkin_device_type_(0), 100 checkin_device_type_(0),
103 url_request_context_getter_(new net::TestURLRequestContextGetter( 101 url_request_context_getter_(new net::TestURLRequestContextGetter(
104 message_loop_.message_loop_proxy())) { 102 message_loop_.message_loop_proxy())) {
105 account_ids_.push_back("account_id");
106 } 103 }
107 104
108 CheckinRequestTest::~CheckinRequestTest() {} 105 CheckinRequestTest::~CheckinRequestTest() {}
109 106
110 void CheckinRequestTest::FetcherCallback( 107 void CheckinRequestTest::FetcherCallback(
111 const checkin_proto::AndroidCheckinResponse& checkin_response) { 108 const checkin_proto::AndroidCheckinResponse& checkin_response) {
112 callback_called_ = true; 109 callback_called_ = true;
113 if (checkin_response.has_android_id()) 110 if (checkin_response.has_android_id())
114 android_id_ = checkin_response.android_id(); 111 android_id_ = checkin_response.android_id();
115 if (checkin_response.has_security_token()) 112 if (checkin_response.has_security_token())
116 security_token_ = checkin_response.security_token(); 113 security_token_ = checkin_response.security_token();
117 } 114 }
118 115
119 void CheckinRequestTest::CreateRequest(uint64 android_id, 116 void CheckinRequestTest::CreateRequest(uint64 android_id,
120 uint64 security_token) { 117 uint64 security_token) {
121 // First setup a chrome_build protobuf. 118 // First setup a chrome_build protobuf.
122 chrome_build_proto_.set_platform( 119 chrome_build_proto_.set_platform(
123 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); 120 checkin_proto::ChromeBuildProto::PLATFORM_LINUX);
124 chrome_build_proto_.set_channel( 121 chrome_build_proto_.set_channel(
125 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); 122 checkin_proto::ChromeBuildProto::CHANNEL_CANARY);
126 chrome_build_proto_.set_chrome_version(kChromeVersion); 123 chrome_build_proto_.set_chrome_version(kChromeVersion);
127 124
128 CheckinRequest::RequestInfo request_info( 125 CheckinRequest::RequestInfo request_info(
129 android_id, 126 android_id,
130 security_token, 127 security_token,
131 kSettingsDigest, 128 kSettingsDigest,
132 account_ids_,
133 chrome_build_proto_); 129 chrome_build_proto_);
134 // Then create a request with that protobuf and specified android_id, 130 // Then create a request with that protobuf and specified android_id,
135 // security_token. 131 // security_token.
136 request_.reset(new CheckinRequest( 132 request_.reset(new CheckinRequest(
137 GURL(kCheckinURL), 133 GURL(kCheckinURL),
138 request_info, 134 request_info,
139 kDefaultBackoffPolicy, 135 kDefaultBackoffPolicy,
140 base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)), 136 base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)),
141 url_request_context_getter_.get(), 137 url_request_context_getter_.get(),
142 &recorder_)); 138 &recorder_));
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 request_proto.checkin().chrome_build().channel()); 201 request_proto.checkin().chrome_build().channel());
206 202
207 #if defined(CHROME_OS) 203 #if defined(CHROME_OS)
208 EXPECT_EQ(checkin_proto::DEVICE_CHROME_OS, request_proto.checkin().type()); 204 EXPECT_EQ(checkin_proto::DEVICE_CHROME_OS, request_proto.checkin().type());
209 #else 205 #else
210 EXPECT_EQ(checkin_proto::DEVICE_CHROME_BROWSER, 206 EXPECT_EQ(checkin_proto::DEVICE_CHROME_BROWSER,
211 request_proto.checkin().type()); 207 request_proto.checkin().type());
212 #endif 208 #endif
213 209
214 EXPECT_EQ(kSettingsDigest, request_proto.digest()); 210 EXPECT_EQ(kSettingsDigest, request_proto.digest());
215 EXPECT_EQ(1, request_proto.account_cookie_size());
216 EXPECT_EQ("[account_id]", request_proto.account_cookie(0));
217 } 211 }
218 212
219 TEST_F(CheckinRequestTest, ResponseBodyEmpty) { 213 TEST_F(CheckinRequestTest, ResponseBodyEmpty) {
220 CreateRequest(0u, 0u); 214 CreateRequest(0u, 0u);
221 request_->Start(); 215 request_->Start();
222 216
223 SetResponseStatusAndString(net::HTTP_OK, std::string()); 217 SetResponseStatusAndString(net::HTTP_OK, std::string());
224 CompleteFetch(); 218 CompleteFetch();
225 219
226 EXPECT_FALSE(callback_called_); 220 EXPECT_FALSE(callback_called_);
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 371
378 SetResponse(VALID_RESPONSE); 372 SetResponse(VALID_RESPONSE);
379 CompleteFetch(); 373 CompleteFetch();
380 374
381 EXPECT_TRUE(callback_called_); 375 EXPECT_TRUE(callback_called_);
382 EXPECT_EQ(kAndroidId, android_id_); 376 EXPECT_EQ(kAndroidId, android_id_);
383 EXPECT_EQ(kSecurityToken, security_token_); 377 EXPECT_EQ(kSecurityToken, security_token_);
384 } 378 }
385 379
386 } // namespace gcm 380 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/checkin_request.cc ('k') | google_apis/gcm/tools/mcs_probe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698