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

Side by Side Diff: components/signin/core/browser/account_tracker_service_unittest.cc

Issue 1376933005: Reflect email address changes in the Avatar Menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « components/signin/core/browser/account_fetcher_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/prefs/pref_registry_simple.h" 8 #include "base/prefs/pref_registry_simple.h"
9 #include "base/prefs/scoped_user_pref_update.h" 9 #include "base/prefs/scoped_user_pref_update.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 ? testing::AssertionSuccess() 238 ? testing::AssertionSuccess()
239 : (testing::AssertionFailure() 239 : (testing::AssertionFailure()
240 << "Expected " << maybe_newline << Str(events) << ", " 240 << "Expected " << maybe_newline << Str(events) << ", "
241 << maybe_newline << "Got " << maybe_newline << Str(events_))); 241 << maybe_newline << "Got " << maybe_newline << Str(events_)));
242 events_.clear(); 242 events_.clear();
243 return result; 243 return result;
244 } 244 }
245 245
246 } // namespace 246 } // namespace
247 247
248 class InfoMutatingFakeAccountFetcherService : public FakeAccountFetcherService {
249 public:
250 InfoMutatingFakeAccountFetcherService(AccountInfo new_info)
251 : info_(new_info) {}
252
253 void StartFetchingUserInfo(const std::string& account_id) override {
254 // It would make no sense to return an AccountInfo with a different ID.
255 EXPECT_EQ(info_.account_id, account_id);
256 // Immediately fake a response with the provided |info_|.
257 FakeUserInfoFetchSuccess(account_id,
258 info_.email,
259 info_.gaia,
260 info_.hosted_domain,
261 info_.full_name,
262 info_.given_name,
263 info_.locale,
264 info_.picture_url);
265 }
266
267 private:
268 AccountInfo info_;
269 };
270
248 class AccountTrackerServiceTest : public testing::Test { 271 class AccountTrackerServiceTest : public testing::Test {
249 public: 272 public:
250 AccountTrackerServiceTest() {} 273 AccountTrackerServiceTest() {}
251 274
252 ~AccountTrackerServiceTest() override {} 275 ~AccountTrackerServiceTest() override {}
253 276
254 void SetUp() override { 277 void SetUp() override {
255 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); 278 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService());
256 279
257 pref_service_.registry()->RegisterListPref( 280 pref_service_.registry()->RegisterListPref(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 342
320 net::TestURLFetcherFactory* test_fetcher_factory() { 343 net::TestURLFetcherFactory* test_fetcher_factory() {
321 return &test_fetcher_factory_; 344 return &test_fetcher_factory_;
322 } 345 }
323 AccountFetcherService* account_fetcher() { return account_fetcher_.get(); } 346 AccountFetcherService* account_fetcher() { return account_fetcher_.get(); }
324 AccountTrackerService* account_tracker() { return account_tracker_.get(); } 347 AccountTrackerService* account_tracker() { return account_tracker_.get(); }
325 OAuth2TokenService* token_service() { 348 OAuth2TokenService* token_service() {
326 return fake_oauth2_token_service_.get(); 349 return fake_oauth2_token_service_.get();
327 } 350 }
328 SigninClient* signin_client() { return signin_client_.get(); } 351 SigninClient* signin_client() { return signin_client_.get(); }
352 PrefService* pref_service() { return &pref_service_; }
329 353
330 private: 354 private:
331 void ReturnOAuthUrlFetchResults(int fetcher_id, 355 void ReturnOAuthUrlFetchResults(int fetcher_id,
332 net::HttpStatusCode response_code, 356 net::HttpStatusCode response_code,
333 const std::string& response_string); 357 const std::string& response_string);
334 358
335 base::MessageLoopForIO message_loop_; 359 base::MessageLoopForIO message_loop_;
336 net::TestURLFetcherFactory test_fetcher_factory_; 360 net::TestURLFetcherFactory test_fetcher_factory_;
337 scoped_ptr<FakeOAuth2TokenService> fake_oauth2_token_service_; 361 scoped_ptr<FakeOAuth2TokenService> fake_oauth2_token_service_;
338 TestingPrefServiceSimple pref_service_; 362 TestingPrefServiceSimple pref_service_;
(...skipping 825 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 ASSERT_FALSE(info.is_child_account); 1188 ASSERT_FALSE(info.is_child_account);
1165 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id))); 1189 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(UPDATED, child_id)));
1166 1190
1167 SimulateTokenRevoked(child_id); 1191 SimulateTokenRevoked(child_id);
1168 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id))); 1192 ASSERT_TRUE(observer.CheckEvents(TrackingEvent(REMOVED, child_id)));
1169 1193
1170 tracker.RemoveObserver(&observer); 1194 tracker.RemoveObserver(&observer);
1171 fetcher.Shutdown(); 1195 fetcher.Shutdown();
1172 tracker.Shutdown(); 1196 tracker.Shutdown();
1173 } 1197 }
1198
1199 TEST_F(AccountTrackerServiceTest, RefreshOnTokensLoadedWhenNeeded) {
1200 std::string account_id("account_id");
1201 AccountInfo info;
1202 {
1203 AccountTrackerService tracker;
1204 tracker.Initialize(signin_client());
1205 FakeAccountFetcherService fetcher;
1206 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1207 fetcher.EnableNetworkFetches();
1208 fetcher.FakeUserInfoFetchSuccess(account_id,
1209 "original@example.com",
1210 account_id,
1211 "",
1212 "first",
1213 "fi",
1214 "en-US",
1215 "");
1216 info = tracker.GetAccountInfo(account_id);
1217 EXPECT_TRUE(info.IsValid());
1218 EXPECT_EQ("original@example.com", info.email);
1219 }
1220
1221 // Set the last update to a long time ago to trigger a refresh when the AFS
1222 // starts.
1223 pref_service()->SetInt64(AccountFetcherService::kLastUpdatePref, 0);
1224
1225 {
1226 // Prepare the new account info that will be fetched for |account_id|.
1227 info.email = "mutated@example.com";
1228 AccountTrackerService tracker;
1229 tracker.Initialize(signin_client());
1230 InfoMutatingFakeAccountFetcherService fetcher(info);
1231 fetcher.Initialize(signin_client(), token_service(), &tracker, nullptr);
1232 fetcher.EnableNetworkFetches();
1233
1234 info = tracker.GetAccountInfo(account_id);
1235 // The persisted info should be returned since the refresh tokens aren't
1236 // loaded yet.
1237 EXPECT_TRUE(info.IsValid());
1238 EXPECT_EQ("original@example.com", info.email);
1239
1240 // Trigger a OnRefreshTokensLoaded() notification.
1241 static_cast<FakeOAuth2TokenService*>(token_service())->
1242 GetFakeOAuth2TokenServiceDelegate()->LoadCredentials(account_id);
1243
1244 info = tracker.GetAccountInfo(account_id);
1245 EXPECT_TRUE(info.IsValid());
1246 EXPECT_EQ("mutated@example.com", info.email);
1247 }
1248 }
1249
OLDNEW
« no previous file with comments | « components/signin/core/browser/account_fetcher_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698