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

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

Issue 179043005: [GCM] Remove the requirement for manifest key (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove cert Created 6 years, 9 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/registration_request.cc ('k') | google_apis/gcm/gcm_client.h » ('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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_tokenizer.h" 10 #include "base/strings/string_tokenizer.h"
11 #include "google_apis/gcm/engine/registration_request.h" 11 #include "google_apis/gcm/engine/registration_request.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_status.h" 13 #include "net/url_request/url_request_status.h"
14 #include "net/url_request/url_request_test_util.h" 14 #include "net/url_request/url_request_test_util.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 namespace gcm { 17 namespace gcm {
18 18
19 namespace { 19 namespace {
20 const uint64 kAndroidId = 42UL; 20 const uint64 kAndroidId = 42UL;
21 const char kAppId[] = "TestAppId"; 21 const char kAppId[] = "TestAppId";
22 const char kCert[] = "0DEADBEEF420";
23 const char kDeveloperId[] = "Project1"; 22 const char kDeveloperId[] = "Project1";
24 const char kLoginHeader[] = "AidLogin"; 23 const char kLoginHeader[] = "AidLogin";
25 const uint64 kSecurityToken = 77UL; 24 const uint64 kSecurityToken = 77UL;
26 25
27 // Backoff policy for testing registration request. 26 // Backoff policy for testing registration request.
28 const net::BackoffEntry::Policy kDefaultBackoffPolicy = { 27 const net::BackoffEntry::Policy kDefaultBackoffPolicy = {
29 // Number of initial errors (in sequence) to ignore before applying 28 // Number of initial errors (in sequence) to ignore before applying
30 // exponential back-off rules. 29 // exponential back-off rules.
31 // Explicitly set to 2 to skip the delay on the first retry, as we are not 30 // Explicitly set to 2 to skip the delay on the first retry, as we are not
32 // trying to test the backoff itself, but rather the fact that retry happens. 31 // trying to test the backoff itself, but rather the fact that retry happens.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void RegistrationRequestTest::CreateRequest(const std::string& sender_ids) { 102 void RegistrationRequestTest::CreateRequest(const std::string& sender_ids) {
104 std::vector<std::string> senders; 103 std::vector<std::string> senders;
105 base::StringTokenizer tokenizer(sender_ids, ","); 104 base::StringTokenizer tokenizer(sender_ids, ",");
106 while (tokenizer.GetNext()) 105 while (tokenizer.GetNext())
107 senders.push_back(tokenizer.token()); 106 senders.push_back(tokenizer.token());
108 107
109 request_.reset(new RegistrationRequest( 108 request_.reset(new RegistrationRequest(
110 RegistrationRequest::RequestInfo(kAndroidId, 109 RegistrationRequest::RequestInfo(kAndroidId,
111 kSecurityToken, 110 kSecurityToken,
112 kAppId, 111 kAppId,
113 kCert,
114 senders), 112 senders),
115 kDefaultBackoffPolicy, 113 kDefaultBackoffPolicy,
116 base::Bind(&RegistrationRequestTest::RegistrationCallback, 114 base::Bind(&RegistrationRequestTest::RegistrationCallback,
117 base::Unretained(this)), 115 base::Unretained(this)),
118 max_retry_count_, 116 max_retry_count_,
119 url_request_context_getter_.get())); 117 url_request_context_getter_.get()));
120 } 118 }
121 119
122 void RegistrationRequestTest::SetResponseStatusAndString( 120 void RegistrationRequestTest::SetResponseStatusAndString(
123 net::HttpStatusCode status_code, 121 net::HttpStatusCode status_code,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 ASSERT_TRUE(auth_tokenizer.GetNext()); 166 ASSERT_TRUE(auth_tokenizer.GetNext());
169 EXPECT_EQ(kLoginHeader, auth_tokenizer.token()); 167 EXPECT_EQ(kLoginHeader, auth_tokenizer.token());
170 ASSERT_TRUE(auth_tokenizer.GetNext()); 168 ASSERT_TRUE(auth_tokenizer.GetNext());
171 EXPECT_EQ(base::Uint64ToString(kAndroidId), auth_tokenizer.token()); 169 EXPECT_EQ(base::Uint64ToString(kAndroidId), auth_tokenizer.token());
172 ASSERT_TRUE(auth_tokenizer.GetNext()); 170 ASSERT_TRUE(auth_tokenizer.GetNext());
173 EXPECT_EQ(base::Uint64ToString(kSecurityToken), auth_tokenizer.token()); 171 EXPECT_EQ(base::Uint64ToString(kSecurityToken), auth_tokenizer.token());
174 172
175 std::map<std::string, std::string> expected_pairs; 173 std::map<std::string, std::string> expected_pairs;
176 expected_pairs["app"] = kAppId; 174 expected_pairs["app"] = kAppId;
177 expected_pairs["sender"] = kDeveloperId; 175 expected_pairs["sender"] = kDeveloperId;
178 expected_pairs["cert"] = kCert;
179 expected_pairs["device"] = base::Uint64ToString(kAndroidId); 176 expected_pairs["device"] = base::Uint64ToString(kAndroidId);
180 177
181 // Verify data was formatted properly. 178 // Verify data was formatted properly.
182 std::string upload_data = fetcher->upload_data(); 179 std::string upload_data = fetcher->upload_data();
183 base::StringTokenizer data_tokenizer(upload_data, "&="); 180 base::StringTokenizer data_tokenizer(upload_data, "&=");
184 while (data_tokenizer.GetNext()) { 181 while (data_tokenizer.GetNext()) {
185 std::map<std::string, std::string>::iterator iter = 182 std::map<std::string, std::string>::iterator iter =
186 expected_pairs.find(data_tokenizer.token()); 183 expected_pairs.find(data_tokenizer.token());
187 ASSERT_TRUE(iter != expected_pairs.end()); 184 ASSERT_TRUE(iter != expected_pairs.end());
188 ASSERT_TRUE(data_tokenizer.GetNext()); 185 ASSERT_TRUE(data_tokenizer.GetNext());
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 398
402 SetResponseStatusAndString(net::HTTP_GATEWAY_TIMEOUT, "token=2501"); 399 SetResponseStatusAndString(net::HTTP_GATEWAY_TIMEOUT, "token=2501");
403 CompleteFetch(); 400 CompleteFetch();
404 401
405 EXPECT_TRUE(callback_called_); 402 EXPECT_TRUE(callback_called_);
406 EXPECT_EQ(RegistrationRequest::REACHED_MAX_RETRIES, status_); 403 EXPECT_EQ(RegistrationRequest::REACHED_MAX_RETRIES, status_);
407 EXPECT_EQ(std::string(), registration_id_); 404 EXPECT_EQ(std::string(), registration_id_);
408 } 405 }
409 406
410 } // namespace gcm 407 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/registration_request.cc ('k') | google_apis/gcm/gcm_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698