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

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

Powered by Google App Engine
This is Rietveld 408576698