| Index: google_apis/gcm/engine/registration_request_unittest.cc
|
| diff --git a/google_apis/gcm/engine/registration_request_unittest.cc b/google_apis/gcm/engine/registration_request_unittest.cc
|
| index 25b7ed8e1cea92bf54c8d0e203d93ef278e26886..51ac6e3f423112b03cc75918447dd33f0568a92e 100644
|
| --- a/google_apis/gcm/engine/registration_request_unittest.cc
|
| +++ b/google_apis/gcm/engine/registration_request_unittest.cc
|
| @@ -24,6 +24,7 @@ namespace gcm {
|
| namespace {
|
| const uint64_t kAndroidId = 42UL;
|
| const char kAppId[] = "TestAppId";
|
| +const char kCategoryForSubtypes[] = "com.chrome.stable.macosx";
|
| const char kDeveloperId[] = "Project1";
|
| const char kLoginHeader[] = "AidLogin";
|
| const char kRegistrationURL[] = "http://foo.bar/register";
|
| @@ -96,8 +97,9 @@ GCMRegistrationRequestTest::~GCMRegistrationRequestTest() {
|
| }
|
|
|
| void GCMRegistrationRequestTest::CreateRequest(const std::string& sender_ids) {
|
| - RegistrationRequest::RequestInfo request_info(
|
| - kAndroidId, kSecurityToken, kAppId);
|
| + RegistrationRequest::RequestInfo request_info(kAndroidId, kSecurityToken,
|
| + kAppId, false /* use_subtype */,
|
| + kCategoryForSubtypes);
|
| std::unique_ptr<GCMRegistrationRequestHandler> request_handler(
|
| new GCMRegistrationRequestHandler(sender_ids));
|
| request_.reset(new RegistrationRequest(
|
| @@ -149,20 +151,7 @@ TEST_F(GCMRegistrationRequestTest, RequestDataAndURL) {
|
| expected_pairs["sender"] = kDeveloperId;
|
| expected_pairs["device"] = base::Uint64ToString(kAndroidId);
|
|
|
| - // Verify data was formatted properly.
|
| - std::string upload_data = fetcher->upload_data();
|
| - base::StringTokenizer data_tokenizer(upload_data, "&=");
|
| - while (data_tokenizer.GetNext()) {
|
| - std::map<std::string, std::string>::iterator iter =
|
| - expected_pairs.find(data_tokenizer.token());
|
| - ASSERT_TRUE(iter != expected_pairs.end());
|
| - ASSERT_TRUE(data_tokenizer.GetNext());
|
| - EXPECT_EQ(iter->second, data_tokenizer.token());
|
| - // Ensure that none of the keys appears twice.
|
| - expected_pairs.erase(iter);
|
| - }
|
| -
|
| - EXPECT_EQ(0UL, expected_pairs.size());
|
| + ASSERT_NO_FATAL_FAILURE(VerifyFetcherUploadData(&expected_pairs));
|
| }
|
|
|
| TEST_F(GCMRegistrationRequestTest, RequestRegistrationWithMultipleSenderIds) {
|
| @@ -398,7 +387,8 @@ class InstanceIDGetTokenRequestTest : public RegistrationRequestTest {
|
| InstanceIDGetTokenRequestTest();
|
| ~InstanceIDGetTokenRequestTest() override;
|
|
|
| - void CreateRequest(const std::string& instance_id,
|
| + void CreateRequest(bool use_subtype,
|
| + const std::string& instance_id,
|
| const std::string& authorized_entity,
|
| const std::string& scope,
|
| const std::map<std::string, std::string>& options);
|
| @@ -411,12 +401,13 @@ InstanceIDGetTokenRequestTest::~InstanceIDGetTokenRequestTest() {
|
| }
|
|
|
| void InstanceIDGetTokenRequestTest::CreateRequest(
|
| + bool use_subtype,
|
| const std::string& instance_id,
|
| const std::string& authorized_entity,
|
| const std::string& scope,
|
| const std::map<std::string, std::string>& options) {
|
| RegistrationRequest::RequestInfo request_info(
|
| - kAndroidId, kSecurityToken, kAppId);
|
| + kAndroidId, kSecurityToken, kAppId, use_subtype, kCategoryForSubtypes);
|
| std::unique_ptr<InstanceIDGetTokenRequestHandler> request_handler(
|
| new InstanceIDGetTokenRequestHandler(instance_id, authorized_entity,
|
| scope, kGCMVersion, options));
|
| @@ -434,7 +425,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestSuccessful) {
|
| options["Foo"] = "Bar";
|
|
|
| set_max_retry_count(0);
|
| - CreateRequest(kInstanceId, kDeveloperId, kScope, options);
|
| + CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope,
|
| + options);
|
| request_->Start();
|
|
|
| SetResponse(net::HTTP_OK, "token=2501");
|
| @@ -448,7 +440,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestSuccessful) {
|
| TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
|
| std::map<std::string, std::string> options;
|
| options["Foo"] = "Bar";
|
| - CreateRequest(kInstanceId, kDeveloperId, kScope, options);
|
| + CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope,
|
| + options);
|
| request_->Start();
|
|
|
| // Get data sent by request.
|
| @@ -479,7 +472,32 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
|
| expected_pairs["gmsv"] = base::IntToString(kGCMVersion);
|
| expected_pairs["app"] = kAppId;
|
| expected_pairs["sender"] = kDeveloperId;
|
| - expected_pairs["X-subtype"] = kDeveloperId;
|
| + expected_pairs["device"] = base::Uint64ToString(kAndroidId);
|
| + expected_pairs["appid"] = kInstanceId;
|
| + expected_pairs["scope"] = kScope;
|
| + expected_pairs["X-scope"] = kScope;
|
| + expected_pairs["X-Foo"] = "Bar";
|
| +
|
| + ASSERT_NO_FATAL_FAILURE(VerifyFetcherUploadData(&expected_pairs));
|
| +}
|
| +
|
| +TEST_F(InstanceIDGetTokenRequestTest, RequestDataWithSubtype) {
|
| + std::map<std::string, std::string> options;
|
| + options["Foo"] = "Bar";
|
| + CreateRequest(true /* use_subtype */, kInstanceId, kDeveloperId, kScope,
|
| + options);
|
| + request_->Start();
|
| +
|
| + // Get data sent by request.
|
| + net::TestURLFetcher* fetcher = GetFetcher();
|
| + ASSERT_TRUE(fetcher);
|
| +
|
| + // Same as RequestDataAndURL except "app" and "X-subtype".
|
| + std::map<std::string, std::string> expected_pairs;
|
| + expected_pairs["gmsv"] = base::IntToString(kGCMVersion);
|
| + expected_pairs["app"] = kCategoryForSubtypes;
|
| + expected_pairs["X-subtype"] = kAppId;
|
| + expected_pairs["sender"] = kDeveloperId;
|
| expected_pairs["device"] = base::Uint64ToString(kAndroidId);
|
| expected_pairs["appid"] = kInstanceId;
|
| expected_pairs["scope"] = kScope;
|
| @@ -490,8 +508,7 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
|
| std::string upload_data = fetcher->upload_data();
|
| base::StringTokenizer data_tokenizer(upload_data, "&=");
|
| while (data_tokenizer.GetNext()) {
|
| - std::map<std::string, std::string>::iterator iter =
|
| - expected_pairs.find(data_tokenizer.token());
|
| + auto iter = expected_pairs.find(data_tokenizer.token());
|
| ASSERT_TRUE(iter != expected_pairs.end());
|
| ASSERT_TRUE(data_tokenizer.GetNext());
|
| EXPECT_EQ(iter->second, data_tokenizer.token());
|
| @@ -504,7 +521,8 @@ TEST_F(InstanceIDGetTokenRequestTest, RequestDataAndURL) {
|
|
|
| TEST_F(InstanceIDGetTokenRequestTest, ResponseHttpStatusNotOK) {
|
| std::map<std::string, std::string> options;
|
| - CreateRequest(kInstanceId, kDeveloperId, kScope, options);
|
| + CreateRequest(false /* use_subtype */, kInstanceId, kDeveloperId, kScope,
|
| + options);
|
| request_->Start();
|
|
|
| SetResponse(net::HTTP_UNAUTHORIZED, "token=2501");
|
|
|