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 "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" |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 // Make sure that if the token was expired it is still needed. | 469 // Make sure that if the token was expired it is still needed. |
470 EXPECT_TRUE(IsFetchingRequired()); | 470 EXPECT_TRUE(IsFetchingRequired()); |
471 } | 471 } |
472 | 472 |
473 // Tests what is the expected time to the next token fetching. | 473 // Tests what is the expected time to the next token fetching. |
474 TEST_F(GCMAccountTrackerTest, GetTimeToNextTokenReporting) { | 474 TEST_F(GCMAccountTrackerTest, GetTimeToNextTokenReporting) { |
475 tracker()->Start(); | 475 tracker()->Start(); |
476 // At this point the last token fetch time is never. | 476 // At this point the last token fetch time is never. |
477 EXPECT_EQ(base::TimeDelta(), GetTimeToNextTokenReporting()); | 477 EXPECT_EQ(base::TimeDelta(), GetTimeToNextTokenReporting()); |
478 | 478 |
| 479 // Regular case. The tokens have been just reported. |
479 driver()->SetLastTokenFetchTime(base::Time::Now()); | 480 driver()->SetLastTokenFetchTime(base::Time::Now()); |
480 EXPECT_TRUE(GetTimeToNextTokenReporting() <= | 481 EXPECT_TRUE(GetTimeToNextTokenReporting() <= |
481 base::TimeDelta::FromSeconds(12 * 60 * 60)); | 482 base::TimeDelta::FromSeconds(12 * 60 * 60)); |
| 483 |
| 484 // A case when gcm driver is not yet initialized. |
| 485 driver()->SetLastTokenFetchTime(base::Time::Max()); |
| 486 EXPECT_EQ(base::TimeDelta::FromSeconds(12 * 60 * 60), |
| 487 GetTimeToNextTokenReporting()); |
| 488 |
| 489 // A case when token reporting calculation is expected to result in more than |
| 490 // 12 hours, in which case we expect exactly 12 hours. |
| 491 driver()->SetLastTokenFetchTime(base::Time::Now() + |
| 492 base::TimeDelta::FromDays(2)); |
| 493 EXPECT_EQ(base::TimeDelta::FromSeconds(12 * 60 * 60), |
| 494 GetTimeToNextTokenReporting()); |
482 } | 495 } |
483 | 496 |
484 // Tests conditions when token reporting is required. | 497 // Tests conditions when token reporting is required. |
485 TEST_F(GCMAccountTrackerTest, IsTokenReportingRequired) { | 498 TEST_F(GCMAccountTrackerTest, IsTokenReportingRequired) { |
486 tracker()->Start(); | 499 tracker()->Start(); |
487 // Required because it is overdue. | 500 // Required because it is overdue. |
488 EXPECT_TRUE(IsTokenReportingRequired()); | 501 EXPECT_TRUE(IsTokenReportingRequired()); |
489 | 502 |
490 // Not required because it just happened. | 503 // Not required because it just happened. |
491 driver()->SetLastTokenFetchTime(base::Time::Now()); | 504 driver()->SetLastTokenFetchTime(base::Time::Now()); |
492 EXPECT_FALSE(IsTokenReportingRequired()); | 505 EXPECT_FALSE(IsTokenReportingRequired()); |
493 | 506 |
494 SignInAccount(kAccountId1); | 507 SignInAccount(kAccountId1); |
495 IssueAccessToken(kAccountId1); | 508 IssueAccessToken(kAccountId1); |
496 driver()->ResetResults(); | 509 driver()->ResetResults(); |
497 // Reporting was triggered, which means testing for required will give false, | 510 // Reporting was triggered, which means testing for required will give false, |
498 // but we have the update call. | 511 // but we have the update call. |
499 SignOutAccount(kAccountId1); | 512 SignOutAccount(kAccountId1); |
500 EXPECT_TRUE(driver()->update_accounts_called()); | 513 EXPECT_TRUE(driver()->update_accounts_called()); |
501 EXPECT_FALSE(IsTokenReportingRequired()); | 514 EXPECT_FALSE(IsTokenReportingRequired()); |
502 } | 515 } |
503 | 516 |
504 // TODO(fgorski): Add test for adding account after removal >> make sure it does | 517 // TODO(fgorski): Add test for adding account after removal >> make sure it does |
505 // not mark removal. | 518 // not mark removal. |
506 | 519 |
507 } // namespace gcm | 520 } // namespace gcm |
OLD | NEW |