| OLD | NEW |
| 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 | 7 |
| 7 #include "google_apis/gcm/engine/checkin_request.h" | 8 #include "google_apis/gcm/engine/checkin_request.h" |
| 8 #include "google_apis/gcm/protocol/checkin.pb.h" | 9 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 9 #include "net/base/backoff_entry.h" | 10 #include "net/base/backoff_entry.h" |
| 10 #include "net/url_request/test_url_fetcher_factory.h" | 11 #include "net/url_request/test_url_fetcher_factory.h" |
| 11 #include "net/url_request/url_request_test_util.h" | 12 #include "net/url_request/url_request_test_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 14 |
| 14 namespace gcm { | 15 namespace gcm { |
| 15 | 16 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 79 |
| 79 protected: | 80 protected: |
| 80 bool callback_called_; | 81 bool callback_called_; |
| 81 uint64 android_id_; | 82 uint64 android_id_; |
| 82 uint64 security_token_; | 83 uint64 security_token_; |
| 83 int checkin_device_type_; | 84 int checkin_device_type_; |
| 84 base::MessageLoop message_loop_; | 85 base::MessageLoop message_loop_; |
| 85 net::TestURLFetcherFactory url_fetcher_factory_; | 86 net::TestURLFetcherFactory url_fetcher_factory_; |
| 86 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 87 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
| 87 checkin_proto::ChromeBuildProto chrome_build_proto_; | 88 checkin_proto::ChromeBuildProto chrome_build_proto_; |
| 89 std::vector<std::string> account_ids_; |
| 88 scoped_ptr<CheckinRequest> request_; | 90 scoped_ptr<CheckinRequest> request_; |
| 89 }; | 91 }; |
| 90 | 92 |
| 91 CheckinRequestTest::CheckinRequestTest() | 93 CheckinRequestTest::CheckinRequestTest() |
| 92 : callback_called_(false), | 94 : callback_called_(false), |
| 93 android_id_(kBlankAndroidId), | 95 android_id_(kBlankAndroidId), |
| 94 security_token_(kBlankSecurityToken), | 96 security_token_(kBlankSecurityToken), |
| 95 checkin_device_type_(0), | 97 checkin_device_type_(0), |
| 96 url_request_context_getter_(new net::TestURLRequestContextGetter( | 98 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 97 message_loop_.message_loop_proxy())) {} | 99 message_loop_.message_loop_proxy())) { |
| 100 account_ids_.push_back("account_id"); |
| 101 } |
| 98 | 102 |
| 99 CheckinRequestTest::~CheckinRequestTest() {} | 103 CheckinRequestTest::~CheckinRequestTest() {} |
| 100 | 104 |
| 101 void CheckinRequestTest::FetcherCallback(uint64 android_id, | 105 void CheckinRequestTest::FetcherCallback(uint64 android_id, |
| 102 uint64 security_token) { | 106 uint64 security_token) { |
| 103 callback_called_ = true; | 107 callback_called_ = true; |
| 104 android_id_ = android_id; | 108 android_id_ = android_id; |
| 105 security_token_ = security_token; | 109 security_token_ = security_token; |
| 106 } | 110 } |
| 107 | 111 |
| 108 void CheckinRequestTest::CreateRequest(uint64 android_id, | 112 void CheckinRequestTest::CreateRequest(uint64 android_id, |
| 109 uint64 security_token) { | 113 uint64 security_token) { |
| 110 // First setup a chrome_build protobuf. | 114 // First setup a chrome_build protobuf. |
| 111 chrome_build_proto_.set_platform( | 115 chrome_build_proto_.set_platform( |
| 112 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); | 116 checkin_proto::ChromeBuildProto::PLATFORM_LINUX); |
| 113 chrome_build_proto_.set_channel( | 117 chrome_build_proto_.set_channel( |
| 114 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); | 118 checkin_proto::ChromeBuildProto::CHANNEL_CANARY); |
| 115 chrome_build_proto_.set_chrome_version(kChromeVersion); | 119 chrome_build_proto_.set_chrome_version(kChromeVersion); |
| 116 // Then create a request with that protobuf and specified android_id, | 120 // Then create a request with that protobuf and specified android_id, |
| 117 // security_token. | 121 // security_token. |
| 118 request_.reset(new CheckinRequest( | 122 request_.reset(new CheckinRequest( |
| 119 base::Bind(&CheckinRequestTest::FetcherCallback, | 123 base::Bind(&CheckinRequestTest::FetcherCallback, base::Unretained(this)), |
| 120 base::Unretained(this)), | |
| 121 kDefaultBackoffPolicy, | 124 kDefaultBackoffPolicy, |
| 122 chrome_build_proto_, | 125 chrome_build_proto_, |
| 123 android_id, | 126 android_id, |
| 124 security_token, | 127 security_token, |
| 128 account_ids_, |
| 125 url_request_context_getter_.get())); | 129 url_request_context_getter_.get())); |
| 126 | 130 |
| 127 // Setting android_id_ and security_token_ to blank value, not used elsewhere | 131 // Setting android_id_ and security_token_ to blank value, not used elsewhere |
| 128 // in the tests. | 132 // in the tests. |
| 129 callback_called_ = false; | 133 callback_called_ = false; |
| 130 android_id_ = kBlankAndroidId; | 134 android_id_ = kBlankAndroidId; |
| 131 security_token_ = kBlankSecurityToken; | 135 security_token_ = kBlankSecurityToken; |
| 132 } | 136 } |
| 133 | 137 |
| 134 void CheckinRequestTest::SetResponseStatusAndString( | 138 void CheckinRequestTest::SetResponseStatusAndString( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 request_proto.checkin().chrome_build().chrome_version()); | 190 request_proto.checkin().chrome_build().chrome_version()); |
| 187 EXPECT_EQ(chrome_build_proto_.channel(), | 191 EXPECT_EQ(chrome_build_proto_.channel(), |
| 188 request_proto.checkin().chrome_build().channel()); | 192 request_proto.checkin().chrome_build().channel()); |
| 189 | 193 |
| 190 #if defined(CHROME_OS) | 194 #if defined(CHROME_OS) |
| 191 EXPECT_EQ(checkin_proto::DEVICE_CHROME_OS, request_proto.checkin().type()); | 195 EXPECT_EQ(checkin_proto::DEVICE_CHROME_OS, request_proto.checkin().type()); |
| 192 #else | 196 #else |
| 193 EXPECT_EQ(checkin_proto::DEVICE_CHROME_BROWSER, | 197 EXPECT_EQ(checkin_proto::DEVICE_CHROME_BROWSER, |
| 194 request_proto.checkin().type()); | 198 request_proto.checkin().type()); |
| 195 #endif | 199 #endif |
| 200 |
| 201 EXPECT_EQ(1, request_proto.account_cookie_size()); |
| 202 EXPECT_EQ("[account_id]", request_proto.account_cookie(0)); |
| 196 } | 203 } |
| 197 | 204 |
| 198 TEST_F(CheckinRequestTest, ResponseBodyEmpty) { | 205 TEST_F(CheckinRequestTest, ResponseBodyEmpty) { |
| 199 CreateRequest(0u, 0u); | 206 CreateRequest(0u, 0u); |
| 200 request_->Start(); | 207 request_->Start(); |
| 201 | 208 |
| 202 SetResponseStatusAndString(net::HTTP_OK, std::string()); | 209 SetResponseStatusAndString(net::HTTP_OK, std::string()); |
| 203 CompleteFetch(); | 210 CompleteFetch(); |
| 204 | 211 |
| 205 EXPECT_FALSE(callback_called_); | 212 EXPECT_FALSE(callback_called_); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 363 |
| 357 SetResponse(VALID_RESPONSE); | 364 SetResponse(VALID_RESPONSE); |
| 358 CompleteFetch(); | 365 CompleteFetch(); |
| 359 | 366 |
| 360 EXPECT_TRUE(callback_called_); | 367 EXPECT_TRUE(callback_called_); |
| 361 EXPECT_EQ(kAndroidId, android_id_); | 368 EXPECT_EQ(kAndroidId, android_id_); |
| 362 EXPECT_EQ(kSecurityToken, security_token_); | 369 EXPECT_EQ(kSecurityToken, security_token_); |
| 363 } | 370 } |
| 364 | 371 |
| 365 } // namespace gcm | 372 } // namespace gcm |
| OLD | NEW |