| 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 "components/os_crypt/os_crypt_switches.h" |
| 12 #include "google_apis/gcm/base/mcs_message.h" | 13 #include "google_apis/gcm/base/mcs_message.h" |
| 13 #include "google_apis/gcm/base/mcs_util.h" | 14 #include "google_apis/gcm/base/mcs_util.h" |
| 14 #include "google_apis/gcm/engine/fake_connection_factory.h" | 15 #include "google_apis/gcm/engine/fake_connection_factory.h" |
| 15 #include "google_apis/gcm/engine/fake_connection_handler.h" | 16 #include "google_apis/gcm/engine/fake_connection_handler.h" |
| 16 #include "google_apis/gcm/protocol/android_checkin.pb.h" | 17 #include "google_apis/gcm/protocol/android_checkin.pb.h" |
| 17 #include "google_apis/gcm/protocol/checkin.pb.h" | 18 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 18 #include "google_apis/gcm/protocol/mcs.pb.h" | 19 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 19 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
| 20 #include "net/url_request/url_fetcher_delegate.h" | 21 #include "net/url_request/url_fetcher_delegate.h" |
| 21 #include "net/url_request/url_request_test_util.h" | 22 #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() | 261 GCMClientImplTest::GCMClientImplTest() |
| 261 : last_event_(NONE), | 262 : last_event_(NONE), |
| 262 last_result_(GCMClient::UNKNOWN_ERROR), | 263 last_result_(GCMClient::UNKNOWN_ERROR), |
| 263 url_request_context_getter_(new net::TestURLRequestContextGetter( | 264 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 264 message_loop_.message_loop_proxy())) { | 265 message_loop_.message_loop_proxy())) { |
| 265 } | 266 } |
| 266 | 267 |
| 267 GCMClientImplTest::~GCMClientImplTest() {} | 268 GCMClientImplTest::~GCMClientImplTest() {} |
| 268 | 269 |
| 269 void GCMClientImplTest::SetUp() { | 270 void GCMClientImplTest::SetUp() { |
| 271 testing::Test::SetUp(); |
| 272 #if defined(OS_MACOSX) |
| 273 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 274 os_crypt::switches::kUseMockKeychain); |
| 275 #endif // OS_MACOSX |
| 270 ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); | 276 ASSERT_TRUE(temp_directory_.CreateUniqueTempDir()); |
| 271 run_loop_.reset(new base::RunLoop); | 277 run_loop_.reset(new base::RunLoop); |
| 272 BuildGCMClient(); | 278 BuildGCMClient(); |
| 273 InitializeGCMClient(); | 279 InitializeGCMClient(); |
| 274 CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken); | 280 CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken); |
| 275 } | 281 } |
| 276 | 282 |
| 277 void GCMClientImplTest::PumpLoop() { | 283 void GCMClientImplTest::PumpLoop() { |
| 278 run_loop_->Run(); | 284 run_loop_->Run(); |
| 279 run_loop_.reset(new base::RunLoop()); | 285 run_loop_.reset(new base::RunLoop()); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 361 |
| 356 // Actual initialization. | 362 // Actual initialization. |
| 357 checkin_proto::ChromeBuildProto chrome_build_proto; | 363 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 358 gcm_client_->Initialize(chrome_build_proto, | 364 gcm_client_->Initialize(chrome_build_proto, |
| 359 temp_directory_.path(), | 365 temp_directory_.path(), |
| 360 std::vector<std::string>(), | 366 std::vector<std::string>(), |
| 361 message_loop_.message_loop_proxy(), | 367 message_loop_.message_loop_proxy(), |
| 362 url_request_context_getter_, | 368 url_request_context_getter_, |
| 363 this); | 369 this); |
| 364 | 370 |
| 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. | 371 // Start loading and check-in. |
| 371 gcm_client_->Load(); | 372 gcm_client_->Load(); |
| 372 | 373 |
| 373 PumpLoopUntilIdle(); | 374 PumpLoopUntilIdle(); |
| 374 } | 375 } |
| 375 | 376 |
| 376 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { | 377 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { |
| 377 gcm_client_->OnMessageReceivedFromMCS(message); | 378 gcm_client_->OnMessageReceivedFromMCS(message); |
| 378 } | 379 } |
| 379 | 380 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); | 590 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); |
| 590 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); | 591 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); |
| 591 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); | 592 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); |
| 592 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); | 593 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); |
| 593 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); | 594 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); |
| 594 EXPECT_EQ("value", | 595 EXPECT_EQ("value", |
| 595 mcs_client()->last_data_message_stanza().app_data(0).value()); | 596 mcs_client()->last_data_message_stanza().app_data(0).value()); |
| 596 } | 597 } |
| 597 | 598 |
| 598 } // namespace gcm | 599 } // namespace gcm |
| OLD | NEW |