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

Side by Side Diff: chrome/browser/signin/account_reconcilor_unittest.cc

Issue 219933002: Componentize AccountReconcilor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/run_loop.h" 6 #include "base/run_loop.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "chrome/browser/signin/account_reconcilor.h"
9 #include "chrome/browser/signin/account_reconcilor_factory.h" 8 #include "chrome/browser/signin/account_reconcilor_factory.h"
10 #include "chrome/browser/signin/chrome_signin_client_factory.h" 9 #include "chrome/browser/signin/chrome_signin_client_factory.h"
11 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
12 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
13 #include "chrome/browser/signin/fake_signin_manager.h" 12 #include "chrome/browser/signin/fake_signin_manager.h"
14 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
15 #include "chrome/browser/signin/signin_manager_factory.h" 14 #include "chrome/browser/signin/signin_manager_factory.h"
16 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
16 #include "components/signin/core/browser/account_reconcilor.h"
17 #include "components/signin/core/browser/profile_oauth2_token_service.h" 17 #include "components/signin/core/browser/profile_oauth2_token_service.h"
18 #include "components/signin/core/browser/signin_manager.h" 18 #include "components/signin/core/browser/signin_manager.h"
19 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "google_apis/gaia/gaia_urls.h" 20 #include "google_apis/gaia/gaia_urls.h"
21 #include "net/url_request/test_url_fetcher_factory.h" 21 #include "net/url_request/test_url_fetcher_factory.h"
22 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 namespace { 25 namespace {
26 26
27 const char kTestEmail[] = "user@gmail.com"; 27 const char kTestEmail[] = "user@gmail.com";
28 28
29 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { 29 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
30 public: 30 public:
31 static KeyedService* Build(content::BrowserContext* context); 31 static KeyedService* Build(content::BrowserContext* context);
32 32
33 explicit MockAccountReconcilor(Profile* profile, SigninClient* client); 33 MockAccountReconcilor(ProfileOAuth2TokenService* token_service,
34 SigninManager* signin_manager,
35 SigninClient* client);
34 virtual ~MockAccountReconcilor() {} 36 virtual ~MockAccountReconcilor() {}
35 37
36 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); 38 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id));
37 MOCK_METHOD1(StartRemoveAction, void(const std::string& account_id)); 39 MOCK_METHOD1(StartRemoveAction, void(const std::string& account_id));
38 MOCK_METHOD3( 40 MOCK_METHOD3(
39 FinishRemoveAction, 41 FinishRemoveAction,
40 void(const std::string& account_id, 42 void(const std::string& account_id,
41 const GoogleServiceAuthError& error, 43 const GoogleServiceAuthError& error,
42 const std::vector<std::pair<std::string, bool> >& accounts)); 44 const std::vector<std::pair<std::string, bool> >& accounts));
43 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id, 45 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id,
44 int session_index)); 46 int session_index));
45 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); 47 MOCK_METHOD0(PerformLogoutAllAccountsAction, void());
46 }; 48 };
47 49
48 // static 50 // static
49 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) { 51 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) {
50 Profile* profile = Profile::FromBrowserContext(context); 52 Profile* profile = Profile::FromBrowserContext(context);
51 AccountReconcilor* reconcilor = new MockAccountReconcilor( 53 AccountReconcilor* reconcilor = new MockAccountReconcilor(
52 profile, ChromeSigninClientFactory::GetForProfile(profile)); 54 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
55 SigninManagerFactory::GetForProfile(profile),
56 ChromeSigninClientFactory::GetForProfile(profile));
53 reconcilor->Initialize(false /* start_reconcile_if_tokens_available */); 57 reconcilor->Initialize(false /* start_reconcile_if_tokens_available */);
54 return reconcilor; 58 return reconcilor;
55 } 59 }
56 60
57 MockAccountReconcilor::MockAccountReconcilor(Profile* profile, 61 MockAccountReconcilor::MockAccountReconcilor(
58 SigninClient* client) 62 ProfileOAuth2TokenService* token_service,
59 : testing::StrictMock<AccountReconcilor>(profile, client) {} 63 SigninManager* signin_manager,
64 SigninClient* client)
65 : testing::StrictMock<AccountReconcilor>(token_service,
66 signin_manager,
67 client) {}
60 68
61 } // namespace 69 } // namespace
62 70
63 class AccountReconcilorTest : public testing::Test { 71 class AccountReconcilorTest : public testing::Test {
64 public: 72 public:
65 AccountReconcilorTest(); 73 AccountReconcilorTest();
66 virtual void SetUp() OVERRIDE; 74 virtual void SetUp() OVERRIDE;
67 virtual void TearDown() OVERRIDE; 75 virtual void TearDown() OVERRIDE;
68 76
69 TestingProfile* profile() { return profile_.get(); } 77 TestingProfile* profile() { return profile_.get(); }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 AccountReconcilor* reconcilor, 157 AccountReconcilor* reconcilor,
150 const std::string& account_id, 158 const std::string& account_id,
151 const std::string& refresh_token) { 159 const std::string& refresh_token) {
152 reconcilor->HandleRefreshTokenFetched(account_id, refresh_token); 160 reconcilor->HandleRefreshTokenFetched(account_id, refresh_token);
153 } 161 }
154 162
155 TEST_F(AccountReconcilorTest, Basic) { 163 TEST_F(AccountReconcilorTest, Basic) {
156 AccountReconcilor* reconcilor = 164 AccountReconcilor* reconcilor =
157 AccountReconcilorFactory::GetForProfile(profile()); 165 AccountReconcilorFactory::GetForProfile(profile());
158 ASSERT_TRUE(reconcilor); 166 ASSERT_TRUE(reconcilor);
159 ASSERT_EQ(profile(), reconcilor->profile()); 167 ASSERT_EQ(token_service(), reconcilor->token_service());
160 } 168 }
161 169
162 #if !defined(OS_CHROMEOS) 170 #if !defined(OS_CHROMEOS)
163 171
164 TEST_F(AccountReconcilorTest, SigninManagerRegistration) { 172 TEST_F(AccountReconcilorTest, SigninManagerRegistration) {
165 AccountReconcilor* reconcilor = 173 AccountReconcilor* reconcilor =
166 AccountReconcilorFactory::GetForProfile(profile()); 174 AccountReconcilorFactory::GetForProfile(profile());
167 ASSERT_TRUE(reconcilor); 175 ASSERT_TRUE(reconcilor);
168 ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning()); 176 ASSERT_FALSE(reconcilor->IsPeriodicReconciliationRunning());
169 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService()); 177 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 561 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
554 base::Time::Now() + base::TimeDelta::FromHours(1)); 562 base::Time::Now() + base::TimeDelta::FromHours(1));
555 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", 563 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
556 base::Time::Now() + base::TimeDelta::FromHours(1)); 564 base::Time::Now() + base::TimeDelta::FromHours(1));
557 565
558 base::RunLoop().RunUntilIdle(); 566 base::RunLoop().RunUntilIdle();
559 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 567 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
560 GoogleServiceAuthError::AuthErrorNone()); 568 GoogleServiceAuthError::AuthErrorNone());
561 ASSERT_FALSE(reconcilor->is_reconcile_started_); 569 ASSERT_FALSE(reconcilor->is_reconcile_started_);
562 } 570 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698