| 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/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
| 11 #include "components/os_crypt/os_crypt.h" | |
| 12 #include "google_apis/gcm/base/mcs_message.h" | 11 #include "google_apis/gcm/base/mcs_message.h" |
| 13 #include "google_apis/gcm/base/mcs_util.h" | 12 #include "google_apis/gcm/base/mcs_util.h" |
| 14 #include "google_apis/gcm/engine/fake_connection_factory.h" | 13 #include "google_apis/gcm/engine/fake_connection_factory.h" |
| 15 #include "google_apis/gcm/engine/fake_connection_handler.h" | 14 #include "google_apis/gcm/engine/fake_connection_handler.h" |
| 15 #include "google_apis/gcm/engine/gcm_internals_builder.h" |
| 16 #include "google_apis/gcm/engine/gcm_store_impl.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" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace gcm { | 25 namespace gcm { |
| 25 | 26 |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 run_loop_->RunUntilIdle(); | 284 run_loop_->RunUntilIdle(); |
| 284 run_loop_.reset(new base::RunLoop()); | 285 run_loop_.reset(new base::RunLoop()); |
| 285 } | 286 } |
| 286 | 287 |
| 287 void GCMClientImplTest::QuitLoop() { | 288 void GCMClientImplTest::QuitLoop() { |
| 288 if (run_loop_ && run_loop_->running()) | 289 if (run_loop_ && run_loop_->running()) |
| 289 run_loop_->Quit(); | 290 run_loop_->Quit(); |
| 290 } | 291 } |
| 291 | 292 |
| 292 void GCMClientImplTest::BuildGCMClient() { | 293 void GCMClientImplTest::BuildGCMClient() { |
| 293 gcm_client_.reset(new GCMClientImpl( | 294 scoped_ptr<GCMInternalsBuilder> builder(new FakeGCMInternalsBuilder()); |
| 294 make_scoped_ptr<GCMInternalsBuilder>(new FakeGCMInternalsBuilder()))); | 295 builder->SetUpForTesting(); |
| 296 gcm_client_.reset(new GCMClientImpl(builder.Pass())); |
| 295 } | 297 } |
| 296 | 298 |
| 297 void GCMClientImplTest::CompleteCheckin(uint64 android_id, | 299 void GCMClientImplTest::CompleteCheckin(uint64 android_id, |
| 298 uint64 security_token) { | 300 uint64 security_token) { |
| 299 checkin_proto::AndroidCheckinResponse response; | 301 checkin_proto::AndroidCheckinResponse response; |
| 300 response.set_stats_ok(true); | 302 response.set_stats_ok(true); |
| 301 response.set_android_id(android_id); | 303 response.set_android_id(android_id); |
| 302 response.set_security_token(security_token); | 304 response.set_security_token(security_token); |
| 303 | 305 |
| 304 std::string response_string; | 306 std::string response_string; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 357 |
| 356 // Actual initialization. | 358 // Actual initialization. |
| 357 checkin_proto::ChromeBuildProto chrome_build_proto; | 359 checkin_proto::ChromeBuildProto chrome_build_proto; |
| 358 gcm_client_->Initialize(chrome_build_proto, | 360 gcm_client_->Initialize(chrome_build_proto, |
| 359 temp_directory_.path(), | 361 temp_directory_.path(), |
| 360 std::vector<std::string>(), | 362 std::vector<std::string>(), |
| 361 message_loop_.message_loop_proxy(), | 363 message_loop_.message_loop_proxy(), |
| 362 url_request_context_getter_, | 364 url_request_context_getter_, |
| 363 this); | 365 this); |
| 364 | 366 |
| 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. | 367 // Start loading and check-in. |
| 371 gcm_client_->Load(); | 368 gcm_client_->Load(); |
| 372 | 369 |
| 373 PumpLoopUntilIdle(); | 370 PumpLoopUntilIdle(); |
| 374 } | 371 } |
| 375 | 372 |
| 376 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { | 373 void GCMClientImplTest::ReceiveMessageFromMCS(const MCSMessage& message) { |
| 377 gcm_client_->OnMessageReceivedFromMCS(message); | 374 gcm_client_->OnMessageReceivedFromMCS(message); |
| 378 } | 375 } |
| 379 | 376 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 589 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); | 586 EXPECT_EQ(CurrentTime(), mcs_client()->last_data_message_stanza().sent()); |
| 590 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); | 587 EXPECT_EQ("007", mcs_client()->last_data_message_stanza().id()); |
| 591 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); | 588 EXPECT_EQ("gcm@chrome.com", mcs_client()->last_data_message_stanza().from()); |
| 592 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); | 589 EXPECT_EQ(kSender, mcs_client()->last_data_message_stanza().to()); |
| 593 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); | 590 EXPECT_EQ("key", mcs_client()->last_data_message_stanza().app_data(0).key()); |
| 594 EXPECT_EQ("value", | 591 EXPECT_EQ("value", |
| 595 mcs_client()->last_data_message_stanza().app_data(0).value()); | 592 mcs_client()->last_data_message_stanza().app_data(0).value()); |
| 596 } | 593 } |
| 597 | 594 |
| 598 } // namespace gcm | 595 } // namespace gcm |
| OLD | NEW |