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

Side by Side Diff: components/gcm_driver/gcm_driver_desktop_unittest.cc

Issue 617003005: Keep the GCM data intact when the user signs out of the profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.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 "components/gcm_driver/gcm_driver_desktop.h" 5 #include "components/gcm_driver/gcm_driver_desktop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 driver_->RemoveAppHandler(kTestAppID2); 266 driver_->RemoveAppHandler(kTestAppID2);
267 } 267 }
268 268
269 void GCMDriverTest::SignIn(const std::string& account_id) { 269 void GCMDriverTest::SignIn(const std::string& account_id) {
270 driver_->OnSignedIn(); 270 driver_->OnSignedIn();
271 PumpIOLoop(); 271 PumpIOLoop();
272 PumpUILoop(); 272 PumpUILoop();
273 } 273 }
274 274
275 void GCMDriverTest::SignOut() { 275 void GCMDriverTest::SignOut() {
276 driver_->Purge(); 276 driver_->OnSignedOut();
277 PumpIOLoop(); 277 PumpIOLoop();
278 PumpUILoop(); 278 PumpUILoop();
279 } 279 }
280 280
281 void GCMDriverTest::Register(const std::string& app_id, 281 void GCMDriverTest::Register(const std::string& app_id,
282 const std::vector<std::string>& sender_ids, 282 const std::vector<std::string>& sender_ids,
283 WaitToFinish wait_to_finish) { 283 WaitToFinish wait_to_finish) {
284 base::RunLoop run_loop; 284 base::RunLoop run_loop;
285 async_operation_completed_callback_ = run_loop.QuitClosure(); 285 async_operation_completed_callback_ = run_loop.QuitClosure();
286 driver_->Register(app_id, 286 driver_->Register(app_id,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 EXPECT_FALSE(driver()->IsStarted()); 372 EXPECT_FALSE(driver()->IsStarted());
373 EXPECT_FALSE(driver()->IsConnected()); 373 EXPECT_FALSE(driver()->IsConnected());
374 EXPECT_FALSE(gcm_connection_observer()->connected()); 374 EXPECT_FALSE(gcm_connection_observer()->connected());
375 375
376 // GCM will be started after app handler is added. 376 // GCM will be started after app handler is added.
377 AddAppHandlers(); 377 AddAppHandlers();
378 EXPECT_TRUE(driver()->IsStarted()); 378 EXPECT_TRUE(driver()->IsStarted());
379 PumpIOLoop(); 379 PumpIOLoop();
380 EXPECT_TRUE(driver()->IsConnected()); 380 EXPECT_TRUE(driver()->IsConnected());
381 EXPECT_TRUE(gcm_connection_observer()->connected()); 381 EXPECT_TRUE(gcm_connection_observer()->connected());
382
383 // Sign-in will not affect GCM state.
384 SignIn(kTestAccountID1);
385 PumpIOLoop();
386 EXPECT_TRUE(driver()->IsStarted());
387 EXPECT_TRUE(driver()->IsConnected());
388
389 // Sign-out will not affect GCM state.
390 SignOut();
391 PumpIOLoop();
392 EXPECT_TRUE(driver()->IsStarted());
393 EXPECT_TRUE(driver()->IsConnected());
382 } 394 }
383 395
384 TEST_F(GCMDriverTest, Shutdown) { 396 TEST_F(GCMDriverTest, Shutdown) {
385 CreateDriver(FakeGCMClient::NO_DELAY_START); 397 CreateDriver(FakeGCMClient::NO_DELAY_START);
386 EXPECT_FALSE(HasAppHandlers()); 398 EXPECT_FALSE(HasAppHandlers());
387 399
388 AddAppHandlers(); 400 AddAppHandlers();
389 EXPECT_TRUE(HasAppHandlers()); 401 EXPECT_TRUE(HasAppHandlers());
390 402
391 ShutdownDriver(); 403 ShutdownDriver();
392 EXPECT_FALSE(HasAppHandlers()); 404 EXPECT_FALSE(HasAppHandlers());
393 EXPECT_FALSE(driver()->IsConnected()); 405 EXPECT_FALSE(driver()->IsConnected());
394 EXPECT_FALSE(gcm_connection_observer()->connected()); 406 EXPECT_FALSE(gcm_connection_observer()->connected());
395 } 407 }
396 408
397 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) { 409 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMEnabled) {
fgorski 2014/10/01 16:54:09 I don't understand why we are stopping. Is GCM onl
jianli 2014/10/01 21:56:23 Before we drop the sign-in enforcement and roll ou
398 // By default, GCM is enabled. 410 // By default, GCM is enabled.
399 CreateDriver(FakeGCMClient::NO_DELAY_START); 411 CreateDriver(FakeGCMClient::NO_DELAY_START);
400 AddAppHandlers(); 412 AddAppHandlers();
401 413
402 // GCMClient should be started after sign-in. 414 // GCMClient should be started after sign-in.
403 SignIn(kTestAccountID1); 415 SignIn(kTestAccountID1);
404 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); 416 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
405 417
406 // GCMClient should be checked out after sign-out. 418 // GCMClient should be stopped out after sign-out.
407 SignOut(); 419 SignOut();
408 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); 420 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status());
409 } 421 }
410 422
411 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMDisabled) { 423 TEST_F(GCMDriverTest, SignInAndSignOutOnGCMDisabled) {
412 // By default, GCM is enabled. 424 // By default, GCM is enabled.
413 CreateDriver(FakeGCMClient::NO_DELAY_START); 425 CreateDriver(FakeGCMClient::NO_DELAY_START);
414 AddAppHandlers(); 426 AddAppHandlers();
415 427
416 // Disable GCM. 428 // Disable GCM.
417 driver()->Disable(); 429 driver()->Disable();
418 430
419 // GCMClient should not be started after sign-in. 431 // GCMClient should not be started after sign-in.
420 SignIn(kTestAccountID1); 432 SignIn(kTestAccountID1);
421 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status()); 433 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status());
422 434
423 // Check-out should still be performed after sign-out. 435 // GCMClient should still be not started after sign-out.
424 SignOut(); 436 SignOut();
425 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); 437 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status());
426 } 438 }
427 439
428 TEST_F(GCMDriverTest, SignOutAndThenSignIn) { 440 TEST_F(GCMDriverTest, SignOutAndThenSignIn) {
429 CreateDriver(FakeGCMClient::NO_DELAY_START); 441 CreateDriver(FakeGCMClient::NO_DELAY_START);
430 AddAppHandlers(); 442 AddAppHandlers();
431 443
432 // GCMClient should be started after sign-in. 444 // GCMClient should be started after sign-in.
433 SignIn(kTestAccountID1); 445 SignIn(kTestAccountID1);
434 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); 446 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
435 447
436 // GCMClient should be checked out after sign-out. 448 // GCMClient should be stopped after sign-out.
437 SignOut(); 449 SignOut();
438 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); 450 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status());
439 451
440 // Sign-in with a different account. 452 // Sign-in with a different account.
441 SignIn(kTestAccountID2); 453 SignIn(kTestAccountID2);
442 454
443 // GCMClient should be started again. 455 // GCMClient should be started again.
444 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status()); 456 EXPECT_EQ(FakeGCMClient::STARTED, GetGCMClient()->status());
445 } 457 }
446 458
447 TEST_F(GCMDriverTest, DisableAndReenableGCM) { 459 TEST_F(GCMDriverTest, DisableAndReenableGCM) {
448 CreateDriver(FakeGCMClient::NO_DELAY_START); 460 CreateDriver(FakeGCMClient::NO_DELAY_START);
(...skipping 23 matching lines...) Expand all
472 driver()->Disable(); 484 driver()->Disable();
473 PumpIOLoop(); 485 PumpIOLoop();
474 PumpUILoop(); 486 PumpUILoop();
475 487
476 // GCMClient should be stopped. 488 // GCMClient should be stopped.
477 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status()); 489 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status());
478 490
479 // Sign out. 491 // Sign out.
480 SignOut(); 492 SignOut();
481 493
482 // GCMClient should be checked out. 494 // GCMClient should be stopped.
483 EXPECT_EQ(FakeGCMClient::CHECKED_OUT, GetGCMClient()->status()); 495 EXPECT_EQ(FakeGCMClient::STOPPED, GetGCMClient()->status());
484 } 496 }
485 497
486 TEST_F(GCMDriverTest, StartOrStopGCMOnDemand) { 498 TEST_F(GCMDriverTest, StartOrStopGCMOnDemand) {
487 CreateDriver(FakeGCMClient::NO_DELAY_START); 499 CreateDriver(FakeGCMClient::NO_DELAY_START);
488 SignIn(kTestAccountID1); 500 SignIn(kTestAccountID1);
489 501
490 // GCMClient is not started. 502 // GCMClient is not started.
491 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status()); 503 EXPECT_EQ(FakeGCMClient::UNINITIALIZED, GetGCMClient()->status());
492 504
493 // GCMClient is started after an app handler has been added. 505 // GCMClient is started after an app handler has been added.
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 // After start-up, the request should still be scheduled at the expected 1192 // After start-up, the request should still be scheduled at the expected
1181 // updated interval. 1193 // updated interval.
1182 actual_delay_seconds = 1194 actual_delay_seconds =
1183 syncer()->current_request_delay_interval().InSeconds(); 1195 syncer()->current_request_delay_interval().InSeconds();
1184 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds)) 1196 EXPECT_TRUE(CompareDelaySeconds(expected_delay_seconds, actual_delay_seconds))
1185 << "expected delay: " << expected_delay_seconds 1197 << "expected delay: " << expected_delay_seconds
1186 << " actual delay: " << actual_delay_seconds; 1198 << " actual delay: " << actual_delay_seconds;
1187 } 1199 }
1188 1200
1189 } // namespace gcm 1201 } // namespace gcm
OLDNEW
« no previous file with comments | « components/gcm_driver/gcm_driver_desktop.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698