diff options
author | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 01:06:33 +0000 |
---|---|---|
committer | achuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-16 01:06:33 +0000 |
commit | c541036c46f58126f703c55e0286248752c1b873 (patch) | |
tree | b6e249b8782dd845f53d1a1711aa0ed9984e0903 /chrome/browser/web_resource | |
parent | 0d6d6c867b7f0d8ee066f8f7d1113aa627f2a0cf (diff) | |
download | chromium_src-c541036c46f58126f703c55e0286248752c1b873.zip chromium_src-c541036c46f58126f703c55e0286248752c1b873.tar.gz chromium_src-c541036c46f58126f703c55e0286248752c1b873.tar.bz2 |
Add a unit test for increments.
BUG=119373
TEST=unit tests pass.
Review URL: https://chromiumcodereview.appspot.com/10398032
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137328 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource')
-rw-r--r-- | chrome/browser/web_resource/notification_promo.cc | 2 | ||||
-rw-r--r-- | chrome/browser/web_resource/promo_resource_service_unittest.cc | 55 |
2 files changed, 51 insertions, 6 deletions
diff --git a/chrome/browser/web_resource/notification_promo.cc b/chrome/browser/web_resource/notification_promo.cc index 6f31d9b..9b8ad53 100644 --- a/chrome/browser/web_resource/notification_promo.cc +++ b/chrome/browser/web_resource/notification_promo.cc @@ -384,7 +384,7 @@ bool NotificationPromo::CanShow() const { !promo_text_.empty() && group_ < max_group_ && !ExceedsMaxViews() && - base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() && + base::Time::FromDoubleT(StartTimeForGroup()) <= base::Time::Now() && base::Time::FromDoubleT(end_) > base::Time::Now() && IsBuildAllowed(build_) && IsPlatformAllowed(platform_); diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc index 034f3d4..6b122d8 100644 --- a/chrome/browser/web_resource/promo_resource_service_unittest.cc +++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc @@ -465,7 +465,7 @@ class NotificationPromoTestDelegate : public NotificationPromo::Delegate { EXPECT_TRUE(notification_promo_->CanShow()); } - void TestText() { + void TestPromoText() { notification_promo_->promo_text_.clear(); EXPECT_FALSE(notification_promo_->CanShow()); @@ -498,6 +498,50 @@ class NotificationPromoTestDelegate : public NotificationPromo::Delegate { EXPECT_TRUE(notification_promo_->CanShow()); } + void TestIncrement() { + const double now = base::Time::Now().ToDoubleT(); + const double slice = 60; + + notification_promo_->num_groups_ = 18; + notification_promo_->initial_segment_ = 5; + notification_promo_->increment_ = 3; + notification_promo_->time_slice_ = slice; + + notification_promo_->start_ = now; + notification_promo_->end_ = now + slice; + + // Test initial segment. + notification_promo_->group_ = 4; + EXPECT_TRUE(notification_promo_->CanShow()); + notification_promo_->group_ = 5; + EXPECT_FALSE(notification_promo_->CanShow()); + + // Test first increment. + notification_promo_->start_ -= slice; + notification_promo_->group_ = 7; + EXPECT_TRUE(notification_promo_->CanShow()); + notification_promo_->group_ = 8; + EXPECT_FALSE(notification_promo_->CanShow()); + + // Test second increment. + notification_promo_->start_ -= slice; + notification_promo_->group_ = 10; + EXPECT_TRUE(notification_promo_->CanShow()); + notification_promo_->group_ = 11; + EXPECT_FALSE(notification_promo_->CanShow()); + + // Test penultimate increment. + notification_promo_->start_ -= 2 * slice; + notification_promo_->group_ = 16; + EXPECT_TRUE(notification_promo_->CanShow()); + notification_promo_->group_ = 17; + EXPECT_FALSE(notification_promo_->CanShow()); + + // Test last increment. + notification_promo_->start_ -= slice; + EXPECT_TRUE(notification_promo_->CanShow()); + } + private: Profile* profile_; PrefService* prefs_; @@ -527,7 +571,7 @@ class NotificationPromoTestDelegate : public NotificationPromo::Delegate { int current_platform_; }; -TEST_F(PromoResourceServiceTest, NotificationPromoTest) { +TEST_F(PromoResourceServiceTest, NotificationPromoTestLegacy) { // Check that prefs are set correctly. PrefService* prefs = profile_.GetPrefs(); ASSERT_TRUE(prefs != NULL); @@ -576,12 +620,12 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest) { delegate.TestViews(); delegate.TestBuild(); delegate.TestClosed(); - delegate.TestText(); + delegate.TestPromoText(); delegate.TestTime(); delegate.TestPlatforms(); } -TEST_F(PromoResourceServiceTest, NotificationPromoTest2) { +TEST_F(PromoResourceServiceTest, NotificationPromoTest) { // Check that prefs are set correctly. PrefService* prefs = profile_.GetPrefs(); ASSERT_TRUE(prefs != NULL); @@ -645,8 +689,9 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest2) { delegate.TestViews(); delegate.TestBuild(); delegate.TestClosed(); - delegate.TestText(); + delegate.TestPromoText(); delegate.TestTime(); + delegate.TestIncrement(); delegate.TestPlatforms(); } |