Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/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/test/simple_test_clock.h" | 11 #include "base/test/simple_test_clock.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/protocol/android_checkin.pb.h" | 16 #include "google_apis/gcm/protocol/android_checkin.pb.h" |
| 17 #include "google_apis/gcm/protocol/checkin.pb.h" | 17 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 18 #include "google_apis/gcm/protocol/mcs.pb.h" | 18 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 19 #include "net/url_request/test_url_fetcher_factory.h" | 19 #include "net/url_request/test_url_fetcher_factory.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 20 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 GCMClientImplTest::GCMClientImplTest() | 260 GCMClientImplTest::GCMClientImplTest() |
| 261 : last_event_(NONE), | 261 : last_event_(NONE), |
| 262 last_result_(GCMClient::UNKNOWN_ERROR), | 262 last_result_(GCMClient::UNKNOWN_ERROR), |
| 263 url_request_context_getter_(new net::TestURLRequestContextGetter( | 263 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 264 message_loop_.message_loop_proxy())) { | 264 message_loop_.message_loop_proxy())) { |
| 265 } | 265 } |
| 266 | 266 |
| 267 GCMClientImplTest::~GCMClientImplTest() {} | 267 GCMClientImplTest::~GCMClientImplTest() {} |
| 268 | 268 |
| 269 void GCMClientImplTest::SetUp() { | 269 void GCMClientImplTest::SetUp() { |
| 270 base::CommandLine::ForCurrentProcess()->AppendSwitch("use-mock-keychain"); | |
|
jianli
2014/04/10 18:38:12
better call testing::Test::SetUp();.
| |
| 270 ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); | 271 ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); |
| 271 run_loop_.reset(new base::RunLoop); | 272 run_loop_.reset(new base::RunLoop); |
| 272 BuildGCMClient(); | 273 BuildGCMClient(); |
| 273 InitializeGCMClient(); | 274 InitializeGCMClient(); |
| 274 CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken); | 275 CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken); |
| 275 } | 276 } |
| 276 | 277 |
| 277 void GCMClientImplTest::PumpLoop() { | 278 void GCMClientImplTest::PumpLoop() { |
| 278 run_loop_->Run(); | 279 run_loop_->Run(); |
| 279 run_loop_.reset(new base::RunLoop()); | 280 run_loop_.reset(new base::RunLoop()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 | 356 |
| 356 // Actual initialization. | 357 // Actual initialization. |
| 357 checkin_proto::ChromeBuildProto chrome_build_proto; | 358 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 358 gcm_client_->Initialize(chrome_build_proto, | 359 gcm_client_->Initialize(chrome_build_proto, |
| 359 temp_directory_.path(), | 360 temp_directory_.path(), |
| 360 std::vector<std::string>(), | 361 std::vector<std::string>(), |
| 361 message_loop_.message_loop_proxy(), | 362 message_loop_.message_loop_proxy(), |
| 362 url_request_context_getter_, | 363 url_request_context_getter_, |
| 363 this); | 364 this); |
| 364 | 365 |
| 365 #if defined(OS_MACOSX) | |
| 366 // On OSX, prevent the Keychain permissions popup during unit tests. | |
| 367 OSCrypt::UseMockKeychain(true); // Must be after Initialize. | |
| 368 #endif | |
| 369 | |
| 370 // Start loading and check-in. | 366 // Start loading and check-in. |
| 371 gcm_client_->Load(); | 367 gcm_client_->Load(); |
| 372 | 368 |
| 373 PumpLoopUntilIdle(); | 369 PumpLoopUntilIdle(); |
| 374 } | 370 } |
| 375 | 371 |
| 376 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { | 372 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { |
| 377 gcm_client_->OnMessageReceivedFromMCS(message); | 373 gcm_client_->OnMessageReceivedFromMCS(message); |
| 378 } | 374 } |
| 379 | 375 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); | 585 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); |
| 590 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); | 586 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); |
| 591 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); | 587 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); |
| 592 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); | 588 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); |
| 593 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); | 589 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); |
| 594 EXPECT_EQ("value", | 590 EXPECT_EQ("value", |
| 595 mcs_client()->last_data_message_stanza().app_data(0).value()); | 591 mcs_client()->last_data_message_stanza().app_data(0).value()); |
| 596 } | 592 } |
| 597 | 593 |
| 598 } // namespace gcm | 594 } // namespace gcm |
| OLD | NEW |