| 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 "components/gcm_driver/gcm_client_impl.h" | 5 #include "components/gcm_driver/gcm_client_impl.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 return email_token_map; | 86 return email_token_map; |
| 87 } | 87 } |
| 88 | 88 |
| 89 class FakeMCSClient : public MCSClient { | 89 class FakeMCSClient : public MCSClient { |
| 90 public: | 90 public: |
| 91 FakeMCSClient(base::Clock* clock, | 91 FakeMCSClient(base::Clock* clock, |
| 92 ConnectionFactory* connection_factory, | 92 ConnectionFactory* connection_factory, |
| 93 GCMStore* gcm_store, | 93 GCMStore* gcm_store, |
| 94 GCMStatsRecorder* recorder); | 94 GCMStatsRecorder* recorder); |
| 95 virtual ~FakeMCSClient(); | 95 virtual ~FakeMCSClient(); |
| 96 virtual void Login(uint64 android_id, uint64 security_token) OVERRIDE; | 96 virtual void Login(uint64 android_id, uint64 security_token) override; |
| 97 virtual void SendMessage(const MCSMessage& message) OVERRIDE; | 97 virtual void SendMessage(const MCSMessage& message) override; |
| 98 | 98 |
| 99 uint64 last_android_id() const { return last_android_id_; } | 99 uint64 last_android_id() const { return last_android_id_; } |
| 100 uint64 last_security_token() const { return last_security_token_; } | 100 uint64 last_security_token() const { return last_security_token_; } |
| 101 uint8 last_message_tag() const { return last_message_tag_; } | 101 uint8 last_message_tag() const { return last_message_tag_; } |
| 102 const mcs_proto::DataMessageStanza& last_data_message_stanza() const { | 102 const mcs_proto::DataMessageStanza& last_data_message_stanza() const { |
| 103 return last_data_message_stanza_; | 103 return last_data_message_stanza_; |
| 104 } | 104 } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 uint64 last_android_id_; | 107 uint64 last_android_id_; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 135 reinterpret_cast<const mcs_proto::DataMessageStanza&>( | 135 reinterpret_cast<const mcs_proto::DataMessageStanza&>( |
| 136 message.GetProtobuf())); | 136 message.GetProtobuf())); |
| 137 } | 137 } |
| 138 } | 138 } |
| 139 | 139 |
| 140 class AutoAdvancingTestClock : public base::Clock { | 140 class AutoAdvancingTestClock : public base::Clock { |
| 141 public: | 141 public: |
| 142 explicit AutoAdvancingTestClock(base::TimeDelta auto_increment_time_delta); | 142 explicit AutoAdvancingTestClock(base::TimeDelta auto_increment_time_delta); |
| 143 virtual ~AutoAdvancingTestClock(); | 143 virtual ~AutoAdvancingTestClock(); |
| 144 | 144 |
| 145 virtual base::Time Now() OVERRIDE; | 145 virtual base::Time Now() override; |
| 146 void Advance(TimeDelta delta); | 146 void Advance(TimeDelta delta); |
| 147 int call_count() const { return call_count_; } | 147 int call_count() const { return call_count_; } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 int call_count_; | 150 int call_count_; |
| 151 base::TimeDelta auto_increment_time_delta_; | 151 base::TimeDelta auto_increment_time_delta_; |
| 152 base::Time now_; | 152 base::Time now_; |
| 153 | 153 |
| 154 DISALLOW_COPY_AND_ASSIGN(AutoAdvancingTestClock); | 154 DISALLOW_COPY_AND_ASSIGN(AutoAdvancingTestClock); |
| 155 }; | 155 }; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 | 170 |
| 171 void AutoAdvancingTestClock::Advance(base::TimeDelta delta) { | 171 void AutoAdvancingTestClock::Advance(base::TimeDelta delta) { |
| 172 now_ += delta; | 172 now_ += delta; |
| 173 } | 173 } |
| 174 | 174 |
| 175 class FakeGCMInternalsBuilder : public GCMInternalsBuilder { | 175 class FakeGCMInternalsBuilder : public GCMInternalsBuilder { |
| 176 public: | 176 public: |
| 177 FakeGCMInternalsBuilder(base::TimeDelta clock_step); | 177 FakeGCMInternalsBuilder(base::TimeDelta clock_step); |
| 178 virtual ~FakeGCMInternalsBuilder(); | 178 virtual ~FakeGCMInternalsBuilder(); |
| 179 | 179 |
| 180 virtual scoped_ptr<base::Clock> BuildClock() OVERRIDE; | 180 virtual scoped_ptr<base::Clock> BuildClock() override; |
| 181 virtual scoped_ptr<MCSClient> BuildMCSClient( | 181 virtual scoped_ptr<MCSClient> BuildMCSClient( |
| 182 const std::string& version, | 182 const std::string& version, |
| 183 base::Clock* clock, | 183 base::Clock* clock, |
| 184 ConnectionFactory* connection_factory, | 184 ConnectionFactory* connection_factory, |
| 185 GCMStore* gcm_store, | 185 GCMStore* gcm_store, |
| 186 GCMStatsRecorder* recorder) OVERRIDE; | 186 GCMStatsRecorder* recorder) override; |
| 187 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( | 187 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( |
| 188 const std::vector<GURL>& endpoints, | 188 const std::vector<GURL>& endpoints, |
| 189 const net::BackoffEntry::Policy& backoff_policy, | 189 const net::BackoffEntry::Policy& backoff_policy, |
| 190 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, | 190 const scoped_refptr<net::HttpNetworkSession>& gcm_network_session, |
| 191 const scoped_refptr<net::HttpNetworkSession>& http_network_session, | 191 const scoped_refptr<net::HttpNetworkSession>& http_network_session, |
| 192 net::NetLog* net_log, | 192 net::NetLog* net_log, |
| 193 GCMStatsRecorder* recorder) OVERRIDE; | 193 GCMStatsRecorder* recorder) override; |
| 194 | 194 |
| 195 private: | 195 private: |
| 196 base::TimeDelta clock_step_; | 196 base::TimeDelta clock_step_; |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder(base::TimeDelta clock_step) | 199 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder(base::TimeDelta clock_step) |
| 200 : clock_step_(clock_step) { | 200 : clock_step_(clock_step) { |
| 201 } | 201 } |
| 202 | 202 |
| 203 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {} | 203 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {} |
| (...skipping 25 matching lines...) Expand all Loading... |
| 229 } | 229 } |
| 230 | 230 |
| 231 } // namespace | 231 } // namespace |
| 232 | 232 |
| 233 class GCMClientImplTest : public testing::Test, | 233 class GCMClientImplTest : public testing::Test, |
| 234 public GCMClient::Delegate { | 234 public GCMClient::Delegate { |
| 235 public: | 235 public: |
| 236 GCMClientImplTest(); | 236 GCMClientImplTest(); |
| 237 virtual ~GCMClientImplTest(); | 237 virtual ~GCMClientImplTest(); |
| 238 | 238 |
| 239 virtual void SetUp() OVERRIDE; | 239 virtual void SetUp() override; |
| 240 | 240 |
| 241 void BuildGCMClient(base::TimeDelta clock_step); | 241 void BuildGCMClient(base::TimeDelta clock_step); |
| 242 void InitializeGCMClient(); | 242 void InitializeGCMClient(); |
| 243 void StartGCMClient(); | 243 void StartGCMClient(); |
| 244 void ReceiveMessageFromMCS(const MCSMessage& message); | 244 void ReceiveMessageFromMCS(const MCSMessage& message); |
| 245 void ReceiveOnMessageSentToMCS( | 245 void ReceiveOnMessageSentToMCS( |
| 246 const std::string& app_id, | 246 const std::string& app_id, |
| 247 const std::string& message_id, | 247 const std::string& message_id, |
| 248 const MCSClient::MessageSendStatus status); | 248 const MCSClient::MessageSendStatus status); |
| 249 void CompleteCheckin(uint64 android_id, | 249 void CompleteCheckin(uint64 android_id, |
| 250 uint64 security_token, | 250 uint64 security_token, |
| 251 const std::string& digest, | 251 const std::string& digest, |
| 252 const std::map<std::string, std::string>& settings); | 252 const std::map<std::string, std::string>& settings); |
| 253 void CompleteRegistration(const std::string& registration_id); | 253 void CompleteRegistration(const std::string& registration_id); |
| 254 void CompleteUnregistration(const std::string& app_id); | 254 void CompleteUnregistration(const std::string& app_id); |
| 255 | 255 |
| 256 bool ExistsRegistration(const std::string& app_id) const; | 256 bool ExistsRegistration(const std::string& app_id) const; |
| 257 void AddRegistration(const std::string& app_id, | 257 void AddRegistration(const std::string& app_id, |
| 258 const std::vector<std::string>& sender_ids, | 258 const std::vector<std::string>& sender_ids, |
| 259 const std::string& registration_id); | 259 const std::string& registration_id); |
| 260 | 260 |
| 261 // GCMClient::Delegate overrides (for verification). | 261 // GCMClient::Delegate overrides (for verification). |
| 262 virtual void OnRegisterFinished(const std::string& app_id, | 262 virtual void OnRegisterFinished(const std::string& app_id, |
| 263 const std::string& registration_id, | 263 const std::string& registration_id, |
| 264 GCMClient::Result result) OVERRIDE; | 264 GCMClient::Result result) override; |
| 265 virtual void OnUnregisterFinished(const std::string& app_id, | 265 virtual void OnUnregisterFinished(const std::string& app_id, |
| 266 GCMClient::Result result) OVERRIDE; | 266 GCMClient::Result result) override; |
| 267 virtual void OnSendFinished(const std::string& app_id, | 267 virtual void OnSendFinished(const std::string& app_id, |
| 268 const std::string& message_id, | 268 const std::string& message_id, |
| 269 GCMClient::Result result) OVERRIDE {} | 269 GCMClient::Result result) override {} |
| 270 virtual void OnMessageReceived(const std::string& registration_id, | 270 virtual void OnMessageReceived(const std::string& registration_id, |
| 271 const GCMClient::IncomingMessage& message) | 271 const GCMClient::IncomingMessage& message) |
| 272 OVERRIDE; | 272 override; |
| 273 virtual void OnMessagesDeleted(const std::string& app_id) OVERRIDE; | 273 virtual void OnMessagesDeleted(const std::string& app_id) override; |
| 274 virtual void OnMessageSendError( | 274 virtual void OnMessageSendError( |
| 275 const std::string& app_id, | 275 const std::string& app_id, |
| 276 const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; | 276 const gcm::GCMClient::SendErrorDetails& send_error_details) override; |
| 277 virtual void OnSendAcknowledged(const std::string& app_id, | 277 virtual void OnSendAcknowledged(const std::string& app_id, |
| 278 const std::string& message_id) OVERRIDE; | 278 const std::string& message_id) override; |
| 279 virtual void OnGCMReady( | 279 virtual void OnGCMReady( |
| 280 const std::vector<AccountMapping>& account_mappings) OVERRIDE; | 280 const std::vector<AccountMapping>& account_mappings) override; |
| 281 virtual void OnActivityRecorded() OVERRIDE {} | 281 virtual void OnActivityRecorded() override {} |
| 282 virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE {} | 282 virtual void OnConnected(const net::IPEndPoint& ip_endpoint) override {} |
| 283 virtual void OnDisconnected() OVERRIDE {} | 283 virtual void OnDisconnected() override {} |
| 284 | 284 |
| 285 GCMClientImpl* gcm_client() const { return gcm_client_.get(); } | 285 GCMClientImpl* gcm_client() const { return gcm_client_.get(); } |
| 286 FakeMCSClient* mcs_client() const { | 286 FakeMCSClient* mcs_client() const { |
| 287 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get()); | 287 return reinterpret_cast<FakeMCSClient*>(gcm_client_->mcs_client_.get()); |
| 288 } | 288 } |
| 289 ConnectionFactory* connection_factory() const { | 289 ConnectionFactory* connection_factory() const { |
| 290 return gcm_client_->connection_factory_.get(); | 290 return gcm_client_->connection_factory_.get(); |
| 291 } | 291 } |
| 292 | 292 |
| 293 const GCMClientImpl::CheckinInfo& device_checkin_info() const { | 293 const GCMClientImpl::CheckinInfo& device_checkin_info() const { |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 EXPECT_EQ(MESSAGE_SEND_ACK, last_event()); | 747 EXPECT_EQ(MESSAGE_SEND_ACK, last_event()); |
| 748 EXPECT_EQ(kAppId, last_app_id()); | 748 EXPECT_EQ(kAppId, last_app_id()); |
| 749 EXPECT_EQ("007", last_message_id()); | 749 EXPECT_EQ("007", last_message_id()); |
| 750 } | 750 } |
| 751 | 751 |
| 752 class GCMClientImplCheckinTest : public GCMClientImplTest { | 752 class GCMClientImplCheckinTest : public GCMClientImplTest { |
| 753 public: | 753 public: |
| 754 GCMClientImplCheckinTest(); | 754 GCMClientImplCheckinTest(); |
| 755 virtual ~GCMClientImplCheckinTest(); | 755 virtual ~GCMClientImplCheckinTest(); |
| 756 | 756 |
| 757 virtual void SetUp() OVERRIDE; | 757 virtual void SetUp() override; |
| 758 }; | 758 }; |
| 759 | 759 |
| 760 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { | 760 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { |
| 761 } | 761 } |
| 762 | 762 |
| 763 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { | 763 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { |
| 764 } | 764 } |
| 765 | 765 |
| 766 void GCMClientImplCheckinTest::SetUp() { | 766 void GCMClientImplCheckinTest::SetUp() { |
| 767 testing::Test::SetUp(); | 767 testing::Test::SetUp(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 976 EXPECT_TRUE(device_checkin_info().accounts_set); | 976 EXPECT_TRUE(device_checkin_info().accounts_set); |
| 977 EXPECT_EQ(MakeEmailToTokenMap(account_tokens), | 977 EXPECT_EQ(MakeEmailToTokenMap(account_tokens), |
| 978 device_checkin_info().account_tokens); | 978 device_checkin_info().account_tokens); |
| 979 } | 979 } |
| 980 | 980 |
| 981 class GCMClientImplStartAndStopTest : public GCMClientImplTest { | 981 class GCMClientImplStartAndStopTest : public GCMClientImplTest { |
| 982 public: | 982 public: |
| 983 GCMClientImplStartAndStopTest(); | 983 GCMClientImplStartAndStopTest(); |
| 984 virtual ~GCMClientImplStartAndStopTest(); | 984 virtual ~GCMClientImplStartAndStopTest(); |
| 985 | 985 |
| 986 virtual void SetUp() OVERRIDE; | 986 virtual void SetUp() override; |
| 987 }; | 987 }; |
| 988 | 988 |
| 989 GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() { | 989 GCMClientImplStartAndStopTest::GCMClientImplStartAndStopTest() { |
| 990 } | 990 } |
| 991 | 991 |
| 992 GCMClientImplStartAndStopTest::~GCMClientImplStartAndStopTest() { | 992 GCMClientImplStartAndStopTest::~GCMClientImplStartAndStopTest() { |
| 993 } | 993 } |
| 994 | 994 |
| 995 void GCMClientImplStartAndStopTest::SetUp() { | 995 void GCMClientImplStartAndStopTest::SetUp() { |
| 996 testing::Test::SetUp(); | 996 testing::Test::SetUp(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1025 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) { | 1025 TEST_F(GCMClientImplStartAndStopTest, StartStopAndRestartImmediately) { |
| 1026 // Start the GCM and then stop and restart it immediately. | 1026 // Start the GCM and then stop and restart it immediately. |
| 1027 gcm_client()->Start(); | 1027 gcm_client()->Start(); |
| 1028 gcm_client()->Stop(); | 1028 gcm_client()->Stop(); |
| 1029 gcm_client()->Start(); | 1029 gcm_client()->Start(); |
| 1030 | 1030 |
| 1031 PumpLoopUntilIdle(); | 1031 PumpLoopUntilIdle(); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 } // namespace gcm | 1034 } // namespace gcm |
| OLD | NEW |