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