Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: google_apis/gcm/gcm_client_impl_unittest.cc

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing zea's comments. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/files/scoped_temp_dir.h" 7 #include "base/files/scoped_temp_dir.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
11 #include "components/os_crypt/os_crypt.h" 11 #include "components/os_crypt/os_crypt.h"
12 #include "google_apis/gcm/base/mcs_message.h" 12 #include "google_apis/gcm/base/mcs_message.h"
13 #include "google_apis/gcm/base/mcs_util.h" 13 #include "google_apis/gcm/base/mcs_util.h"
14 #include "google_apis/gcm/engine/fake_connection_factory.h" 14 #include "google_apis/gcm/engine/fake_connection_factory.h"
15 #include "google_apis/gcm/engine/fake_connection_handler.h" 15 #include "google_apis/gcm/engine/fake_connection_handler.h"
16 #include "google_apis/gcm/gcm_stats_recorder.h"
16 #include "google_apis/gcm/protocol/android_checkin.pb.h" 17 #include "google_apis/gcm/protocol/android_checkin.pb.h"
17 #include "google_apis/gcm/protocol/checkin.pb.h" 18 #include "google_apis/gcm/protocol/checkin.pb.h"
18 #include "google_apis/gcm/protocol/mcs.pb.h" 19 #include "google_apis/gcm/protocol/mcs.pb.h"
19 #include "net/url_request/test_url_fetcher_factory.h" 20 #include "net/url_request/test_url_fetcher_factory.h"
20 #include "net/url_request/url_fetcher_delegate.h" 21 #include "net/url_request/url_fetcher_delegate.h"
21 #include "net/url_request/url_request_test_util.h" 22 #include "net/url_request/url_request_test_util.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace gcm { 25 namespace gcm {
25 26
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 app_data->set_key(iter->first); 60 app_data->set_key(iter->first);
60 app_data->set_value(iter->second); 61 app_data->set_value(iter->second);
61 } 62 }
62 return MCSMessage(kDataMessageStanzaTag, data_message); 63 return MCSMessage(kDataMessageStanzaTag, data_message);
63 } 64 }
64 65
65 class FakeMCSClient : public MCSClient { 66 class FakeMCSClient : public MCSClient {
66 public: 67 public:
67 FakeMCSClient(base::Clock* clock, 68 FakeMCSClient(base::Clock* clock,
68 ConnectionFactory* connection_factory, 69 ConnectionFactory* connection_factory,
69 GCMStore* gcm_store); 70 GCMStore* gcm_store,
71 GCMStatsRecorder* recorder);
70 virtual ~FakeMCSClient(); 72 virtual ~FakeMCSClient();
71 virtual void Login(uint64 android_id, uint64 security_token) OVERRIDE; 73 virtual void Login(uint64 android_id, uint64 security_token) OVERRIDE;
72 virtual void SendMessage(const MCSMessage& message) OVERRIDE; 74 virtual void SendMessage(const MCSMessage& message) OVERRIDE;
73 75
74 uint64 last_android_id() const { return last_android_id_; } 76 uint64 last_android_id() const { return last_android_id_; }
75 uint64 last_security_token() const { return last_security_token_; } 77 uint64 last_security_token() const { return last_security_token_; }
76 uint8 last_message_tag() const { return last_message_tag_; } 78 uint8 last_message_tag() const { return last_message_tag_; }
77 const mcs_proto::DataMessageStanza& last_data_message_stanza() const { 79 const mcs_proto::DataMessageStanza& last_data_message_stanza() const {
78 return last_data_message_stanza_; 80 return last_data_message_stanza_;
79 } 81 }
80 82
81 private: 83 private:
82 uint64 last_android_id_; 84 uint64 last_android_id_;
83 uint64 last_security_token_; 85 uint64 last_security_token_;
84 uint8 last_message_tag_; 86 uint8 last_message_tag_;
85 mcs_proto::DataMessageStanza last_data_message_stanza_; 87 mcs_proto::DataMessageStanza last_data_message_stanza_;
86 }; 88 };
87 89
88 FakeMCSClient::FakeMCSClient(base::Clock* clock, 90 FakeMCSClient::FakeMCSClient(base::Clock* clock,
89 ConnectionFactory* connection_factory, 91 ConnectionFactory* connection_factory,
90 GCMStore* gcm_store) 92 GCMStore* gcm_store,
91 : MCSClient("", clock, connection_factory, gcm_store), 93 GCMStatsRecorder* recorder)
94 : MCSClient("", clock, connection_factory, gcm_store, recorder),
92 last_android_id_(0u), 95 last_android_id_(0u),
93 last_security_token_(0u), 96 last_security_token_(0u),
94 last_message_tag_(kNumProtoTypes) { 97 last_message_tag_(kNumProtoTypes) {
95 } 98 }
96 99
97 FakeMCSClient::~FakeMCSClient() { 100 FakeMCSClient::~FakeMCSClient() {
98 } 101 }
99 102
100 void FakeMCSClient::Login(uint64 android_id, uint64 security_token) { 103 void FakeMCSClient::Login(uint64 android_id, uint64 security_token) {
101 last_android_id_ = android_id; 104 last_android_id_ = android_id;
(...skipping 12 matching lines...) Expand all
114 class FakeGCMInternalsBuilder : public GCMInternalsBuilder { 117 class FakeGCMInternalsBuilder : public GCMInternalsBuilder {
115 public: 118 public:
116 FakeGCMInternalsBuilder(); 119 FakeGCMInternalsBuilder();
117 virtual ~FakeGCMInternalsBuilder(); 120 virtual ~FakeGCMInternalsBuilder();
118 121
119 virtual scoped_ptr<base::Clock> BuildClock() OVERRIDE; 122 virtual scoped_ptr<base::Clock> BuildClock() OVERRIDE;
120 virtual scoped_ptr<MCSClient> BuildMCSClient( 123 virtual scoped_ptr<MCSClient> BuildMCSClient(
121 const std::string& version, 124 const std::string& version,
122 base::Clock* clock, 125 base::Clock* clock,
123 ConnectionFactory* connection_factory, 126 ConnectionFactory* connection_factory,
124 GCMStore* gcm_store) OVERRIDE; 127 GCMStore* gcm_store,
128 GCMStatsRecorder* recorder) OVERRIDE;
125 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory( 129 virtual scoped_ptr<ConnectionFactory> BuildConnectionFactory(
126 const std::vector<GURL>& endpoints, 130 const std::vector<GURL>& endpoints,
127 const net::BackoffEntry::Policy& backoff_policy, 131 const net::BackoffEntry::Policy& backoff_policy,
128 scoped_refptr<net::HttpNetworkSession> network_session, 132 scoped_refptr<net::HttpNetworkSession> network_session,
129 net::NetLog* net_log) OVERRIDE; 133 net::NetLog* net_log) OVERRIDE;
130 }; 134 };
131 135
132 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder() {} 136 FakeGCMInternalsBuilder::FakeGCMInternalsBuilder() {}
133 137
134 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {} 138 FakeGCMInternalsBuilder::~FakeGCMInternalsBuilder() {}
135 139
136 scoped_ptr<base::Clock> FakeGCMInternalsBuilder::BuildClock() { 140 scoped_ptr<base::Clock> FakeGCMInternalsBuilder::BuildClock() {
137 return make_scoped_ptr<base::Clock>(new base::SimpleTestClock()); 141 return make_scoped_ptr<base::Clock>(new base::SimpleTestClock());
138 } 142 }
139 143
140 scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient( 144 scoped_ptr<MCSClient> FakeGCMInternalsBuilder::BuildMCSClient(
141 const std::string& version, 145 const std::string& version,
142 base::Clock* clock, 146 base::Clock* clock,
143 ConnectionFactory* connection_factory, 147 ConnectionFactory* connection_factory,
144 GCMStore* gcm_store) { 148 GCMStore* gcm_store,
149 GCMStatsRecorder* recorder) {
145 return make_scoped_ptr<MCSClient>(new FakeMCSClient(clock, 150 return make_scoped_ptr<MCSClient>(new FakeMCSClient(clock,
146 connection_factory, 151 connection_factory,
147 gcm_store)); 152 gcm_store,
153 recorder));
148 } 154 }
149 155
150 scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory( 156 scoped_ptr<ConnectionFactory> FakeGCMInternalsBuilder::BuildConnectionFactory(
151 const std::vector<GURL>& endpoints, 157 const std::vector<GURL>& endpoints,
152 const net::BackoffEntry::Policy& backoff_policy, 158 const net::BackoffEntry::Policy& backoff_policy,
153 scoped_refptr<net::HttpNetworkSession> network_session, 159 scoped_refptr<net::HttpNetworkSession> network_session,
154 net::NetLog* net_log) { 160 net::NetLog* net_log) {
155 return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory()); 161 return make_scoped_ptr<ConnectionFactory>(new FakeConnectionFactory());
156 } 162 }
157 163
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); 595 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent());
590 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); 596 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id());
591 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); 597 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from());
592 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); 598 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to());
593 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); 599 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key());
594 EXPECT_EQ("value", 600 EXPECT_EQ("value",
595 mcs_client()->last_data_message_stanza().app_data(0).value()); 601 mcs_client()->last_data_message_stanza().app_data(0).value());
596 } 602 }
597 603
598 } // namespace gcm 604 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698