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