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

Side by Side Diff: chrome/browser/services/gcm/gcm_account_tracker_unittest.cc

Issue 618003002: [GCM] Handling connection events in GCMAccountTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the test failing on a mac Created 6 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
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 "chrome/browser/services/gcm/gcm_account_tracker.h" 5 #include "chrome/browser/services/gcm/gcm_account_tracker.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/run_loop.h"
13 #include "components/gcm_driver/fake_gcm_driver.h"
12 #include "google_apis/gaia/fake_identity_provider.h" 14 #include "google_apis/gaia/fake_identity_provider.h"
13 #include "google_apis/gaia/fake_oauth2_token_service.h" 15 #include "google_apis/gaia/fake_oauth2_token_service.h"
14 #include "google_apis/gaia/google_service_auth_error.h" 16 #include "google_apis/gaia/google_service_auth_error.h"
15 #include "net/http/http_status_code.h" 17 #include "net/http/http_status_code.h"
16 #include "net/url_request/test_url_fetcher_factory.h" 18 #include "net/url_request/test_url_fetcher_factory.h"
17 #include "net/url_request/url_request_test_util.h" 19 #include "net/url_request/url_request_test_util.h"
18 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
19 21
20 namespace gcm { 22 namespace gcm {
21 23
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 actual_iter = actual_tokens.begin(); 56 actual_iter = actual_tokens.begin();
55 expected_iter != expected_tokens.end() && 57 expected_iter != expected_tokens.end() &&
56 actual_iter != actual_tokens.end(); 58 actual_iter != actual_tokens.end();
57 ++expected_iter, ++actual_iter) { 59 ++expected_iter, ++actual_iter) {
58 EXPECT_EQ(expected_iter->account_id, actual_iter->account_id); 60 EXPECT_EQ(expected_iter->account_id, actual_iter->account_id);
59 EXPECT_EQ(expected_iter->email, actual_iter->email); 61 EXPECT_EQ(expected_iter->email, actual_iter->email);
60 EXPECT_EQ(expected_iter->access_token, actual_iter->access_token); 62 EXPECT_EQ(expected_iter->access_token, actual_iter->access_token);
61 } 63 }
62 } 64 }
63 65
66 // This version of FakeGCMDriver is customized around handling accounts and
67 // connection events for testing GCMAccountTracker.
68 class CustomFakeGCMDriver : public FakeGCMDriver {
69 public:
70 CustomFakeGCMDriver();
71 virtual ~CustomFakeGCMDriver();
72
73 // GCMDriver overrides:
74 virtual void SetAccountTokens(
75 const std::vector<GCMClient::AccountTokenInfo>& account_tokens) override;
76 virtual void AddConnectionObserver(GCMConnectionObserver* observer) override;
77 virtual void RemoveConnectionObserver(
78 GCMConnectionObserver* observer) override;
79 virtual bool IsConnected() const override { return connected_; }
80
81 // Test results and helpers.
82 void SetConnected(bool connected);
83 void ResetResults();
84 bool update_accounts_called() const { return update_accounts_called_; }
85 const std::vector<GCMClient::AccountTokenInfo>& accounts() const {
86 return accounts_;
87 }
88 const GCMConnectionObserver* last_connection_observer() const {
89 return last_connection_observer_;
90 }
91 const GCMConnectionObserver* last_removed_connection_observer() const {
92 return removed_connection_observer_;
93 }
94
95 private:
96 bool connected_;
97 std::vector<GCMClient::AccountTokenInfo> accounts_;
98 bool update_accounts_called_;
99 GCMConnectionObserver* last_connection_observer_;
100 GCMConnectionObserver* removed_connection_observer_;
101 net::IPEndPoint ip_endpoint_;
102
103 DISALLOW_COPY_AND_ASSIGN(CustomFakeGCMDriver);
104 };
105
106 CustomFakeGCMDriver::CustomFakeGCMDriver()
107 : connected_(true),
108 update_accounts_called_(false),
109 last_connection_observer_(NULL),
110 removed_connection_observer_(NULL) {
111 }
112
113 CustomFakeGCMDriver::~CustomFakeGCMDriver() {
114 }
115
116 void CustomFakeGCMDriver::SetAccountTokens(
117 const std::vector<GCMClient::AccountTokenInfo>& accounts) {
118 update_accounts_called_ = true;
119 accounts_ = accounts;
120 }
121
122 void CustomFakeGCMDriver::AddConnectionObserver(
123 GCMConnectionObserver* observer) {
124 last_connection_observer_ = observer;
125 }
126
127 void CustomFakeGCMDriver::RemoveConnectionObserver(
128 GCMConnectionObserver* observer) {
129 removed_connection_observer_ = observer;
130 }
131
132 void CustomFakeGCMDriver::SetConnected(bool connected) {
133 connected_ = connected;
134 if (connected && last_connection_observer_)
135 last_connection_observer_->OnConnected(ip_endpoint_);
136 }
137
138 void CustomFakeGCMDriver::ResetResults() {
139 accounts_.clear();
140 update_accounts_called_ = false;
141 last_connection_observer_ = NULL;
142 removed_connection_observer_ = NULL;
143 }
144
64 } // namespace 145 } // namespace
65 146
66 class GCMAccountTrackerTest : public testing::Test { 147 class GCMAccountTrackerTest : public testing::Test {
67 public: 148 public:
68 GCMAccountTrackerTest(); 149 GCMAccountTrackerTest();
69 virtual ~GCMAccountTrackerTest(); 150 virtual ~GCMAccountTrackerTest();
70 151
71 // Callback for the account tracker.
72 void UpdateAccounts(const std::vector<GCMClient::AccountTokenInfo>& accounts);
73
74 // Helpers to pass fake events to the tracker. Tests should have either a pair 152 // Helpers to pass fake events to the tracker. Tests should have either a pair
75 // of Start/FinishAccountSignIn or SignInAccount per account. Don't mix. 153 // of Start/FinishAccountSignIn or SignInAccount per account. Don't mix.
76 // Call to SignOutAccount is not mandatory. 154 // Call to SignOutAccount is not mandatory.
77 void StartAccountSignIn(const std::string& account_key); 155 void StartAccountSignIn(const std::string& account_key);
78 void FinishAccountSignIn(const std::string& account_key); 156 void FinishAccountSignIn(const std::string& account_key);
79 void SignInAccount(const std::string& account_key); 157 void SignInAccount(const std::string& account_key);
80 void SignOutAccount(const std::string& account_key); 158 void SignOutAccount(const std::string& account_key);
81 159
82 // Helpers for dealing with OAuth2 access token requests. 160 // Helpers for dealing with OAuth2 access token requests.
83 void IssueAccessToken(const std::string& account_key); 161 void IssueAccessToken(const std::string& account_key);
162 void IssueExpiredAccessToken(const std::string& account_key);
84 void IssueError(const std::string& account_key); 163 void IssueError(const std::string& account_key);
85 164
86 // Test results and helpers. 165 // Accessors to account tracker and gcm driver.
87 void ResetResults();
88 bool update_accounts_called() const { return update_accounts_called_; }
89 const std::vector<GCMClient::AccountTokenInfo>& accounts() const {
90 return accounts_;
91 }
92
93 // Accessor to account tracker.
94 GCMAccountTracker* tracker() { return tracker_.get(); } 166 GCMAccountTracker* tracker() { return tracker_.get(); }
167 CustomFakeGCMDriver* driver() { return &driver_; }
95 168
96 private: 169 private:
97 std::vector<GCMClient::AccountTokenInfo> accounts_; 170 CustomFakeGCMDriver driver_;
98 bool update_accounts_called_;
99 171
100 base::MessageLoop message_loop_; 172 base::MessageLoop message_loop_;
101 net::TestURLFetcherFactory test_fetcher_factory_; 173 net::TestURLFetcherFactory test_fetcher_factory_;
102 scoped_ptr<FakeOAuth2TokenService> fake_token_service_; 174 scoped_ptr<FakeOAuth2TokenService> fake_token_service_;
103 scoped_ptr<FakeIdentityProvider> fake_identity_provider_; 175 scoped_ptr<FakeIdentityProvider> fake_identity_provider_;
104 scoped_ptr<GCMAccountTracker> tracker_; 176 scoped_ptr<GCMAccountTracker> tracker_;
105 }; 177 };
106 178
107 GCMAccountTrackerTest::GCMAccountTrackerTest() 179 GCMAccountTrackerTest::GCMAccountTrackerTest() {
108 : update_accounts_called_(false) {
109 fake_token_service_.reset(new FakeOAuth2TokenService()); 180 fake_token_service_.reset(new FakeOAuth2TokenService());
110 181
111 fake_identity_provider_.reset( 182 fake_identity_provider_.reset(
112 new FakeIdentityProvider(fake_token_service_.get())); 183 new FakeIdentityProvider(fake_token_service_.get()));
113 184
114 scoped_ptr<gaia::AccountTracker> gaia_account_tracker( 185 scoped_ptr<gaia::AccountTracker> gaia_account_tracker(
115 new gaia::AccountTracker(fake_identity_provider_.get(), 186 new gaia::AccountTracker(fake_identity_provider_.get(),
116 new net::TestURLRequestContextGetter( 187 new net::TestURLRequestContextGetter(
117 message_loop_.message_loop_proxy()))); 188 message_loop_.message_loop_proxy())));
118 189
119 tracker_.reset(new GCMAccountTracker( 190 tracker_.reset(new GCMAccountTracker(gaia_account_tracker.Pass(), &driver_));
120 gaia_account_tracker.Pass(),
121 base::Bind(&GCMAccountTrackerTest::UpdateAccounts,
122 base::Unretained(this))));
123 } 191 }
124 192
125 GCMAccountTrackerTest::~GCMAccountTrackerTest() { 193 GCMAccountTrackerTest::~GCMAccountTrackerTest() {
126 if (tracker_) 194 if (tracker_)
127 tracker_->Shutdown(); 195 tracker_->Shutdown();
128 } 196 }
129 197
130 void GCMAccountTrackerTest::UpdateAccounts(
131 const std::vector<GCMClient::AccountTokenInfo>& accounts) {
132 update_accounts_called_ = true;
133 accounts_ = accounts;
134 }
135
136 void GCMAccountTrackerTest::ResetResults() {
137 accounts_.clear();
138 update_accounts_called_ = false;
139 }
140
141 void GCMAccountTrackerTest::StartAccountSignIn(const std::string& account_key) { 198 void GCMAccountTrackerTest::StartAccountSignIn(const std::string& account_key) {
142 fake_identity_provider_->LogIn(account_key); 199 fake_identity_provider_->LogIn(account_key);
143 fake_token_service_->AddAccount(account_key); 200 fake_token_service_->AddAccount(account_key);
144 } 201 }
145 202
146 void GCMAccountTrackerTest::FinishAccountSignIn( 203 void GCMAccountTrackerTest::FinishAccountSignIn(
147 const std::string& account_key) { 204 const std::string& account_key) {
148 IssueAccessToken(account_key); 205 IssueAccessToken(account_key);
149 206
150 net::TestURLFetcher* fetcher = test_fetcher_factory_.GetFetcherByID( 207 net::TestURLFetcher* fetcher = test_fetcher_factory_.GetFetcherByID(
(...skipping 11 matching lines...) Expand all
162 219
163 void GCMAccountTrackerTest::SignOutAccount(const std::string& account_key) { 220 void GCMAccountTrackerTest::SignOutAccount(const std::string& account_key) {
164 fake_token_service_->RemoveAccount(account_key); 221 fake_token_service_->RemoveAccount(account_key);
165 } 222 }
166 223
167 void GCMAccountTrackerTest::IssueAccessToken(const std::string& account_key) { 224 void GCMAccountTrackerTest::IssueAccessToken(const std::string& account_key) {
168 fake_token_service_->IssueAllTokensForAccount( 225 fake_token_service_->IssueAllTokensForAccount(
169 account_key, MakeAccessToken(account_key), base::Time::Max()); 226 account_key, MakeAccessToken(account_key), base::Time::Max());
170 } 227 }
171 228
229 void GCMAccountTrackerTest::IssueExpiredAccessToken(
230 const std::string& account_key) {
231 fake_token_service_->IssueAllTokensForAccount(
232 account_key, MakeAccessToken(account_key), base::Time::Now());
233 }
234
172 void GCMAccountTrackerTest::IssueError(const std::string& account_key) { 235 void GCMAccountTrackerTest::IssueError(const std::string& account_key) {
173 fake_token_service_->IssueErrorForAllPendingRequestsForAccount( 236 fake_token_service_->IssueErrorForAllPendingRequestsForAccount(
174 account_key, 237 account_key,
175 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); 238 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
176 } 239 }
177 240
178 TEST_F(GCMAccountTrackerTest, NoAccounts) { 241 TEST_F(GCMAccountTrackerTest, NoAccounts) {
179 EXPECT_FALSE(update_accounts_called()); 242 EXPECT_FALSE(driver()->update_accounts_called());
180 tracker()->Start(); 243 tracker()->Start();
181 // Callback should not be called if there where no accounts provided. 244 // Callback should not be called if there where no accounts provided.
182 EXPECT_FALSE(update_accounts_called()); 245 EXPECT_FALSE(driver()->update_accounts_called());
183 EXPECT_TRUE(accounts().empty()); 246 EXPECT_TRUE(driver()->accounts().empty());
184 tracker()->Stop();
185 } 247 }
186 248
187 // Verifies that callback is called after a token is issued for a single account 249 // Verifies that callback is called after a token is issued for a single account
188 // with a specific scope. In this scenario, the underlying account tracker is 250 // with a specific scope. In this scenario, the underlying account tracker is
189 // still working when the CompleteCollectingTokens is called for the first time. 251 // still working when the CompleteCollectingTokens is called for the first time.
190 TEST_F(GCMAccountTrackerTest, SingleAccount) { 252 TEST_F(GCMAccountTrackerTest, SingleAccount) {
191 StartAccountSignIn(kAccountId1); 253 StartAccountSignIn(kAccountId1);
192 254
193 tracker()->Start(); 255 tracker()->Start();
194 // We don't have any accounts to report, but given the inner account tracker 256 // We don't have any accounts to report, but given the inner account tracker
195 // is still working we don't make a call with empty accounts list. 257 // is still working we don't make a call with empty accounts list.
196 EXPECT_FALSE(update_accounts_called()); 258 EXPECT_FALSE(driver()->update_accounts_called());
197 259
198 // This concludes the work of inner account tracker. 260 // This concludes the work of inner account tracker.
199 FinishAccountSignIn(kAccountId1); 261 FinishAccountSignIn(kAccountId1);
200 IssueAccessToken(kAccountId1); 262 IssueAccessToken(kAccountId1);
201 263
202 EXPECT_TRUE(update_accounts_called()); 264 EXPECT_TRUE(driver()->update_accounts_called());
203 265
204 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 266 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
205 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 267 expected_accounts.push_back(MakeAccountToken(kAccountId1));
206 VerifyAccountTokens(expected_accounts, accounts()); 268 VerifyAccountTokens(expected_accounts, driver()->accounts());
207 tracker()->Stop();
208 } 269 }
209 270
210 TEST_F(GCMAccountTrackerTest, MultipleAccounts) { 271 TEST_F(GCMAccountTrackerTest, MultipleAccounts) {
211 StartAccountSignIn(kAccountId1); 272 StartAccountSignIn(kAccountId1);
212 StartAccountSignIn(kAccountId2); 273 StartAccountSignIn(kAccountId2);
213 274
214 tracker()->Start(); 275 tracker()->Start();
215 EXPECT_FALSE(update_accounts_called()); 276 EXPECT_FALSE(driver()->update_accounts_called());
216 277
217 FinishAccountSignIn(kAccountId1); 278 FinishAccountSignIn(kAccountId1);
218 IssueAccessToken(kAccountId1); 279 IssueAccessToken(kAccountId1);
219 EXPECT_FALSE(update_accounts_called()); 280 EXPECT_FALSE(driver()->update_accounts_called());
220 281
221 FinishAccountSignIn(kAccountId2); 282 FinishAccountSignIn(kAccountId2);
222 IssueAccessToken(kAccountId2); 283 IssueAccessToken(kAccountId2);
223 EXPECT_TRUE(update_accounts_called()); 284 EXPECT_TRUE(driver()->update_accounts_called());
224 285
225 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 286 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
226 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 287 expected_accounts.push_back(MakeAccountToken(kAccountId1));
227 expected_accounts.push_back(MakeAccountToken(kAccountId2)); 288 expected_accounts.push_back(MakeAccountToken(kAccountId2));
228 VerifyAccountTokens(expected_accounts, accounts()); 289 VerifyAccountTokens(expected_accounts, driver()->accounts());
229
230 tracker()->Stop();
231 } 290 }
232 291
233 TEST_F(GCMAccountTrackerTest, AccountAdded) { 292 TEST_F(GCMAccountTrackerTest, AccountAdded) {
234 tracker()->Start(); 293 tracker()->Start();
235 ResetResults(); 294 driver()->ResetResults();
236 295
237 SignInAccount(kAccountId1); 296 SignInAccount(kAccountId1);
238 EXPECT_FALSE(update_accounts_called()); 297 EXPECT_FALSE(driver()->update_accounts_called());
239 298
240 IssueAccessToken(kAccountId1); 299 IssueAccessToken(kAccountId1);
241 EXPECT_TRUE(update_accounts_called()); 300 EXPECT_TRUE(driver()->update_accounts_called());
242 301
243 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 302 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
244 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 303 expected_accounts.push_back(MakeAccountToken(kAccountId1));
245 VerifyAccountTokens(expected_accounts, accounts()); 304 VerifyAccountTokens(expected_accounts, driver()->accounts());
246
247 tracker()->Stop();
248 } 305 }
249 306
250 TEST_F(GCMAccountTrackerTest, AccountRemoved) { 307 TEST_F(GCMAccountTrackerTest, AccountRemoved) {
251 SignInAccount(kAccountId1); 308 SignInAccount(kAccountId1);
252 SignInAccount(kAccountId2); 309 SignInAccount(kAccountId2);
253 310
254 tracker()->Start(); 311 tracker()->Start();
255 IssueAccessToken(kAccountId1); 312 IssueAccessToken(kAccountId1);
256 IssueAccessToken(kAccountId2); 313 IssueAccessToken(kAccountId2);
257 EXPECT_TRUE(update_accounts_called()); 314 EXPECT_TRUE(driver()->update_accounts_called());
258 315
259 ResetResults(); 316 driver()->ResetResults();
260 EXPECT_FALSE(update_accounts_called()); 317 EXPECT_FALSE(driver()->update_accounts_called());
261 318
262 SignOutAccount(kAccountId2); 319 SignOutAccount(kAccountId2);
263 EXPECT_TRUE(update_accounts_called()); 320 EXPECT_TRUE(driver()->update_accounts_called());
264 321
265 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 322 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
266 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 323 expected_accounts.push_back(MakeAccountToken(kAccountId1));
267 VerifyAccountTokens(expected_accounts, accounts()); 324 VerifyAccountTokens(expected_accounts, driver()->accounts());
268
269 tracker()->Stop();
270 } 325 }
271 326
272 TEST_F(GCMAccountTrackerTest, GetTokenFailed) { 327 TEST_F(GCMAccountTrackerTest, GetTokenFailed) {
273 SignInAccount(kAccountId1); 328 SignInAccount(kAccountId1);
274 SignInAccount(kAccountId2); 329 SignInAccount(kAccountId2);
275 330
276 tracker()->Start(); 331 tracker()->Start();
277 IssueAccessToken(kAccountId1); 332 IssueAccessToken(kAccountId1);
278 EXPECT_FALSE(update_accounts_called()); 333 EXPECT_FALSE(driver()->update_accounts_called());
279 334
280 IssueError(kAccountId2); 335 IssueError(kAccountId2);
281 EXPECT_TRUE(update_accounts_called()); 336 EXPECT_FALSE(driver()->update_accounts_called());
337
338 EXPECT_EQ(1UL, tracker()->get_pending_token_request_count());
339
340 IssueAccessToken(kAccountId2);
341 EXPECT_TRUE(driver()->update_accounts_called());
282 342
283 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 343 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
284 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 344 expected_accounts.push_back(MakeAccountToken(kAccountId1));
285 VerifyAccountTokens(expected_accounts, accounts()); 345 expected_accounts.push_back(MakeAccountToken(kAccountId2));
286 346 VerifyAccountTokens(expected_accounts, driver()->accounts());
287 tracker()->Stop();
288 } 347 }
289 348
290 TEST_F(GCMAccountTrackerTest, GetTokenFailedAccountRemoved) { 349 TEST_F(GCMAccountTrackerTest, GetTokenFailedAccountRemoved) {
291 SignInAccount(kAccountId1); 350 SignInAccount(kAccountId1);
292 SignInAccount(kAccountId2); 351 SignInAccount(kAccountId2);
293 352
294 tracker()->Start(); 353 tracker()->Start();
295 IssueAccessToken(kAccountId1); 354 IssueAccessToken(kAccountId1);
296 IssueError(kAccountId2); 355 IssueError(kAccountId2);
297 356
298 ResetResults(); 357 driver()->ResetResults();
299 SignOutAccount(kAccountId2); 358 SignOutAccount(kAccountId2);
300 EXPECT_TRUE(update_accounts_called()); 359 IssueError(kAccountId2);
360
361 EXPECT_TRUE(driver()->update_accounts_called());
301 362
302 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 363 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
303 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 364 expected_accounts.push_back(MakeAccountToken(kAccountId1));
304 VerifyAccountTokens(expected_accounts, accounts()); 365 VerifyAccountTokens(expected_accounts, driver()->accounts());
305
306 tracker()->Stop();
307 } 366 }
308 367
309 TEST_F(GCMAccountTrackerTest, AccountRemovedWhileRequestsPending) { 368 TEST_F(GCMAccountTrackerTest, AccountRemovedWhileRequestsPending) {
310 SignInAccount(kAccountId1); 369 SignInAccount(kAccountId1);
311 SignInAccount(kAccountId2); 370 SignInAccount(kAccountId2);
312 371
313 tracker()->Start(); 372 tracker()->Start();
314 IssueAccessToken(kAccountId1); 373 IssueAccessToken(kAccountId1);
315 EXPECT_FALSE(update_accounts_called()); 374 EXPECT_FALSE(driver()->update_accounts_called());
316 375
317 SignOutAccount(kAccountId2); 376 SignOutAccount(kAccountId2);
318 IssueAccessToken(kAccountId2); 377 IssueAccessToken(kAccountId2);
319 EXPECT_TRUE(update_accounts_called()); 378 EXPECT_TRUE(driver()->update_accounts_called());
320 379
321 std::vector<GCMClient::AccountTokenInfo> expected_accounts; 380 std::vector<GCMClient::AccountTokenInfo> expected_accounts;
322 expected_accounts.push_back(MakeAccountToken(kAccountId1)); 381 expected_accounts.push_back(MakeAccountToken(kAccountId1));
323 VerifyAccountTokens(expected_accounts, accounts()); 382 VerifyAccountTokens(expected_accounts, driver()->accounts());
383 }
324 384
325 tracker()->Stop(); 385 // Makes sure that tracker observes GCM connection when running.
386 TEST_F(GCMAccountTrackerTest, TrackerObservesConnection) {
387 EXPECT_EQ(NULL, driver()->last_connection_observer());
388 tracker()->Start();
389 EXPECT_EQ(tracker(), driver()->last_connection_observer());
390 tracker()->Shutdown();
391 EXPECT_EQ(tracker(), driver()->last_removed_connection_observer());
392 }
393
394 // Makes sure that token fetching happens only after connection is established.
395 TEST_F(GCMAccountTrackerTest, PostponeTokenFetchingUntilConnected) {
396 driver()->SetConnected(false);
397 StartAccountSignIn(kAccountId1);
398 tracker()->Start();
399 FinishAccountSignIn(kAccountId1);
400
401 EXPECT_EQ(0UL, tracker()->get_pending_token_request_count());
402 driver()->SetConnected(true);
403
404 EXPECT_EQ(1UL, tracker()->get_pending_token_request_count());
405 }
406
407 TEST_F(GCMAccountTrackerTest, IvalidateExpiredTokens) {
408 StartAccountSignIn(kAccountId1);
409 StartAccountSignIn(kAccountId2);
410 tracker()->Start();
411 FinishAccountSignIn(kAccountId1);
412 FinishAccountSignIn(kAccountId2);
413
414 EXPECT_EQ(2UL, tracker()->get_pending_token_request_count());
415
416 IssueExpiredAccessToken(kAccountId1);
417 IssueAccessToken(kAccountId2);
418 // Because the first token is expired, we expect the sanitize to kick in and
419 // clean it up before the SetAccessToken is called. This also means a new
420 // token request will be issued
421 EXPECT_FALSE(driver()->update_accounts_called());
422 EXPECT_EQ(1UL, tracker()->get_pending_token_request_count());
326 } 423 }
327 424
328 // TODO(fgorski): Add test for adding account after removal >> make sure it does 425 // TODO(fgorski): Add test for adding account after removal >> make sure it does
329 // not mark removal. 426 // not mark removal.
330 427
331 } // namespace gcm 428 } // namespace gcm
OLDNEW
« no previous file with comments | « chrome/browser/services/gcm/gcm_account_tracker.cc ('k') | chrome/browser/services/gcm/gcm_profile_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698