OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/engine/mcs_client.h" | 5 #include "google_apis/gcm/engine/mcs_client.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/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/test/simple_test_clock.h" | 12 #include "base/test/simple_test_clock.h" |
13 #include "components/os_crypt/os_crypt_switches.h" | 13 #include "google_apis/gcm/base/fake_encryptor.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/engine/gcm_store_impl.h" | 17 #include "google_apis/gcm/engine/gcm_store_impl.h" |
18 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 18 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
20 | 20 |
21 namespace gcm { | 21 namespace gcm { |
22 | 22 |
23 namespace { | 23 namespace { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 const std::string& app_id, | 122 const std::string& app_id, |
123 const std::string& message_id, | 123 const std::string& message_id, |
124 MCSClient::MessageSendStatus status); | 124 MCSClient::MessageSendStatus status); |
125 | 125 |
126 base::SimpleTestClock clock_; | 126 base::SimpleTestClock clock_; |
127 | 127 |
128 base::ScopedTempDir temp_directory_; | 128 base::ScopedTempDir temp_directory_; |
129 base::MessageLoop message_loop_; | 129 base::MessageLoop message_loop_; |
130 scoped_ptr<base::RunLoop> run_loop_; | 130 scoped_ptr<base::RunLoop> run_loop_; |
131 scoped_ptr<GCMStore> gcm_store_; | 131 scoped_ptr<GCMStore> gcm_store_; |
| 132 FakeEncryptor fake_encryptor_; |
132 | 133 |
133 FakeConnectionFactory connection_factory_; | 134 FakeConnectionFactory connection_factory_; |
134 scoped_ptr<TestMCSClient> mcs_client_; | 135 scoped_ptr<TestMCSClient> mcs_client_; |
135 bool init_success_; | 136 bool init_success_; |
136 uint64 restored_android_id_; | 137 uint64 restored_android_id_; |
137 uint64 restored_security_token_; | 138 uint64 restored_security_token_; |
138 scoped_ptr<MCSMessage> received_message_; | 139 scoped_ptr<MCSMessage> received_message_; |
139 std::string sent_message_id_; | 140 std::string sent_message_id_; |
140 MCSClient::MessageSendStatus message_send_status_; | 141 MCSClient::MessageSendStatus message_send_status_; |
141 | 142 |
(...skipping 10 matching lines...) Expand all Loading... |
152 run_loop_.reset(new base::RunLoop()); | 153 run_loop_.reset(new base::RunLoop()); |
153 | 154 |
154 // Advance the clock to a non-zero time. | 155 // Advance the clock to a non-zero time. |
155 clock_.Advance(base::TimeDelta::FromSeconds(1)); | 156 clock_.Advance(base::TimeDelta::FromSeconds(1)); |
156 } | 157 } |
157 | 158 |
158 MCSClientTest::~MCSClientTest() {} | 159 MCSClientTest::~MCSClientTest() {} |
159 | 160 |
160 void MCSClientTest::SetUp() { | 161 void MCSClientTest::SetUp() { |
161 testing::Test::SetUp(); | 162 testing::Test::SetUp(); |
162 #if defined(OS_MACOSX) | |
163 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
164 os_crypt::switches::kUseMockKeychain); | |
165 #endif // OS_MACOSX | |
166 } | 163 } |
167 | 164 |
168 void MCSClientTest::BuildMCSClient() { | 165 void MCSClientTest::BuildMCSClient() { |
169 gcm_store_.reset(new GCMStoreImpl(temp_directory_.path(), | 166 gcm_store_.reset(new GCMStoreImpl(temp_directory_.path(), |
170 message_loop_.message_loop_proxy())); | 167 message_loop_.message_loop_proxy(), |
| 168 &fake_encryptor_)); |
171 mcs_client_.reset(new TestMCSClient(&clock_, | 169 mcs_client_.reset(new TestMCSClient(&clock_, |
172 &connection_factory_, | 170 &connection_factory_, |
173 gcm_store_.get(), | 171 gcm_store_.get(), |
174 &recorder_)); | 172 &recorder_)); |
175 } | 173 } |
176 | 174 |
177 void MCSClientTest::InitializeClient() { | 175 void MCSClientTest::InitializeClient() { |
178 gcm_store_->Load(base::Bind( | 176 gcm_store_->Load(base::Bind( |
179 &MCSClient::Initialize, | 177 &MCSClient::Initialize, |
180 base::Unretained(mcs_client_.get()), | 178 base::Unretained(mcs_client_.get()), |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 | 790 |
793 LoginClient(std::vector<std::string>()); | 791 LoginClient(std::vector<std::string>()); |
794 GetFakeHandler()->ExpectOutgoingMessage(message); | 792 GetFakeHandler()->ExpectOutgoingMessage(message); |
795 GetFakeHandler()->ExpectOutgoingMessage(message2); | 793 GetFakeHandler()->ExpectOutgoingMessage(message2); |
796 PumpLoop(); | 794 PumpLoop(); |
797 } | 795 } |
798 | 796 |
799 } // namespace | 797 } // namespace |
800 | 798 |
801 } // namespace gcm | 799 } // namespace gcm |
OLD | NEW |