Commit 33e14911 authored by achuith@chromium.org's avatar achuith@chromium.org

Allow max_group = 0 to pass all groups.

BUG=NONE
TEST=unit tests.

Review URL: https://chromiumcodereview.appspot.com/10704143

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146009 0039d316-1c4b-4281-b951-d872f2087c98
parent 08ec2170
...@@ -146,11 +146,11 @@ void NotificationPromo::InitFromJson(const DictionaryValue& json) { ...@@ -146,11 +146,11 @@ void NotificationPromo::InitFromJson(const DictionaryValue& json) {
grouping->GetInteger("increment_frequency", &time_slice_); grouping->GetInteger("increment_frequency", &time_slice_);
grouping->GetInteger("increment_max", &max_group_); grouping->GetInteger("increment_max", &max_group_);
DVLOG(1) << "num_groups_=" << num_groups_; DVLOG(1) << "num_groups_ = " << num_groups_
DVLOG(1) << "initial_segment_ = " << initial_segment_; << ", initial_segment_ = " << initial_segment_
DVLOG(1) << "increment_ = " << increment_; << ", increment_ = " << increment_
DVLOG(1) << "time_slice_ = " << time_slice_; << ", time_slice_ = " << time_slice_
DVLOG(1) << "max_group_ = " << max_group_; << ", max_group_ = " << max_group_;
} }
// Payload. // Payload.
...@@ -285,7 +285,7 @@ void NotificationPromo::InitFromPrefs() { ...@@ -285,7 +285,7 @@ void NotificationPromo::InitFromPrefs() {
bool NotificationPromo::CanShow() const { bool NotificationPromo::CanShow() const {
return !closed_ && return !closed_ &&
!promo_text_.empty() && !promo_text_.empty() &&
group_ < max_group_ && !ExceedsMaxGroup() &&
!ExceedsMaxViews() && !ExceedsMaxViews() &&
base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() && base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() &&
base::Time::FromDoubleT(EndTime()) > base::Time::Now() && base::Time::FromDoubleT(EndTime()) > base::Time::Now() &&
...@@ -309,6 +309,10 @@ bool NotificationPromo::HandleViewed() { ...@@ -309,6 +309,10 @@ bool NotificationPromo::HandleViewed() {
return ExceedsMaxViews(); return ExceedsMaxViews();
} }
bool NotificationPromo::ExceedsMaxGroup() const {
return (max_group_ == 0) ? false : group_ >= max_group_;
}
bool NotificationPromo::ExceedsMaxViews() const { bool NotificationPromo::ExceedsMaxViews() const {
return (max_views_ == 0) ? false : views_ >= max_views_; return (max_views_ == 0) ? false : views_ >= max_views_;
} }
......
...@@ -64,6 +64,10 @@ class NotificationPromo { ...@@ -64,6 +64,10 @@ class NotificationPromo {
// Flush data members to prefs for storage. // Flush data members to prefs for storage.
void WritePrefs(); void WritePrefs();
// Tests group_ against max_group_.
// When max_group_ is 0, all groups pass.
bool ExceedsMaxGroup() const;
// Tests views_ against max_views_. // Tests views_ against max_views_.
// When max_views_ is 0, we don't cap the number of views. // When max_views_ is 0, we don't cap the number of views.
bool ExceedsMaxViews() const; bool ExceedsMaxViews() const;
......
...@@ -197,6 +197,13 @@ class NotificationPromoTest { ...@@ -197,6 +197,13 @@ class NotificationPromoTest {
notification_promo_.group_ = i; notification_promo_.group_ = i;
EXPECT_TRUE(notification_promo_.CanShow()); EXPECT_TRUE(notification_promo_.CanShow());
} }
// When max_group_ is 0, all groups pass.
notification_promo_.max_group_ = 0;
for (int i = 0; i < num_groups_; i += incr) {
notification_promo_.group_ = i;
EXPECT_TRUE(notification_promo_.CanShow());
}
} }
void TestViews() { void TestViews() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment