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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
9 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/test/simple_test_clock.h" | 12 #include "base/test/simple_test_clock.h" |
12 #include "components/os_crypt/os_crypt.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/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 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 | 77 |
78 private: | 78 private: |
79 uint32 next_id_; | 79 uint32 next_id_; |
80 }; | 80 }; |
81 | 81 |
82 class MCSClientTest : public testing::Test { | 82 class MCSClientTest : public testing::Test { |
83 public: | 83 public: |
84 MCSClientTest(); | 84 MCSClientTest(); |
85 virtual ~MCSClientTest(); | 85 virtual ~MCSClientTest(); |
86 | 86 |
87 virtual void SetUp() OVERRIDE; | |
88 | |
87 void BuildMCSClient(); | 89 void BuildMCSClient(); |
88 void InitializeClient(); | 90 void InitializeClient(); |
89 void StoreCredentials(); | 91 void StoreCredentials(); |
90 void LoginClient(const std::vector<std::string>& acknowledged_ids); | 92 void LoginClient(const std::vector<std::string>& acknowledged_ids); |
91 | 93 |
92 base::SimpleTestClock* clock() { return &clock_; } | 94 base::SimpleTestClock* clock() { return &clock_; } |
93 TestMCSClient* mcs_client() const { return mcs_client_.get(); } | 95 TestMCSClient* mcs_client() const { return mcs_client_.get(); } |
94 FakeConnectionFactory* connection_factory() { | 96 FakeConnectionFactory* connection_factory() { |
95 return &connection_factory_; | 97 return &connection_factory_; |
96 } | 98 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
137 | 139 |
138 MCSClientTest::MCSClientTest() | 140 MCSClientTest::MCSClientTest() |
139 : run_loop_(new base::RunLoop()), | 141 : run_loop_(new base::RunLoop()), |
140 init_success_(true), | 142 init_success_(true), |
141 restored_android_id_(0), | 143 restored_android_id_(0), |
142 restored_security_token_(0), | 144 restored_security_token_(0), |
143 message_send_status_(MCSClient::SENT) { | 145 message_send_status_(MCSClient::SENT) { |
144 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); | 146 EXPECT_TRUE(temp_directory_.CreateUniqueTempDir()); |
145 run_loop_.reset(new base::RunLoop()); | 147 run_loop_.reset(new base::RunLoop()); |
146 | 148 |
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. | 149 // Advance the clock to a non-zero time. |
153 clock_.Advance(base::TimeDelta::FromSeconds(1)); | 150 clock_.Advance(base::TimeDelta::FromSeconds(1)); |
154 } | 151 } |
155 | 152 |
156 MCSClientTest::~MCSClientTest() {} | 153 MCSClientTest::~MCSClientTest() {} |
157 | 154 |
155 void MCSClientTest::SetUp() { | |
156 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-mock-keychain"); | |
jianli
2014/04/10 18:38:12
nit: better call testing::Test::SetUp()
fgorski
2014/04/10 19:01:15
Done.
| |
157 } | |
158 | |
158 void MCSClientTest::BuildMCSClient() { | 159 void MCSClientTest::BuildMCSClient() { |
159 gcm_store_.reset(new GCMStoreImpl(true, | 160 gcm_store_.reset(new GCMStoreImpl(temp_directory_.path(), |
160 temp_directory_.path(), | |
161 message_loop_.message_loop_proxy())); | 161 message_loop_.message_loop_proxy())); |
162 mcs_client_.reset(new TestMCSClient(&clock_, | 162 mcs_client_.reset(new TestMCSClient(&clock_, |
163 &connection_factory_, | 163 &connection_factory_, |
164 gcm_store_.get())); | 164 gcm_store_.get())); |
165 } | 165 } |
166 | 166 |
167 void MCSClientTest::InitializeClient() { | 167 void MCSClientTest::InitializeClient() { |
168 gcm_store_->Load(base::Bind( | 168 gcm_store_->Load(base::Bind( |
169 &MCSClient::Initialize, | 169 &MCSClient::Initialize, |
170 base::Unretained(mcs_client_.get()), | 170 base::Unretained(mcs_client_.get()), |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
782 | 782 |
783 LoginClient(std::vector<std::string>()); | 783 LoginClient(std::vector<std::string>()); |
784 GetFakeHandler()->ExpectOutgoingMessage(message); | 784 GetFakeHandler()->ExpectOutgoingMessage(message); |
785 GetFakeHandler()->ExpectOutgoingMessage(message2); | 785 GetFakeHandler()->ExpectOutgoingMessage(message2); |
786 PumpLoop(); | 786 PumpLoop(); |
787 } | 787 } |
788 | 788 |
789 } // namespace | 789 } // namespace |
790 | 790 |
791 } // namespace gcm | 791 } // namespace gcm |
OLD | NEW |