| 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/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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.h" |
| 12 #include "components/os_crypt/os_crypt.h" | |
| 13 #include "google_apis/gcm/base/mcs_util.h" | 12 #include "google_apis/gcm/base/mcs_util.h" |
| 14 #include "google_apis/gcm/engine/fake_connection_factory.h" | 13 #include "google_apis/gcm/engine/fake_connection_factory.h" |
| 15 #include "google_apis/gcm/engine/fake_connection_handler.h" | 14 #include "google_apis/gcm/engine/fake_connection_handler.h" |
| 15 #include "google_apis/gcm/engine/gcm_internals_builder.h" |
| 16 #include "google_apis/gcm/engine/gcm_store_impl.h" | 16 #include "google_apis/gcm/engine/gcm_store_impl.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 18 |
| 19 namespace gcm { | 19 namespace gcm { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 const uint64 kAndroidId = 54321; | 23 const uint64 kAndroidId = 54321; |
| 24 const uint64 kSecurityToken = 12345; | 24 const uint64 kSecurityToken = 12345; |
| 25 | 25 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 MCSClientTest::MCSClientTest() | 138 MCSClientTest::MCSClientTest() |
| 139 : run_loop_(new base::RunLoop()), | 139 : run_loop_(new base::RunLoop()), |
| 140 init_success_(true), | 140 init_success_(true), |
| 141 restored_android_id_(0), | 141 restored_android_id_(0), |
| 142 restored_security_token_(0), | 142 restored_security_token_(0), |
| 143 message_send_status_(MCSClient::SENT) { | 143 message_send_status_(MCSClient::SENT) { |
| 144 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); | 144 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); |
| 145 run_loop_.reset(new base::RunLoop()); | 145 run_loop_.reset(new base::RunLoop()); |
| 146 | |
| 147 // On OSX, prevent the Keychain permissions popup during unit tests. | |
| 148 #if defined(OS_MACOSX) | |
| 149 OSCrypt::UseMockKeychain(true); | |
| 150 #endif | |
| 151 | |
| 152 // Advance the clock to a non-zero time. | 146 // Advance the clock to a non-zero time. |
| 153 clock_.Advance(base::TimeDelta::FromSeconds(1)); | 147 clock_.Advance(base::TimeDelta::FromSeconds(1)); |
| 154 } | 148 } |
| 155 | 149 |
| 156 MCSClientTest::~MCSClientTest() {} | 150 MCSClientTest::~MCSClientTest() {} |
| 157 | 151 |
| 158 void MCSClientTest::BuildMCSClient() { | 152 void MCSClientTest::BuildMCSClient() { |
| 159 gcm_store_.reset(new GCMStoreImpl(true, | 153 GCMInternalsBuilder builder; |
| 160 temp_directory_.path(), | 154 builder.SetUpForTesting(); |
| 161 message_loop_.message_loop_proxy())); | 155 gcm_store_ = builder.BuildGCMStore(temp_directory_.path(), |
| 156 message_loop_.message_loop_proxy()); |
| 162 mcs_client_.reset(new TestMCSClient(&clock_, | 157 mcs_client_.reset(new TestMCSClient(&clock_, |
| 163 &connection_factory_, | 158 &connection_factory_, |
| 164 gcm_store_.get())); | 159 gcm_store_.get())); |
| 165 } | 160 } |
| 166 | 161 |
| 167 void MCSClientTest::InitializeClient() { | 162 void MCSClientTest::InitializeClient() { |
| 168 gcm_store_->Load(base::Bind( | 163 gcm_store_->Load(base::Bind( |
| 169 &MCSClient::Initialize, | 164 &MCSClient::Initialize, |
| 170 base::Unretained(mcs_client_.get()), | 165 base::Unretained(mcs_client_.get()), |
| 171 base::Bind(&MCSClientTest::ErrorCallback, | 166 base::Bind(&MCSClientTest::ErrorCallback, |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 | 777 |
| 783 LoginClient(std::vector<std::string>()); | 778 LoginClient(std::vector<std::string>()); |
| 784 GetFakeHandler()->ExpectOutgoingMessage(message); | 779 GetFakeHandler()->ExpectOutgoingMessage(message); |
| 785 GetFakeHandler()->ExpectOutgoingMessage(message2); | 780 GetFakeHandler()->ExpectOutgoingMessage(message2); |
| 786 PumpLoop(); | 781 PumpLoop(); |
| 787 } | 782 } |
| 788 | 783 |
| 789 } // namespace | 784 } // namespace |
| 790 | 785 |
| 791 } // namespace gcm | 786 } // namespace gcm |
| OLD | NEW |