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" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 testing::AssertionResult CheckEvents(const TrackingEvent& e1); | 107 testing::AssertionResult CheckEvents(const TrackingEvent& e1); |
108 testing::AssertionResult CheckEvents(const TrackingEvent& e1, | 108 testing::AssertionResult CheckEvents(const TrackingEvent& e1, |
109 const TrackingEvent& e2); | 109 const TrackingEvent& e2); |
110 testing::AssertionResult CheckEvents(const TrackingEvent& e1, | 110 testing::AssertionResult CheckEvents(const TrackingEvent& e1, |
111 const TrackingEvent& e2, | 111 const TrackingEvent& e2, |
112 const TrackingEvent& e3); | 112 const TrackingEvent& e3); |
113 | 113 |
114 private: | 114 private: |
115 // AccountTrackerService::Observer implementation | 115 // AccountTrackerService::Observer implementation |
116 virtual void OnAccountUpdated( | 116 virtual void OnAccountUpdated( |
117 const AccountTrackerService::AccountInfo& ids) OVERRIDE; | 117 const AccountTrackerService::AccountInfo& ids) override; |
118 virtual void OnAccountRemoved( | 118 virtual void OnAccountRemoved( |
119 const AccountTrackerService::AccountInfo& ids) OVERRIDE; | 119 const AccountTrackerService::AccountInfo& ids) override; |
120 | 120 |
121 testing::AssertionResult CheckEvents( | 121 testing::AssertionResult CheckEvents( |
122 const std::vector<TrackingEvent>& events); | 122 const std::vector<TrackingEvent>& events); |
123 | 123 |
124 std::vector<TrackingEvent> events_; | 124 std::vector<TrackingEvent> events_; |
125 }; | 125 }; |
126 | 126 |
127 void AccountTrackerObserver::OnAccountUpdated( | 127 void AccountTrackerObserver::OnAccountUpdated( |
128 const AccountTrackerService::AccountInfo& ids) { | 128 const AccountTrackerService::AccountInfo& ids) { |
129 events_.push_back(TrackingEvent(UPDATED, ids.account_id, ids.gaia)); | 129 events_.push_back(TrackingEvent(UPDATED, ids.account_id, ids.gaia)); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 188 } |
189 | 189 |
190 } // namespace | 190 } // namespace |
191 | 191 |
192 class AccountTrackerServiceTest : public testing::Test { | 192 class AccountTrackerServiceTest : public testing::Test { |
193 public: | 193 public: |
194 AccountTrackerServiceTest() {} | 194 AccountTrackerServiceTest() {} |
195 | 195 |
196 virtual ~AccountTrackerServiceTest() {} | 196 virtual ~AccountTrackerServiceTest() {} |
197 | 197 |
198 virtual void SetUp() OVERRIDE { | 198 virtual void SetUp() override { |
199 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); | 199 fake_oauth2_token_service_.reset(new FakeOAuth2TokenService()); |
200 | 200 |
201 pref_service_.registry()->RegisterListPref( | 201 pref_service_.registry()->RegisterListPref( |
202 AccountTrackerService::kAccountInfoPref); | 202 AccountTrackerService::kAccountInfoPref); |
203 | 203 |
204 account_tracker_.reset(new AccountTrackerService()); | 204 account_tracker_.reset(new AccountTrackerService()); |
205 account_tracker_->Initialize(fake_oauth2_token_service_.get(), | 205 account_tracker_->Initialize(fake_oauth2_token_service_.get(), |
206 &pref_service_, | 206 &pref_service_, |
207 new net::TestURLRequestContextGetter( | 207 new net::TestURLRequestContextGetter( |
208 message_loop_.message_loop_proxy())); | 208 message_loop_.message_loop_proxy())); |
209 account_tracker_->AddObserver(&observer_); | 209 account_tracker_->AddObserver(&observer_); |
210 } | 210 } |
211 | 211 |
212 virtual void TearDown() OVERRIDE { | 212 virtual void TearDown() override { |
213 account_tracker_->RemoveObserver(&observer_); | 213 account_tracker_->RemoveObserver(&observer_); |
214 account_tracker_->Shutdown(); | 214 account_tracker_->Shutdown(); |
215 } | 215 } |
216 | 216 |
217 void SimulateTokenAvailable(const std::string& account_id) { | 217 void SimulateTokenAvailable(const std::string& account_id) { |
218 fake_oauth2_token_service_->AddAccount(account_id); | 218 fake_oauth2_token_service_->AddAccount(account_id); |
219 } | 219 } |
220 | 220 |
221 void SimulateTokenRevoked(const std::string& account_id) { | 221 void SimulateTokenRevoked(const std::string& account_id) { |
222 fake_oauth2_token_service_->RemoveAccount(account_id); | 222 fake_oauth2_token_service_->RemoveAccount(account_id); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 | 500 |
501 std::vector<AccountTrackerService::AccountInfo> infos = | 501 std::vector<AccountTrackerService::AccountInfo> infos = |
502 tracker.GetAccounts(); | 502 tracker.GetAccounts(); |
503 ASSERT_EQ(1u, infos.size()); | 503 ASSERT_EQ(1u, infos.size()); |
504 EXPECT_EQ("beta", infos[0].account_id); | 504 EXPECT_EQ("beta", infos[0].account_id); |
505 EXPECT_EQ(AccountIdToGaiaId("beta"), infos[0].gaia); | 505 EXPECT_EQ(AccountIdToGaiaId("beta"), infos[0].gaia); |
506 EXPECT_EQ(AccountIdToEmail("beta"), infos[0].email); | 506 EXPECT_EQ(AccountIdToEmail("beta"), infos[0].email); |
507 tracker.Shutdown(); | 507 tracker.Shutdown(); |
508 } | 508 } |
509 } | 509 } |
OLD | NEW |