Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: google_apis/gcm/gcm_client_impl_unittest.cc

Issue 261853012: Componentize GCM Part 1: create GCM component and move some files over (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove os_crypt dependency from google_apis/gcm Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 : last_event_(NONE), 322 : last_event_(NONE),
323 last_result_(GCMClient::UNKNOWN_ERROR), 323 last_result_(GCMClient::UNKNOWN_ERROR),
324 url_request_context_getter_(new net::TestURLRequestContextGetter( 324 url_request_context_getter_(new net::TestURLRequestContextGetter(
325 message_loop_.message_loop_proxy())) { 325 message_loop_.message_loop_proxy())) {
326 } 326 }
327 327
328 GCMClientImplTest::~GCMClientImplTest() {} 328 GCMClientImplTest::~GCMClientImplTest() {}
329 329
330 void GCMClientImplTest::SetUp() { 330 void GCMClientImplTest::SetUp() {
331 testing::Test::SetUp(); 331 testing::Test::SetUp();
332 #if defined(OS_MACOSX)
333 base::CommandLine::ForCurrentProcess()->AppendSwitch(
334 os_crypt::switches::kUseMockKeychain);
335 #endif // OS_MACOSX
336 ASSERT_TRUE(CreateUniqueTempDir()); 332 ASSERT_TRUE(CreateUniqueTempDir());
337 InitializeLoop(); 333 InitializeLoop();
338 BuildGCMClient(base::TimeDelta()); 334 BuildGCMClient(base::TimeDelta());
339 InitializeGCMClient(); 335 InitializeGCMClient();
340 CompleteCheckin(kDeviceAndroidId, 336 CompleteCheckin(kDeviceAndroidId,
341 kDeviceSecurityToken, 337 kDeviceSecurityToken,
342 std::string(), 338 std::string(),
343 std::map<std::string, std::string>()); 339 std::map<std::string, std::string>());
344 } 340 }
345 341
(...skipping 14 matching lines...) Expand all
360 356
361 void GCMClientImplTest::InitializeLoop() { 357 void GCMClientImplTest::InitializeLoop() {
362 run_loop_.reset(new base::RunLoop); 358 run_loop_.reset(new base::RunLoop);
363 } 359 }
364 360
365 bool GCMClientImplTest::CreateUniqueTempDir() { 361 bool GCMClientImplTest::CreateUniqueTempDir() {
366 return temp_directory_.CreateUniqueTempDir(); 362 return temp_directory_.CreateUniqueTempDir();
367 } 363 }
368 364
369 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) { 365 void GCMClientImplTest::BuildGCMClient(base::TimeDelta clock_step) {
370 gcm_client_.reset(new GCMClientImpl(make_scoped_ptr<GCMInternalsBuilder>( 366 gcm_client_.reset(new GCMClientImpl(
371 new FakeGCMInternalsBuilder(clock_step)))); 367 make_scoped_ptr<GCMInternalsBuilder>(
368 new FakeGCMInternalsBuilder(clock_step)),
369 make_scoped_ptr<FakeEncryptor>(new FakeEncryptor)));
372 } 370 }
373 371
374 void GCMClientImplTest::CompleteCheckin( 372 void GCMClientImplTest::CompleteCheckin(
375 uint64 android_id, 373 uint64 android_id,
376 uint64 security_token, 374 uint64 security_token,
377 const std::string& digest, 375 const std::string& digest,
378 const std::map<std::string, std::string>& settings) { 376 const std::map<std::string, std::string>& settings) {
379 checkin_proto::AndroidCheckinResponse response; 377 checkin_proto::AndroidCheckinResponse response;
380 response.set_stats_ok(true); 378 response.set_stats_ok(true);
381 response.set_android_id(android_id); 379 response.set_android_id(android_id);
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 }; 692 };
695 693
696 GCMClientImplCheckinTest::GCMClientImplCheckinTest() { 694 GCMClientImplCheckinTest::GCMClientImplCheckinTest() {
697 } 695 }
698 696
699 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() { 697 GCMClientImplCheckinTest::~GCMClientImplCheckinTest() {
700 } 698 }
701 699
702 void GCMClientImplCheckinTest::SetUp() { 700 void GCMClientImplCheckinTest::SetUp() {
703 testing::Test::SetUp(); 701 testing::Test::SetUp();
704 #if defined(OS_MACOSX)
705 base::CommandLine::ForCurrentProcess()->AppendSwitch(
706 os_crypt::switches::kUseMockKeychain);
707 #endif // OS_MACOSX
708 // 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
709 // GCM Client and G-services settings. 703 // GCM Client and G-services settings.
710 ASSERT_TRUE(CreateUniqueTempDir()); 704 ASSERT_TRUE(CreateUniqueTempDir());
711 InitializeLoop(); 705 InitializeLoop();
712 // Time will be advancing one hour every time it is checked. 706 // Time will be advancing one hour every time it is checked.
713 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval)); 707 BuildGCMClient(base::TimeDelta::FromSeconds(kSettingsCheckinInterval));
714 InitializeGCMClient(); 708 InitializeGCMClient();
715 } 709 }
716 710
717 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) { 711 TEST_F(GCMClientImplCheckinTest, GServicesSettingsAfterInitialCheckin) {
(...skipping 20 matching lines...) Expand all
738 CompleteCheckin( 732 CompleteCheckin(
739 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); 733 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings);
740 EXPECT_EQ(2, clock()->call_count()); 734 EXPECT_EQ(2, clock()->call_count());
741 735
742 PumpLoopUntilIdle(); 736 PumpLoopUntilIdle();
743 CompleteCheckin( 737 CompleteCheckin(
744 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings); 738 kDeviceAndroidId, kDeviceSecurityToken, kSettingsDefaultDigest, settings);
745 } 739 }
746 740
747 } // namespace gcm 741 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698