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_account_mapper.h" | 5 #include "components/gcm_driver/gcm_account_mapper.h" |
6 | 6 |
7 #include "base/test/simple_test_clock.h" | 7 #include "base/test/simple_test_clock.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "components/gcm_driver/fake_gcm_driver.h" | 9 #include "components/gcm_driver/fake_gcm_driver.h" |
10 #include "google_apis/gcm/engine/account_mapping.h" | 10 #include "google_apis/gcm/engine/account_mapping.h" |
11 #include "google_apis/gcm/engine/gcm_store.h" | 11 #include "google_apis/gcm/engine/gcm_store.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace gcm { | 14 namespace gcm { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 const char kGCMAccountMapperSenderId[] = "745476177629"; | 18 const char kGCMAccountMapperSenderId[] = "745476177629"; |
19 const char kGCMAccountMapperAppId[] = "com.google.android.gms"; | |
20 const char kRegistrationId[] = "reg_id"; | 19 const char kRegistrationId[] = "reg_id"; |
21 | 20 |
22 AccountMapping MakeAccountMapping(const std::string& account_id, | 21 AccountMapping MakeAccountMapping(const std::string& account_id, |
23 AccountMapping::MappingStatus status, | 22 AccountMapping::MappingStatus status, |
24 const base::Time& status_change_timestamp, | 23 const base::Time& status_change_timestamp, |
25 const std::string& last_message_id) { | 24 const std::string& last_message_id) { |
26 AccountMapping account_mapping; | 25 AccountMapping account_mapping; |
27 account_mapping.account_id = account_id; | 26 account_mapping.account_id = account_id; |
28 account_mapping.email = account_id + "@gmail.com"; | 27 account_mapping.email = account_id + "@gmail.com"; |
29 // account_mapping.access_token intentionally left empty. | 28 // account_mapping.access_token intentionally left empty. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 GCMAccountMapperTest::GCMAccountMapperTest() { | 264 GCMAccountMapperTest::GCMAccountMapperTest() { |
266 Restart(); | 265 Restart(); |
267 } | 266 } |
268 | 267 |
269 GCMAccountMapperTest::~GCMAccountMapperTest() { | 268 GCMAccountMapperTest::~GCMAccountMapperTest() { |
270 } | 269 } |
271 | 270 |
272 void GCMAccountMapperTest::Restart() { | 271 void GCMAccountMapperTest::Restart() { |
273 if (account_mapper_) | 272 if (account_mapper_) |
274 account_mapper_->ShutdownHandler(); | 273 account_mapper_->ShutdownHandler(); |
| 274 gcm_driver_.RemoveAppHandler(kGCMAccountMapperAppId); |
275 account_mapper_.reset(new GCMAccountMapper(&gcm_driver_)); | 275 account_mapper_.reset(new GCMAccountMapper(&gcm_driver_)); |
276 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); | 276 scoped_ptr<base::SimpleTestClock> clock(new base::SimpleTestClock); |
277 clock_ = clock.get(); | 277 clock_ = clock.get(); |
278 account_mapper_->SetClockForTesting(clock.PassAs<base::Clock>()); | 278 account_mapper_->SetClockForTesting(clock.PassAs<base::Clock>()); |
279 } | 279 } |
280 | 280 |
281 // Tests the initialization of account mappings (from the store) when empty. | 281 // Tests the initialization of account mappings (from the store) when empty. |
282 // It also checks that initialization triggers registration ID request. | 282 // It also checks that initialization triggers registration ID request. |
283 TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) { | 283 TEST_F(GCMAccountMapperTest, InitializeAccountMappingsEmpty) { |
284 EXPECT_FALSE(gcm_driver().registration_id_requested()); | 284 EXPECT_FALSE(gcm_driver().registration_id_requested()); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
897 expected_mappings[1].status_change_timestamp = clock()->Now(); | 897 expected_mappings[1].status_change_timestamp = clock()->Now(); |
898 expected_mappings[1].status = AccountMapping::MAPPED; | 898 expected_mappings[1].status = AccountMapping::MAPPED; |
899 expected_mappings[2].status_change_timestamp = clock()->Now(); | 899 expected_mappings[2].status_change_timestamp = clock()->Now(); |
900 expected_mappings[2].status = AccountMapping::MAPPED; | 900 expected_mappings[2].status = AccountMapping::MAPPED; |
901 | 901 |
902 VerifyMappings( | 902 VerifyMappings( |
903 expected_mappings, GetAccounts(), "Step 6, Three mapped accounts"); | 903 expected_mappings, GetAccounts(), "Step 6, Three mapped accounts"); |
904 } | 904 } |
905 | 905 |
906 } // namespace gcm | 906 } // namespace gcm |
OLD | NEW |