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

Side by Side Diff: components/gcm_driver/gcm_client_impl_unittest.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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 "components/gcm_driver/gcm_client_impl.h" 5 #include "components/gcm_driver/gcm_client_impl.h"
6 6
7 #include <stdint.h>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
8 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
13 #include "base/test/test_mock_time_task_runner.h" 16 #include "base/test/test_mock_time_task_runner.h"
14 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
15 #include "base/time/clock.h" 18 #include "base/time/clock.h"
16 #include "base/timer/timer.h" 19 #include "base/timer/timer.h"
17 #include "google_apis/gcm/base/fake_encryptor.h" 20 #include "google_apis/gcm/base/fake_encryptor.h"
18 #include "google_apis/gcm/base/mcs_message.h" 21 #include "google_apis/gcm/base/mcs_message.h"
19 #include "google_apis/gcm/base/mcs_util.h" 22 #include "google_apis/gcm/base/mcs_util.h"
20 #include "google_apis/gcm/engine/fake_connection_factory.h" 23 #include "google_apis/gcm/engine/fake_connection_factory.h"
(...skipping 17 matching lines...) Expand all
38 LOADING_COMPLETED, 41 LOADING_COMPLETED,
39 REGISTRATION_COMPLETED, 42 REGISTRATION_COMPLETED,
40 UNREGISTRATION_COMPLETED, 43 UNREGISTRATION_COMPLETED,
41 MESSAGE_SEND_ERROR, 44 MESSAGE_SEND_ERROR,
42 MESSAGE_SEND_ACK, 45 MESSAGE_SEND_ACK,
43 MESSAGE_RECEIVED, 46 MESSAGE_RECEIVED,
44 MESSAGES_DELETED, 47 MESSAGES_DELETED,
45 }; 48 };
46 49
47 const char kChromeVersion[] = "45.0.0.1"; 50 const char kChromeVersion[] = "45.0.0.1";
48 const uint64 kDeviceAndroidId = 54321; 51 const uint64_t kDeviceAndroidId = 54321;
49 const uint64 kDeviceSecurityToken = 12345; 52 const uint64_t kDeviceSecurityToken = 12345;
50 const uint64 kDeviceAndroidId2 = 11111; 53 const uint64_t kDeviceAndroidId2 = 11111;
51 const uint64 kDeviceSecurityToken2 = 2222; 54 const uint64_t kDeviceSecurityToken2 = 2222;
52 const int64 kSettingsCheckinInterval = 16 * 60 * 60; 55 const int64_t kSettingsCheckinInterval = 16 * 60 * 60;
53 const char kAppId[] = "app_id"; 56 const char kAppId[] = "app_id";
54 const char kSender[] = "project_id"; 57 const char kSender[] = "project_id";
55 const char kSender2[] = "project_id2"; 58 const char kSender2[] = "project_id2";
56 const char kSender3[] = "project_id3"; 59 const char kSender3[] = "project_id3";
57 const char kRegistrationResponsePrefix[] = "token="; 60 const char kRegistrationResponsePrefix[] = "token=";
58 const char kUnregistrationResponsePrefix[] = "deleted="; 61 const char kUnregistrationResponsePrefix[] = "deleted=";
59 const char kRawData[] = "example raw data"; 62 const char kRawData[] = "example raw data";
60 63
61 const char kInstanceID[] = "iid_1"; 64 const char kInstanceID[] = "iid_1";
62 const char kScope[] = "GCM"; 65 const char kScope[] = "GCM";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 return email_token_map; 103 return email_token_map;
101 } 104 }
102 105
103 class FakeMCSClient : public MCSClient { 106 class FakeMCSClient : public MCSClient {
104 public: 107 public:
105 FakeMCSClient(base::Clock* clock, 108 FakeMCSClient(base::Clock* clock,
106 ConnectionFactory* connection_factory, 109 ConnectionFactory* connection_factory,
107 GCMStore* gcm_store, 110 GCMStore* gcm_store,
108 GCMStatsRecorder* recorder); 111 GCMStatsRecorder* recorder);
109 ~FakeMCSClient() override; 112 ~FakeMCSClient() override;
110 void Login(uint64 android_id, uint64 security_token) override; 113 void Login(uint64_t android_id, uint64_t security_token) override;
111 void SendMessage(const MCSMessage& message) override; 114 void SendMessage(const MCSMessage& message) override;
112 115
113 uint64 last_android_id() const { return last_android_id_; } 116 uint64_t last_android_id() const { return last_android_id_; }
114 uint64 last_security_token() const { return last_security_token_; } 117 uint64_t last_security_token() const { return last_security_token_; }
115 uint8 last_message_tag() const { return last_message_tag_; } 118 uint8_t last_message_tag() const { return last_message_tag_; }
116 const mcs_proto::DataMessageStanza& last_data_message_stanza() const { 119 const mcs_proto::DataMessageStanza& last_data_message_stanza() const {
117 return last_data_message_stanza_; 120 return last_data_message_stanza_;
118 } 121 }
119 122
120 private: 123 private:
121 uint64 last_android_id_; 124 uint64_t last_android_id_;
122 uint64 last_security_token_; 125 uint64_t last_security_token_;
123 uint8 last_message_tag_; 126 uint8_t last_message_tag_;
124 mcs_proto::DataMessageStanza last_data_message_stanza_; 127 mcs_proto::DataMessageStanza last_data_message_stanza_;
125 }; 128 };
126 129
127 FakeMCSClient::FakeMCSClient(base::Clock* clock, 130 FakeMCSClient::FakeMCSClient(base::Clock* clock,
128 ConnectionFactory* connection_factory, 131 ConnectionFactory* connection_factory,
129 GCMStore* gcm_store, 132 GCMStore* gcm_store,
130 GCMStatsRecorder* recorder) 133 GCMStatsRecorder* recorder)
131 : MCSClient("", clock, connection_factory, gcm_store, recorder), 134 : MCSClient("", clock, connection_factory, gcm_store, recorder),
132 last_android_id_(0u), 135 last_android_id_(0u),
133 last_security_token_(0u), 136 last_security_token_(0u),
134 last_message_tag_(kNumProtoTypes) { 137 last_message_tag_(kNumProtoTypes) {
135 } 138 }
136 139
137 FakeMCSClient::~FakeMCSClient() { 140 FakeMCSClient::~FakeMCSClient() {
138 } 141 }
139 142
140 void FakeMCSClient::Login(uint64 android_id, uint64 security_token) { 143 void FakeMCSClient::Login(uint64_t android_id, uint64_t security_token) {
141 last_android_id_ = android_id; 144 last_android_id_ = android_id;
142 last_security_token_ = security_token; 145 last_security_token_ = security_token;
143 } 146 }
144 147
145 void FakeMCSClient::SendMessage(const MCSMessage& message) { 148 void FakeMCSClient::SendMessage(const MCSMessage& message) {
146 last_message_tag_ = message.tag(); 149 last_message_tag_ = message.tag();
147 if (last_message_tag_ == kDataMessageStanzaTag) { 150 if (last_message_tag_ == kDataMessageStanzaTag) {
148 last_data_message_stanza_.CopyFrom( 151 last_data_message_stanza_.CopyFrom(
149 reinterpret_cast<const mcs_proto::DataMessageStanza&>( 152 reinterpret_cast<const mcs_proto::DataMessageStanza&>(
150 message.GetProtobuf())); 153 message.GetProtobuf()));
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 void InitializeGCMClient(); 258 void InitializeGCMClient();
256 void StartGCMClient(); 259 void StartGCMClient();
257 void Register(const std::string& app_id, 260 void Register(const std::string& app_id,
258 const std::vector<std::string>& senders); 261 const std::vector<std::string>& senders);
259 void Unregister(const std::string& app_id); 262 void Unregister(const std::string& app_id);
260 void ReceiveMessageFromMCS(const MCSMessage& message); 263 void ReceiveMessageFromMCS(const MCSMessage& message);
261 void ReceiveOnMessageSentToMCS( 264 void ReceiveOnMessageSentToMCS(
262 const std::string& app_id, 265 const std::string& app_id,
263 const std::string& message_id, 266 const std::string& message_id,
264 const MCSClient::MessageSendStatus status); 267 const MCSClient::MessageSendStatus status);
265 void CompleteCheckin(uint64 android_id, 268 void CompleteCheckin(uint64_t android_id,
266 uint64 security_token, 269 uint64_t security_token,
267 const std::string& digest, 270 const std::string& digest,
268 const std::map<std::string, std::string>& settings); 271 const std::map<std::string, std::string>& settings);
269 void CompleteRegistration(const std::string& registration_id); 272 void CompleteRegistration(const std::string& registration_id);
270 void CompleteUnregistration(const std::string& app_id); 273 void CompleteUnregistration(const std::string& app_id);
271 void VerifyPendingRequestFetcherDeleted(); 274 void VerifyPendingRequestFetcherDeleted();
272 275
273 bool ExistsRegistration(const std::string& app_id) const; 276 bool ExistsRegistration(const std::string& app_id) const;
274 void AddRegistration(const std::string& app_id, 277 void AddRegistration(const std::string& app_id,
275 const std::vector<std::string>& sender_ids, 278 const std::vector<std::string>& sender_ids,
276 const std::string& registration_id); 279 const std::string& registration_id);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 return temp_directory_.path(); 353 return temp_directory_.path();
351 } 354 }
352 355
353 base::FilePath gcm_store_path() const { 356 base::FilePath gcm_store_path() const {
354 // Pass an non-existent directory as store path to match the exact 357 // Pass an non-existent directory as store path to match the exact
355 // behavior in the production code. Currently GCMStoreImpl checks if 358 // behavior in the production code. Currently GCMStoreImpl checks if
356 // the directory exist or not to determine the store existence. 359 // the directory exist or not to determine the store existence.
357 return temp_directory_.path().Append(FILE_PATH_LITERAL("GCM Store")); 360 return temp_directory_.path().Append(FILE_PATH_LITERAL("GCM Store"));
358 } 361 }
359 362
360 int64 CurrentTime(); 363 int64_t CurrentTime();
361 364
362 // Tooling. 365 // Tooling.
363 void PumpLoopUntilIdle(); 366 void PumpLoopUntilIdle();
364 bool CreateUniqueTempDir(); 367 bool CreateUniqueTempDir();
365 AutoAdvancingTestClock* clock() const { 368 AutoAdvancingTestClock* clock() const {
366 return reinterpret_cast<AutoAdvancingTestClock*>(gcm_client_->clock_.get()); 369 return reinterpret_cast<AutoAdvancingTestClock*>(gcm_client_->clock_.get());
367 } 370 }
368 net::TestURLFetcherFactory* url_fetcher_factory() { 371 net::TestURLFetcherFactory* url_fetcher_factory() {
369 return &url_fetcher_factory_; 372 return &url_fetcher_factory_;
370 } 373 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 bool GCMClientImplTest::CreateUniqueTempDir() { 437 bool GCMClientImplTest::CreateUniqueTempDir() {
435 return temp_directory_.CreateUniqueTempDir(); 438 return temp_directory_.CreateUniqueTempDir();
436 } 439 }
437 440
438 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) { 441 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) {
439 gcm_client_.reset(new GCMClientImpl(make_scoped_ptr<GCMInternalsBuilder>( 442 gcm_client_.reset(new GCMClientImpl(make_scoped_ptr<GCMInternalsBuilder>(
440 new FakeGCMInternalsBuilder(clock_step)))); 443 new FakeGCMInternalsBuilder(clock_step))));
441 } 444 }
442 445
443 void GCMClientImplTest::CompleteCheckin( 446 void GCMClientImplTest::CompleteCheckin(
444 uint64 android_id, 447 uint64_t android_id,
445 uint64 security_token, 448 uint64_t security_token,
446 const std::string& digest, 449 const std::string& digest,
447 const std::map<std::string, std::string>& settings) { 450 const std::map<std::string, std::string>& settings) {
448 checkin_proto::AndroidCheckinResponse response; 451 checkin_proto::AndroidCheckinResponse response;
449 response.set_stats_ok(true); 452 response.set_stats_ok(true);
450 response.set_android_id(android_id); 453 response.set_android_id(android_id);
451 response.set_security_token(security_token); 454 response.set_security_token(security_token);
452 455
453 // For testing G-services settings. 456 // For testing G-services settings.
454 if (!digest.empty()) { 457 if (!digest.empty()) {
455 response.set_digest(digest); 458 response.set_digest(digest);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 last_error_details_ = send_error_details; 620 last_error_details_ = send_error_details;
618 } 621 }
619 622
620 void GCMClientImplTest::OnSendAcknowledged(const std::string& app_id, 623 void GCMClientImplTest::OnSendAcknowledged(const std::string& app_id,
621 const std::string& message_id) { 624 const std::string& message_id) {
622 last_event_ = MESSAGE_SEND_ACK; 625 last_event_ = MESSAGE_SEND_ACK;
623 last_app_id_ = app_id; 626 last_app_id_ = app_id;
624 last_message_id_ = message_id; 627 last_message_id_ = message_id;
625 } 628 }
626 629
627 int64 GCMClientImplTest::CurrentTime() { 630 int64_t GCMClientImplTest::CurrentTime() {
628 return clock()->Now().ToInternalValue() / base::Time::kMicrosecondsPerSecond; 631 return clock()->Now().ToInternalValue() / base::Time::kMicrosecondsPerSecond;
629 } 632 }
630 633
631 TEST_F(GCMClientImplTest, LoadingCompleted) { 634 TEST_F(GCMClientImplTest, LoadingCompleted) {
632 EXPECT_EQ(LOADING_COMPLETED, last_event()); 635 EXPECT_EQ(LOADING_COMPLETED, last_event());
633 EXPECT_EQ(kDeviceAndroidId, mcs_client()->last_android_id()); 636 EXPECT_EQ(kDeviceAndroidId, mcs_client()->last_android_id());
634 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token()); 637 EXPECT_EQ(kDeviceSecurityToken, mcs_client()->last_security_token());
635 638
636 // Checking freshly loaded CheckinInfo. 639 // Checking freshly loaded CheckinInfo.
637 EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id); 640 EXPECT_EQ(kDeviceAndroidId, device_checkin_info().android_id);
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 // No need to call CompleteDeleteToken since unregistration request should 1646 // No need to call CompleteDeleteToken since unregistration request should
1644 // not be triggered. 1647 // not be triggered.
1645 PumpLoopUntilIdle(); 1648 PumpLoopUntilIdle();
1646 1649
1647 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event()); 1650 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event());
1648 EXPECT_EQ(kAppId, last_app_id()); 1651 EXPECT_EQ(kAppId, last_app_id());
1649 EXPECT_EQ(GCMClient::SUCCESS, last_result()); 1652 EXPECT_EQ(GCMClient::SUCCESS, last_result());
1650 } 1653 }
1651 1654
1652 } // namespace gcm 1655 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_client_impl.cc ('k') | components/gcm_driver/gcm_connection_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698