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

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

Issue 297303003: Revert of non-new-profile-management creates a "no-op" style account_reconcilor, (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 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/command_line.h"
6 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
7 #include "base/run_loop.h" 6 #include "base/run_loop.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 7 #include "base/time/time.h"
10 #include "chrome/browser/prefs/pref_service_syncable.h"
11 #include "chrome/browser/signin/account_reconcilor_factory.h" 8 #include "chrome/browser/signin/account_reconcilor_factory.h"
12 #include "chrome/browser/signin/chrome_signin_client_factory.h" 9 #include "chrome/browser/signin/chrome_signin_client_factory.h"
13 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
14 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" 11 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h"
15 #include "chrome/browser/signin/fake_signin_manager.h" 12 #include "chrome/browser/signin/fake_signin_manager.h"
16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/signin/signin_manager_factory.h" 14 #include "chrome/browser/signin/signin_manager_factory.h"
18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
20 #include "chrome/test/base/testing_profile_manager.h"
21 #include "components/signin/core/browser/account_reconcilor.h" 16 #include "components/signin/core/browser/account_reconcilor.h"
22 #include "components/signin/core/browser/profile_oauth2_token_service.h" 17 #include "components/signin/core/browser/profile_oauth2_token_service.h"
23 #include "components/signin/core/browser/signin_manager.h" 18 #include "components/signin/core/browser/signin_manager.h"
24 #include "components/signin/core/common/signin_switches.h"
25 #include "content/public/test/test_browser_thread_bundle.h" 19 #include "content/public/test/test_browser_thread_bundle.h"
26 #include "google_apis/gaia/gaia_urls.h" 20 #include "google_apis/gaia/gaia_urls.h"
27 #include "net/url_request/test_url_fetcher_factory.h" 21 #include "net/url_request/test_url_fetcher_factory.h"
28 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
30 24
31 namespace { 25 namespace {
32 26
33 const char kTestEmail[] = "user@gmail.com"; 27 const char kTestEmail[] = "user@gmail.com";
34 28
35 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> { 29 class MockAccountReconcilor : public testing::StrictMock<AccountReconcilor> {
36 public: 30 public:
37 static KeyedService* Build(content::BrowserContext* context); 31 static KeyedService* Build(content::BrowserContext* context);
38 32
39 MockAccountReconcilor(ProfileOAuth2TokenService* token_service, 33 MockAccountReconcilor(ProfileOAuth2TokenService* token_service,
40 SigninManagerBase* signin_manager, 34 SigninManagerBase* signin_manager,
41 SigninClient* client); 35 SigninClient* client);
42 virtual ~MockAccountReconcilor() {} 36 virtual ~MockAccountReconcilor() {}
43 37
44 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id)); 38 MOCK_METHOD1(PerformMergeAction, void(const std::string& account_id));
45 MOCK_METHOD1(PerformStartRemoveAction, void(const std::string& account_id)); 39 MOCK_METHOD1(StartRemoveAction, void(const std::string& account_id));
46 MOCK_METHOD3( 40 MOCK_METHOD3(
47 PerformFinishRemoveAction, 41 FinishRemoveAction,
48 void(const std::string& account_id, 42 void(const std::string& account_id,
49 const GoogleServiceAuthError& error, 43 const GoogleServiceAuthError& error,
50 const std::vector<std::pair<std::string, bool> >& accounts)); 44 const std::vector<std::pair<std::string, bool> >& accounts));
51 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id, 45 MOCK_METHOD2(PerformAddToChromeAction, void(const std::string& account_id,
52 int session_index)); 46 int session_index));
53 MOCK_METHOD0(PerformLogoutAllAccountsAction, void()); 47 MOCK_METHOD0(PerformLogoutAllAccountsAction, void());
54 }; 48 };
55 49
56 // static 50 // static
57 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) { 51 KeyedService* MockAccountReconcilor::Build(content::BrowserContext* context) {
(...skipping 15 matching lines...) Expand all
73 client) {} 67 client) {}
74 68
75 } // namespace 69 } // namespace
76 70
77 class AccountReconcilorTest : public testing::Test { 71 class AccountReconcilorTest : public testing::Test {
78 public: 72 public:
79 AccountReconcilorTest(); 73 AccountReconcilorTest();
80 virtual void SetUp() OVERRIDE; 74 virtual void SetUp() OVERRIDE;
81 virtual void TearDown() OVERRIDE; 75 virtual void TearDown() OVERRIDE;
82 76
83 TestingProfile* profile() { return profile_; } 77 TestingProfile* profile() { return profile_.get(); }
84 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; } 78 FakeSigninManagerForTesting* signin_manager() { return signin_manager_; }
85 FakeProfileOAuth2TokenService* token_service() { return token_service_; } 79 FakeProfileOAuth2TokenService* token_service() { return token_service_; }
86 80
87 void SetFakeResponse(const std::string& url, 81 void SetFakeResponse(const std::string& url,
88 const std::string& data, 82 const std::string& data,
89 net::HttpStatusCode code, 83 net::HttpStatusCode code,
90 net::URLRequestStatus::Status status) { 84 net::URLRequestStatus::Status status) {
91 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status); 85 url_fetcher_factory_.SetFakeResponse(GURL(url), data, code, status);
92 } 86 }
93 87
94 MockAccountReconcilor* GetMockReconcilor(); 88 MockAccountReconcilor* GetMockReconcilor();
95 89
96 void SimulateMergeSessionCompleted( 90 void SimulateMergeSessionCompleted(
97 MergeSessionHelper::Observer* observer, 91 MergeSessionHelper::Observer* observer,
98 const std::string& account_id, 92 const std::string& account_id,
99 const GoogleServiceAuthError& error); 93 const GoogleServiceAuthError& error);
100 94
101 void SimulateRefreshTokenFetched( 95 void SimulateRefreshTokenFetched(
102 AccountReconcilor* reconcilor, 96 AccountReconcilor* reconcilor,
103 const std::string& account_id, 97 const std::string& account_id,
104 const std::string& refresh_token); 98 const std::string& refresh_token);
105 99
106 private: 100 private:
107 content::TestBrowserThreadBundle bundle_; 101 content::TestBrowserThreadBundle bundle_;
108 TestingProfile* profile_; 102 scoped_ptr<TestingProfile> profile_;
109 FakeSigninManagerForTesting* signin_manager_; 103 FakeSigninManagerForTesting* signin_manager_;
110 FakeProfileOAuth2TokenService* token_service_; 104 FakeProfileOAuth2TokenService* token_service_;
111 MockAccountReconcilor* mock_reconcilor_; 105 MockAccountReconcilor* mock_reconcilor_;
112 net::FakeURLFetcherFactory url_fetcher_factory_; 106 net::FakeURLFetcherFactory url_fetcher_factory_;
113 TestingProfileManager* testing_profile_manager_;
114 }; 107 };
115 108
116 AccountReconcilorTest::AccountReconcilorTest() 109 AccountReconcilorTest::AccountReconcilorTest()
117 : signin_manager_(NULL), 110 : signin_manager_(NULL),
118 token_service_(NULL), 111 token_service_(NULL),
119 mock_reconcilor_(NULL), 112 mock_reconcilor_(NULL),
120 url_fetcher_factory_(NULL) {} 113 url_fetcher_factory_(NULL) {}
121 114
122 void AccountReconcilorTest::SetUp() { 115 void AccountReconcilorTest::SetUp() {
123 CommandLine::ForCurrentProcess()->AppendSwitch( 116 TestingProfile::Builder builder;
124 switches::kNewProfileManagement); 117 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
125 118 BuildFakeProfileOAuth2TokenService);
126 testing_profile_manager_ = 119 builder.AddTestingFactory(SigninManagerFactory::GetInstance(),
127 new TestingProfileManager(TestingBrowserProcess::GetGlobal()); 120 FakeSigninManagerBase::Build);
128 ASSERT_TRUE(testing_profile_manager_->SetUp()); 121 builder.AddTestingFactory(AccountReconcilorFactory::GetInstance(),
129 122 MockAccountReconcilor::Build);
130 TestingProfile::TestingFactories factories; 123 profile_ = builder.Build();
131 factories.push_back(std::make_pair(
132 ProfileOAuth2TokenServiceFactory::GetInstance(),
133 BuildFakeProfileOAuth2TokenService));
134 factories.push_back(std::make_pair(SigninManagerFactory::GetInstance(),
135 FakeSigninManagerBase::Build));
136 factories.push_back(std::make_pair(AccountReconcilorFactory::GetInstance(),
137 MockAccountReconcilor::Build));
138
139 profile_ = testing_profile_manager_->CreateTestingProfile("name",
140 scoped_ptr<PrefServiceSyncable>(),
141 base::UTF8ToUTF16("name"), 0, std::string(),
142 factories);
143 124
144 signin_manager_ = 125 signin_manager_ =
145 static_cast<FakeSigninManagerForTesting*>( 126 static_cast<FakeSigninManagerForTesting*>(
146 SigninManagerFactory::GetForProfile(profile())); 127 SigninManagerFactory::GetForProfile(profile()));
147 128
148 token_service_ = 129 token_service_ =
149 static_cast<FakeProfileOAuth2TokenService*>( 130 static_cast<FakeProfileOAuth2TokenService*>(
150 ProfileOAuth2TokenServiceFactory::GetForProfile(profile())); 131 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()));
151 } 132 }
152 133
153 void AccountReconcilorTest::TearDown() { 134 void AccountReconcilorTest::TearDown() {
154 // The |testing_profile_manager_| will handle destroying the profile. 135 // Destroy the profile before all threads are torn down.
155 delete testing_profile_manager_; 136 profile_.reset();
156 } 137 }
157 138
158 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() { 139 MockAccountReconcilor* AccountReconcilorTest::GetMockReconcilor() {
159 if (!mock_reconcilor_) { 140 if (!mock_reconcilor_) {
160 mock_reconcilor_ = 141 mock_reconcilor_ =
161 static_cast<MockAccountReconcilor*>( 142 static_cast<MockAccountReconcilor*>(
162 AccountReconcilorFactory::GetForProfile(profile())); 143 AccountReconcilorFactory::GetForProfile(profile()));
163 } 144 }
164 145
165 return mock_reconcilor_; 146 return mock_reconcilor_;
(...skipping 21 matching lines...) Expand all
187 } 168 }
188 169
189 #if !defined(OS_CHROMEOS) 170 #if !defined(OS_CHROMEOS)
190 171
191 TEST_F(AccountReconcilorTest, SigninManagerRegistration) { 172 TEST_F(AccountReconcilorTest, SigninManagerRegistration) {
192 AccountReconcilor* reconcilor = 173 AccountReconcilor* reconcilor =
193 AccountReconcilorFactory::GetForProfile(profile()); 174 AccountReconcilorFactory::GetForProfile(profile());
194 ASSERT_TRUE(reconcilor); 175 ASSERT_TRUE(reconcilor);
195 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService()); 176 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
196 177
197 signin_manager()->set_password("password");
198 signin_manager()->OnExternalSigninCompleted(kTestEmail); 178 signin_manager()->OnExternalSigninCompleted(kTestEmail);
199 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); 179 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
200 180
201 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction()); 181 EXPECT_CALL(*GetMockReconcilor(), PerformLogoutAllAccountsAction());
202 182
203 signin_manager()->SignOut(); 183 signin_manager()->SignOut();
204 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService()); 184 ASSERT_FALSE(reconcilor->IsRegisteredWithTokenService());
205 } 185 }
206 186
207 TEST_F(AccountReconcilorTest, Reauth) { 187 TEST_F(AccountReconcilorTest, Reauth) {
208 signin_manager()->SetAuthenticatedUsername(kTestEmail); 188 signin_manager()->SetAuthenticatedUsername(kTestEmail);
209 signin_manager()->set_password("password");
210 189
211 AccountReconcilor* reconcilor = 190 AccountReconcilor* reconcilor =
212 AccountReconcilorFactory::GetForProfile(profile()); 191 AccountReconcilorFactory::GetForProfile(profile());
213 ASSERT_TRUE(reconcilor); 192 ASSERT_TRUE(reconcilor);
214 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); 193 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
215 194
216 // Simulate reauth. The state of the reconcilor should not change. 195 // Simulate reauth. The state of the reconcilor should not change.
217 signin_manager()->OnExternalSigninCompleted(kTestEmail); 196 signin_manager()->OnExternalSigninCompleted(kTestEmail);
218 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService()); 197 ASSERT_TRUE(reconcilor->IsRegisteredWithTokenService());
219 } 198 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked()); 415 ASSERT_FALSE(reconcilor->AreAllRefreshTokensChecked());
437 416
438 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 417 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
439 base::Time::Now() + base::TimeDelta::FromHours(1)); 418 base::Time::Now() + base::TimeDelta::FromHours(1));
440 419
441 base::RunLoop().RunUntilIdle(); 420 base::RunLoop().RunUntilIdle();
442 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked()); 421 ASSERT_TRUE(reconcilor->AreAllRefreshTokensChecked());
443 ASSERT_FALSE(reconcilor->is_reconcile_started_); 422 ASSERT_FALSE(reconcilor->is_reconcile_started_);
444 } 423 }
445 424
446
447 TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) { 425 TEST_F(AccountReconcilorTest, StartReconcileAddToCookie) {
448 signin_manager()->SetAuthenticatedUsername("user@gmail.com"); 426 signin_manager()->SetAuthenticatedUsername("user@gmail.com");
449 token_service()->UpdateCredentials("user@gmail.com", "refresh_token"); 427 token_service()->UpdateCredentials("user@gmail.com", "refresh_token");
450 token_service()->UpdateCredentials("other@gmail.com", "refresh_token"); 428 token_service()->UpdateCredentials("other@gmail.com", "refresh_token");
451 429
452 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com")); 430 EXPECT_CALL(*GetMockReconcilor(), PerformMergeAction("other@gmail.com"));
453 431
454 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(), 432 SetFakeResponse(GaiaUrls::GetInstance()->list_accounts_url().spec(),
455 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]", 433 "[\"f\", [[\"b\", 0, \"n\", \"user@gmail.com\", \"p\", 0, 0, 0, 0, 1]]]",
456 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 434 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token", 557 token_service()->IssueAllTokensForAccount("user@gmail.com", "access_token",
580 base::Time::Now() + base::TimeDelta::FromHours(1)); 558 base::Time::Now() + base::TimeDelta::FromHours(1));
581 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token", 559 token_service()->IssueAllTokensForAccount("other@gmail.com", "access_token",
582 base::Time::Now() + base::TimeDelta::FromHours(1)); 560 base::Time::Now() + base::TimeDelta::FromHours(1));
583 561
584 base::RunLoop().RunUntilIdle(); 562 base::RunLoop().RunUntilIdle();
585 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com", 563 SimulateMergeSessionCompleted(reconcilor, "user@gmail.com",
586 GoogleServiceAuthError::AuthErrorNone()); 564 GoogleServiceAuthError::AuthErrorNone());
587 ASSERT_FALSE(reconcilor->is_reconcile_started_); 565 ASSERT_FALSE(reconcilor->is_reconcile_started_);
588 } 566 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | components/signin/core/browser/account_reconcilor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698