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 "components/gcm_driver/gcm_client_impl.h" | 5 #include "components/gcm_driver/gcm_client_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
14 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
15 #include "base/time/clock.h" | 14 #include "base/time/clock.h" |
16 #include "base/timer/timer.h" | 15 #include "base/timer/timer.h" |
17 #include "google_apis/gcm/base/fake_encryptor.h" | 16 #include "google_apis/gcm/base/fake_encryptor.h" |
18 #include "google_apis/gcm/base/mcs_message.h" | 17 #include "google_apis/gcm/base/mcs_message.h" |
19 #include "google_apis/gcm/base/mcs_util.h" | 18 #include "google_apis/gcm/base/mcs_util.h" |
20 #include "google_apis/gcm/engine/fake_connection_factory.h" | 19 #include "google_apis/gcm/engine/fake_connection_factory.h" |
21 #include "google_apis/gcm/engine/fake_connection_handler.h" | 20 #include "google_apis/gcm/engine/fake_connection_handler.h" |
22 #include "google_apis/gcm/engine/gservices_settings.h" | 21 #include "google_apis/gcm/engine/gservices_settings.h" |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 net::TestURLFetcherFactory url_fetcher_factory_; | 384 net::TestURLFetcherFactory url_fetcher_factory_; |
386 | 385 |
387 // Injected to GCM client: | 386 // Injected to GCM client: |
388 base::ScopedTempDir temp_directory_; | 387 base::ScopedTempDir temp_directory_; |
389 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; | 388 scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_; |
390 }; | 389 }; |
391 | 390 |
392 GCMClientImplTest::GCMClientImplTest() | 391 GCMClientImplTest::GCMClientImplTest() |
393 : last_event_(NONE), | 392 : last_event_(NONE), |
394 last_result_(GCMClient::UNKNOWN_ERROR), | 393 last_result_(GCMClient::UNKNOWN_ERROR), |
395 url_request_context_getter_(new net::TestURLRequestContextGetter( | 394 url_request_context_getter_( |
396 message_loop_.message_loop_proxy())) { | 395 new net::TestURLRequestContextGetter(message_loop_.task_runner())) { |
397 } | 396 } |
398 | 397 |
399 GCMClientImplTest::~GCMClientImplTest() {} | 398 GCMClientImplTest::~GCMClientImplTest() {} |
400 | 399 |
401 void GCMClientImplTest::SetUp() { | 400 void GCMClientImplTest::SetUp() { |
402 testing::Test::SetUp(); | 401 testing::Test::SetUp(); |
403 ASSERT_TRUE(CreateUniqueTempDir()); | 402 ASSERT_TRUE(CreateUniqueTempDir()); |
404 InitializeLoop(); | 403 InitializeLoop(); |
405 BuildGCMClient(base::TimeDelta()); | 404 BuildGCMClient(base::TimeDelta()); |
406 InitializeGCMClient(); | 405 InitializeGCMClient(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 registration->sender_ids = sender_ids; | 517 registration->sender_ids = sender_ids; |
519 gcm_client_->registrations_[registration] = registration_id; | 518 gcm_client_->registrations_[registration] = registration_id; |
520 } | 519 } |
521 | 520 |
522 void GCMClientImplTest::InitializeGCMClient() { | 521 void GCMClientImplTest::InitializeGCMClient() { |
523 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); | 522 clock()->Advance(base::TimeDelta::FromMilliseconds(1)); |
524 | 523 |
525 // Actual initialization. | 524 // Actual initialization. |
526 GCMClient::ChromeBuildInfo chrome_build_info; | 525 GCMClient::ChromeBuildInfo chrome_build_info; |
527 chrome_build_info.version = kChromeVersion; | 526 chrome_build_info.version = kChromeVersion; |
528 gcm_client_->Initialize(chrome_build_info, | 527 gcm_client_->Initialize(chrome_build_info, temp_directory_.path(), |
529 temp_directory_.path(), | 528 message_loop_.task_runner(), |
530 message_loop_.message_loop_proxy(), | |
531 url_request_context_getter_, | 529 url_request_context_getter_, |
532 make_scoped_ptr<Encryptor>(new FakeEncryptor), | 530 make_scoped_ptr<Encryptor>(new FakeEncryptor), this); |
533 this); | |
534 } | 531 } |
535 | 532 |
536 void GCMClientImplTest::StartGCMClient() { | 533 void GCMClientImplTest::StartGCMClient() { |
537 // Start loading and check-in. | 534 // Start loading and check-in. |
538 gcm_client_->Start(GCMClient::IMMEDIATE_START); | 535 gcm_client_->Start(GCMClient::IMMEDIATE_START); |
539 | 536 |
540 PumpLoopUntilIdle(); | 537 PumpLoopUntilIdle(); |
541 } | 538 } |
542 | 539 |
543 void GCMClientImplTest::Register(const std::string& app_id, | 540 void GCMClientImplTest::Register(const std::string& app_id, |
(...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1420 | 1417 |
1421 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event()); | 1418 EXPECT_EQ(UNREGISTRATION_COMPLETED, last_event()); |
1422 EXPECT_EQ(kAppId, last_app_id()); | 1419 EXPECT_EQ(kAppId, last_app_id()); |
1423 EXPECT_EQ(GCMClient::SUCCESS, last_result()); | 1420 EXPECT_EQ(GCMClient::SUCCESS, last_result()); |
1424 // All tokens are gone now. | 1421 // All tokens are gone now. |
1425 EXPECT_FALSE(ExistsToken(kAppId, kSender, kScope)); | 1422 EXPECT_FALSE(ExistsToken(kAppId, kSender, kScope)); |
1426 EXPECT_FALSE(ExistsToken(kAppId, kSender, kScope)); | 1423 EXPECT_FALSE(ExistsToken(kAppId, kSender, kScope)); |
1427 } | 1424 } |
1428 | 1425 |
1429 } // namespace gcm | 1426 } // namespace gcm |
OLD | NEW |