| 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 "google_apis/gcm/gcm_client_impl.h" | 5 #include "google_apis/gcm/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" |
| 11 #include "base/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.h" |
| 12 #include "components/os_crypt/os_crypt_switches.h" | 12 #include "components/os_crypt/os_crypt_switches.h" |
| 13 #include "google_apis/gcm/base/mcs_message.h" | 13 #include "google_apis/gcm/base/mcs_message.h" |
| 14 #include "google_apis/gcm/base/mcs_util.h" | 14 #include "google_apis/gcm/base/mcs_util.h" |
| 15 #include "google_apis/gcm/engine/fake_connection_factory.h" | 15 #include "google_apis/gcm/engine/fake_connection_factory.h" |
| 16 #include "google_apis/gcm/engine/fake_connection_handler.h" | 16 #include "google_apis/gcm/engine/fake_connection_handler.h" |
| 17 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 17 #include "google_apis/gcm/protocol/android_checkin.pb.h" | 18 #include "google_apis/gcm/protocol/android_checkin.pb.h" |
| 18 #include "google_apis/gcm/protocol/checkin.pb.h" | 19 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 19 #include "google_apis/gcm/protocol/mcs.pb.h" | 20 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 20 #include "net/url_request/test_url_fetcher_factory.h" | 21 #include "net/url_request/test_url_fetcher_factory.h" |
| 21 #include "net/url_request/url_fetcher_delegate.h" | 22 #include "net/url_request/url_fetcher_delegate.h" |
| 22 #include "net/url_request/url_request_test_util.h" | 23 #include "net/url_request/url_request_test_util.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 namespace gcm { | 26 namespace gcm { |
| 26 | 27 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 app_data->set_key(iter->first); | 61 app_data->set_key(iter->first); |
| 61 app_data->set_value(iter->second); | 62 app_data->set_value(iter->second); |
| 62 } | 63 } |
| 63 return MCSMessage(kDataMessageStanzaTag, data_message); | 64 return MCSMessage(kDataMessageStanzaTag, data_message); |
| 64 } | 65 } |
| 65 | 66 |
| 66 class FakeMCSClient : public MCSClient { | 67 class FakeMCSClient : public MCSClient { |
| 67 public: | 68 public: |
| 68 FakeMCSClient(base::Clock* clock, | 69 FakeMCSClient(base::Clock* clock, |
| 69 ConnectionFactory* connection_factory, | 70 ConnectionFactory* connection_factory, |
| 70 GCMStore* gcm_store); | 71 GCMStore* gcm_store, |
| 72 GCMStatsRecorder* recorder); |
| 71 virtual ~FakeMCSClient(); | 73 virtual ~FakeMCSClient(); |
| 72 virtual void Login(uint64 android_id, uint64 security_token) OVERRIDE; | 74 virtual void Login(uint64 android_id, uint64 security_token) OVERRIDE; |
| 73 virtual void SendMessage(const MCSMessage& message) OVERRIDE; | 75 virtual void SendMessage(const MCSMessage& message) OVERRIDE; |
| 74 | 76 |
| 75 uint64 last_android_id() const { return last_android_id_; } | 77 uint64 last_android_id() const { return last_android_id_; } |
| 76 uint64 last_security_token() const { return last_security_token_; } | 78 uint64 last_security_token() const { return last_security_token_; } |
| 77 uint8 last_message_tag() const { return last_message_tag_; } | 79 uint8 last_message_tag() const { return last_message_tag_; } |
| 78 const mcs_proto::DataMessageStanza& last_data_message_stanza() const { | 80 const mcs_proto::DataMessageStanza& last_data_message_stanza() const { |
| 79 return last_data_message_stanza_; | 81 return last_data_message_stanza_; |
| 80 } | 82 } |
| 81 | 83 |
| 82 private: | 84 private: |
| 83 uint64 last_android_id_; | 85 uint64 last_android_id_; |
| 84 uint64 last_security_token_; | 86 uint64 last_security_token_; |
| 85 uint8 last_message_tag_; | 87 uint8 last_message_tag_; |
| 86 mcs_proto::DataMessageStanza last_data_message_stanza_; | 88 mcs_proto::DataMessageStanza last_data_message_stanza_; |
| 87 }; | 89 }; |
| 88 | 90 |
| 89 FakeMCSClient::FakeMCSClient(base::Clock* clock, | 91 FakeMCSClient::FakeMCSClient(base::Clock* clock, |
| 90 ConnectionFactory* connection_factory, | 92 ConnectionFactory* connection_factory, |
| 91 GCMStore* gcm_store) | 93 GCMStore* gcm_store, |
| 92 : MCSClient("", clock, connection_factory, gcm_store), | 94 GCMStatsRecorder* recorder) |
| 95 : MCSClient("", clock, connection_factory, gcm_store, recorder), |
| 93 last_android_id_(0u), | 96 last_android_id_(0u), |
| 94 last_security_token_(0u), | 97 last_security_token_(0u), |
| 95 last_message_tag_(kNumProtoTypes) { | 98 last_message_tag_(kNumProtoTypes) { |
| 96 } | 99 } |
| 97 | 100 |
| 98 FakeMCSClient::~FakeMCSClient() { | 101 FakeMCSClient::~FakeMCSClient() { |
| 99 } | 102 } |
| 100 | 103 |
| 101 void FakeMCSClient::Login(uint64 android_id, uint64 security_token) { | 104 void FakeMCSClient::Login(uint64 android_id, uint64 security_token) { |
| 102 last_android_id_ = android_id; | 105 last_android_id_ = android_id; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 115 class FakeGCMInternalsBuilder : public GCMInternalsBuilder { | 118 class FakeGCMInternalsBuilder : public GCMInternalsBuilder { |
| 116 public: | 119 public: |
| 117 FakeGCMInternalsBuilder(); | 120 FakeGCMInternalsBuilder(); |
| 118 virtual ~FakeGCMInternalsBuilder(); | 121 virtual ~FakeGCMInternalsBuilder(); |
| 119 | 122 |
| 120 virtual scoped_ptr<base::Clock> BuildClock() OVERRIDE; | 123 virtual scoped_ptr<base::Clock> BuildClock() OVERRIDE; |
| 121 virtual scoped_ptr<MCSClient> BuildMCSClient( | 124 virtual scoped_ptr<MCSClient> BuildMCSClient( |
| 122 const std::string& version, | 125 const std::string& version, |
| 123 base::Clock* clock, | 126 base::Clock* clock, |
| 124 ConnectionFactory* connection_factory, | 127 ConnectionFactory* connection_factory, |
| 125 GCMStore* gcm_store) OVERRIDE; | 128 GCMStore* gcm_store, |
| 129 GCMStatsRecorder* recorder) OVERRIDE; |
| 126 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( | 130 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( |
| 127 const std::vector<GURL>& endpoints, | 131 const std::vector<GURL>& endpoints, |
| 128 const net::BackoffEntry::Policy& backoff_policy, | 132 const net::BackoffEntry::Policy& backoff_policy, |
| 129 scoped_refptr<net::HttpNetworkSession> network_session, | 133 scoped_refptr<net::HttpNetworkSession> network_session, |
| 130 net::NetLog* net_log) OVERRIDE; | 134 net::NetLog* net_log) OVERRIDE; |
| 131 }; | 135 }; |
| 132 | 136 |
| 133 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder() {} | 137 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder() {} |
| 134 | 138 |
| 135 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {} | 139 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {} |
| 136 | 140 |
| 137 scoped_ptr<base::Clock> FakeGCMInternalsBuilder::BuildClock() { | 141 scoped_ptr<base::Clock> FakeGCMInternalsBuilder::BuildClock() { |
| 138 return make_scoped_ptr<base::Clock>(new base::SimpleTestClock()); | 142 return make_scoped_ptr<base::Clock>(new base::SimpleTestClock()); |
| 139 } | 143 } |
| 140 | 144 |
| 141 scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient( | 145 scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient( |
| 142 const std::string& version, | 146 const std::string& version, |
| 143 base::Clock* clock, | 147 base::Clock* clock, |
| 144 ConnectionFactory* connection_factory, | 148 ConnectionFactory* connection_factory, |
| 145 GCMStore* gcm_store) { | 149 GCMStore* gcm_store, |
| 150 GCMStatsRecorder* recorder) { |
| 146 return make_scoped_ptr<MCSClient>(new FakeMCSClient(clock, | 151 return make_scoped_ptr<MCSClient>(new FakeMCSClient(clock, |
| 147 connection_factory, | 152 connection_factory, |
| 148 gcm_store)); | 153 gcm_store, |
| 154 recorder)); |
| 149 } | 155 } |
| 150 | 156 |
| 151 scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory( | 157 scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory( |
| 152 const std::vector<GURL>& endpoints, | 158 const std::vector<GURL>& endpoints, |
| 153 const net::BackoffEntry::Policy& backoff_policy, | 159 const net::BackoffEntry::Policy& backoff_policy, |
| 154 scoped_refptr<net::HttpNetworkSession> network_session, | 160 scoped_refptr<net::HttpNetworkSession> network_session, |
| 155 net::NetLog* net_log) { | 161 net::NetLog* net_log) { |
| 156 return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory()); | 162 return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory()); |
| 157 } | 163 } |
| 158 | 164 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 590 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); | 596 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); |
| 591 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); | 597 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); |
| 592 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); | 598 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); |
| 593 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); | 599 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); |
| 594 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); | 600 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); |
| 595 EXPECT_EQ("value", | 601 EXPECT_EQ("value", |
| 596 mcs_client()->last_data_message_stanza().app_data(0).value()); | 602 mcs_client()->last_data_message_stanza().app_data(0).value()); |
| 597 } | 603 } |
| 598 | 604 |
| 599 } // namespace gcm | 605 } // namespace gcm |
| OLD | NEW |