| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "components/signin/core/browser/account_tracker_service.h" | 12 #include "components/signin/core/browser/account_tracker_service.h" |
| 13 #include "components/signin/core/common/signin_pref_names.h" |
| 13 #include "google_apis/gaia/fake_oauth2_token_service.h" | 14 #include "google_apis/gaia/fake_oauth2_token_service.h" |
| 14 #include "google_apis/gaia/gaia_oauth_client.h" | 15 #include "google_apis/gaia/gaia_oauth_client.h" |
| 15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" | 17 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" | 18 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "net/url_request/url_request_test_util.h" | 19 #include "net/url_request/url_request_test_util.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 public: | 194 public: |
| 194 AccountTrackerServiceTest() {} | 195 AccountTrackerServiceTest() {} |
| 195 | 196 |
| 196 virtual ~AccountTrackerServiceTest() {} | 197 virtual ~AccountTrackerServiceTest() {} |
| 197 | 198 |
| 198 virtual void SetUp() override { | 199 virtual void SetUp() override { |
| 199 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); | 200 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); |
| 200 | 201 |
| 201 pref_service_.registry()->RegisterListPref( | 202 pref_service_.registry()->RegisterListPref( |
| 202 AccountTrackerService::kAccountInfoPref); | 203 AccountTrackerService::kAccountInfoPref); |
| 204 pref_service_.registry()->RegisterIntegerPref( |
| 205 prefs::kAccountIdMigrationState, |
| 206 AccountTrackerService::MIGRATION_NOT_STARTED); |
| 203 | 207 |
| 204 account_tracker_.reset(new AccountTrackerService()); | 208 account_tracker_.reset(new AccountTrackerService()); |
| 205 account_tracker_->Initialize(fake_oauth2_token_service_.get(), | 209 account_tracker_->Initialize(fake_oauth2_token_service_.get(), |
| 206 &pref_service_, | 210 &pref_service_, |
| 207 new net::TestURLRequestContextGetter( | 211 new net::TestURLRequestContextGetter( |
| 208 message_loop_.message_loop_proxy())); | 212 message_loop_.message_loop_proxy())); |
| 209 account_tracker_->AddObserver(&observer_); | 213 account_tracker_->AddObserver(&observer_); |
| 210 } | 214 } |
| 211 | 215 |
| 212 virtual void TearDown() override { | 216 virtual void TearDown() override { |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 504 |
| 501 std::vector<AccountTrackerService::AccountInfo> infos = | 505 std::vector<AccountTrackerService::AccountInfo> infos = |
| 502 tracker.GetAccounts(); | 506 tracker.GetAccounts(); |
| 503 ASSERT_EQ(1u, infos.size()); | 507 ASSERT_EQ(1u, infos.size()); |
| 504 EXPECT_EQ("beta", infos[0].account_id); | 508 EXPECT_EQ("beta", infos[0].account_id); |
| 505 EXPECT_EQ(AccountIdToGaiaId("beta"), infos[0].gaia); | 509 EXPECT_EQ(AccountIdToGaiaId("beta"), infos[0].gaia); |
| 506 EXPECT_EQ(AccountIdToEmail("beta"), infos[0].email); | 510 EXPECT_EQ(AccountIdToEmail("beta"), infos[0].email); |
| 507 tracker.Shutdown(); | 511 tracker.Shutdown(); |
| 508 } | 512 } |
| 509 } | 513 } |
| 514 |
| 515 TEST_F(AccountTrackerServiceTest, SeedAccountInfo) { |
| 516 std::vector<AccountTrackerService::AccountInfo> infos = |
| 517 account_tracker()->GetAccounts(); |
| 518 EXPECT_EQ(0u, infos.size()); |
| 519 |
| 520 const std::string gaia_id = AccountIdToGaiaId("alpha"); |
| 521 const std::string email = AccountIdToEmail("alpha"); |
| 522 const std::string account_id = |
| 523 account_tracker()->PickAccountIdForAccount(gaia_id, email); |
| 524 account_tracker()->SeedAccountInfo(gaia_id, email); |
| 525 |
| 526 infos = account_tracker()->GetAccounts(); |
| 527 EXPECT_EQ(1u, infos.size()); |
| 528 EXPECT_EQ(account_id, infos[0].account_id); |
| 529 EXPECT_EQ(gaia_id, infos[0].gaia); |
| 530 EXPECT_EQ(email, infos[0].email); |
| 531 } |
| OLD | NEW |