| 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/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/time/clock.h" | 12 #include "base/time/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_message.h" | 14 #include "google_apis/gcm/base/mcs_message.h" |
| 15 #include "google_apis/gcm/base/mcs_util.h" | 15 #include "google_apis/gcm/base/mcs_util.h" |
| 16 #include "google_apis/gcm/engine/fake_connection_factory.h" | 16 #include "google_apis/gcm/engine/fake_connection_factory.h" |
| 17 #include "google_apis/gcm/engine/fake_connection_handler.h" | 17 #include "google_apis/gcm/engine/fake_connection_handler.h" |
| 18 #include "google_apis/gcm/engine/gservices_settings.h" | 18 #include "google_apis/gcm/engine/gservices_settings.h" |
| 19 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 19 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 20 #include "google_apis/gcm/protocol/android_checkin.pb.h" | 20 #include "google_apis/gcm/protocol/android_checkin.pb.h" |
| 21 #include "google_apis/gcm/protocol/checkin.pb.h" | 21 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 22 #include "google_apis/gcm/protocol/mcs.pb.h" | 22 #include "google_apis/gcm/protocol/mcs.pb.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 23 #include "net/url_request/test_url_fetcher_factory.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 : last_event_(NONE), | 323 : last_event_(NONE), |
| 324 last_result_(GCMClient::UNKNOWN_ERROR), | 324 last_result_(GCMClient::UNKNOWN_ERROR), |
| 325 url_request_context_getter_(new net::TestURLRequestContextGetter( | 325 url_request_context_getter_(new net::TestURLRequestContextGetter( |
| 326 message_loop_.message_loop_proxy())) { | 326 message_loop_.message_loop_proxy())) { |
| 327 } | 327 } |
| 328 | 328 |
| 329 GCMClientImplTest::~GCMClientImplTest() {} | 329 GCMClientImplTest::~GCMClientImplTest() {} |
| 330 | 330 |
| 331 void GCMClientImplTest::SetUp() { | 331 void GCMClientImplTest::SetUp() { |
| 332 testing::Test::SetUp(); | 332 testing::Test::SetUp(); |
| 333 #if defined(OS_MACOSX) | |
| 334 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 335 os_crypt::switches::kUseMockKeychain); | |
| 336 #endif // OS_MACOSX | |
| 337 ASSERT_TRUE(CreateUniqueTempDir()); | 333 ASSERT_TRUE(CreateUniqueTempDir()); |
| 338 InitializeLoop(); | 334 InitializeLoop(); |
| 339 BuildGCMClient(base::TimeDelta()); | 335 BuildGCMClient(base::TimeDelta()); |
| 340 InitializeGCMClient(); | 336 InitializeGCMClient(); |
| 341 CompleteCheckin(kDeviceAndroidId, | 337 CompleteCheckin(kDeviceAndroidId, |
| 342 kDeviceSecurityToken, | 338 kDeviceSecurityToken, |
| 343 std::string(), | 339 std::string(), |
| 344 std::map<std::string, std::string>()); | 340 std::map<std::string, std::string>()); |
| 345 } | 341 } |
| 346 | 342 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 void GCMClientImplTest::InitializeGCMClient() { | 443 void GCMClientImplTest::InitializeGCMClient() { |
| 448 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); | 444 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); |
| 449 | 445 |
| 450 // Actual initialization. | 446 // Actual initialization. |
| 451 checkin_proto::ChromeBuildProto chrome_build_proto; | 447 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 452 gcm_client_->Initialize(chrome_build_proto, | 448 gcm_client_->Initialize(chrome_build_proto, |
| 453 temp_directory_.path(), | 449 temp_directory_.path(), |
| 454 std::vector<std::string>(), | 450 std::vector<std::string>(), |
| 455 message_loop_.message_loop_proxy(), | 451 message_loop_.message_loop_proxy(), |
| 456 url_request_context_getter_, | 452 url_request_context_getter_, |
| 453 make_scoped_ptr<Encryptor>(new FakeEncryptor), |
| 457 this); | 454 this); |
| 458 | 455 |
| 459 // Start loading and check-in. | 456 // Start loading and check-in. |
| 460 gcm_client_->Start(); | 457 gcm_client_->Start(); |
| 461 | 458 |
| 462 PumpLoopUntilIdle(); | 459 PumpLoopUntilIdle(); |
| 463 } | 460 } |
| 464 | 461 |
| 465 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { | 462 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { |
| 466 gcm_client_->OnMessageReceivedFromMCS(message); | 463 gcm_client_->OnMessageReceivedFromMCS(message); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 }; | 692 }; |
| 696 | 693 |
| 697 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { | 694 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { |
| 698 } | 695 } |
| 699 | 696 |
| 700 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { | 697 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { |
| 701 } | 698 } |
| 702 | 699 |
| 703 void GCMClientImplCheckinTest::SetUp() { | 700 void GCMClientImplCheckinTest::SetUp() { |
| 704 testing::Test::SetUp(); | 701 testing::Test::SetUp(); |
| 705 #if defined(OS_MACOSX) | |
| 706 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 707 os_crypt::switches::kUseMockKeychain); | |
| 708 #endif // OS_MACOSX | |
| 709 // Creating unique temp directory that will be used by GCMStore shared between | 702 // Creating unique temp directory that will be used by GCMStore shared between |
| 710 // GCM Client and G-services settings. | 703 // GCM Client and G-services settings. |
| 711 ASSERT_TRUE(CreateUniqueTempDir()); | 704 ASSERT_TRUE(CreateUniqueTempDir()); |
| 712 InitializeLoop(); | 705 InitializeLoop(); |
| 713 // Time will be advancing one hour every time it is checked. | 706 // Time will be advancing one hour every time it is checked. |
| 714 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval)); | 707 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval)); |
| 715 InitializeGCMClient(); | 708 InitializeGCMClient(); |
| 716 } | 709 } |
| 717 | 710 |
| 718 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { | 711 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 gservices_settings().checkin_url()); | 765 gservices_settings().checkin_url()); |
| 773 EXPECT_EQ(GURL("http://alternative.url/registration"), | 766 EXPECT_EQ(GURL("http://alternative.url/registration"), |
| 774 gservices_settings().registration_url()); | 767 gservices_settings().registration_url()); |
| 775 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), | 768 EXPECT_EQ(GURL("https://alternative.gcm.host:7777"), |
| 776 gservices_settings().mcs_main_endpoint()); | 769 gservices_settings().mcs_main_endpoint()); |
| 777 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), | 770 EXPECT_EQ(GURL("https://alternative.gcm.host:443"), |
| 778 gservices_settings().mcs_fallback_endpoint()); | 771 gservices_settings().mcs_fallback_endpoint()); |
| 779 } | 772 } |
| 780 | 773 |
| 781 } // namespace gcm | 774 } // namespace gcm |
| OLD | NEW |