Commit c67ab81f authored by achuith@chromium.org's avatar achuith@chromium.org

Preferences support for multiple promos.

* Add promo_type_. For now this is hardcoded to ntp_notification_promo, but we'll also allow bubble_promo soon.
* Store promo preferences in a dictionary, in a list, in a promo object. This reflects the structure of the promo as we receive it over the wire.
* Add ClearDeprecatedPrefs.
* Fix logic of CheckForNewNotification, HandleViewed and HandleClosed. These now call InitFromPreferences.
* Add better tests for HandleViewed and HandleClosed. Get rid of TestPrefs.

BUG=123061
TEST=unit tests.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148013 0039d316-1c4b-4281-b951-d872f2087c98
parent 94bc2ccf
...@@ -27,6 +27,9 @@ class NotificationPromo { ...@@ -27,6 +27,9 @@ class NotificationPromo {
public: public:
static GURL PromoServerURL(); static GURL PromoServerURL();
static const char kNtpNotificationPromoType[];
static const char kBubblePromoType[];
explicit NotificationPromo(Profile* profile); explicit NotificationPromo(Profile* profile);
~NotificationPromo(); ~NotificationPromo();
...@@ -79,6 +82,7 @@ class NotificationPromo { ...@@ -79,6 +82,7 @@ class NotificationPromo {
Profile* profile_; Profile* profile_;
PrefService* prefs_; PrefService* prefs_;
std::string promo_type_;
std::string promo_text_; std::string promo_text_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
std::string promo_text_long_; std::string promo_text_long_;
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <vector>
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
...@@ -108,7 +110,6 @@ class NotificationPromoTest { ...@@ -108,7 +110,6 @@ class NotificationPromoTest {
// Test the fields. // Test the fields.
TestNotification(); TestNotification();
TestPrefs();
} }
void TestNotification() { void TestNotification() {
...@@ -151,43 +152,6 @@ class NotificationPromoTest { ...@@ -151,43 +152,6 @@ class NotificationPromoTest {
EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_); EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_);
} }
void TestPrefs() {
EXPECT_EQ(prefs_->GetString(prefs::kNtpPromoLine), promo_text_);
#if defined(OS_ANDROID)
EXPECT_EQ(prefs_->GetString(prefs::kNtpPromoLineLong), promo_text_long_);
EXPECT_EQ(prefs_->GetString(prefs::kNtpPromoActionType),
promo_action_type_);
const base::ListValue* lv = prefs_->GetList(prefs::kNtpPromoActionArgs);
EXPECT_TRUE(lv != NULL);
EXPECT_EQ(lv->GetSize(), promo_action_args_.size());
for (std::size_t i = 0; i < lv->GetSize(); ++i) {
std::string value;
EXPECT_TRUE(lv->GetString(i, &value));
EXPECT_EQ(value, promo_action_args_[i]);
}
#endif // defined(OS_ANDROID)
EXPECT_EQ(prefs_->GetDouble(prefs::kNtpPromoStart), start_);
EXPECT_EQ(prefs_->GetDouble(prefs::kNtpPromoEnd), end_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoNumGroups), num_groups_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoInitialSegment),
initial_segment_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoIncrement), increment_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoGroupTimeSlice), time_slice_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoGroupMax), max_group_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoViewsMax), max_views_);
EXPECT_EQ(prefs_->GetBoolean(prefs::kNtpPromoClosed), closed_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoGroup),
notification_promo_.group_);
EXPECT_EQ(prefs_->GetInteger(prefs::kNtpPromoViews), 0);
EXPECT_EQ(prefs_->GetBoolean(prefs::kNtpPromoGplusRequired),
gplus_required_);
}
// Create a new NotificationPromo from prefs and compare to current // Create a new NotificationPromo from prefs and compare to current
// notification. // notification.
void TestInitFromPrefs() { void TestInitFromPrefs() {
...@@ -265,9 +229,22 @@ class NotificationPromoTest { ...@@ -265,9 +229,22 @@ class NotificationPromoTest {
notification_promo_.group_ = i; notification_promo_.group_ = i;
EXPECT_TRUE(notification_promo_.CanShow()); EXPECT_TRUE(notification_promo_.CanShow());
} }
notification_promo_.WritePrefs();
} }
void TestViews() { void TestViews() {
notification_promo_.views_ = notification_promo_.max_views_ - 2;
notification_promo_.WritePrefs();
NotificationPromo new_promo(profile_);
new_promo.HandleViewed();
EXPECT_TRUE(new_promo.CanShow());
new_promo.HandleViewed();
EXPECT_FALSE(new_promo.CanShow());
notification_promo_.InitFromPrefs();
EXPECT_FALSE(notification_promo_.CanShow());
// Test out of range views. // Test out of range views.
for (int i = max_views_; i < max_views_ * 2; ++i) { for (int i = max_views_; i < max_views_ * 2; ++i) {
notification_promo_.views_ = i; notification_promo_.views_ = i;
...@@ -279,14 +256,24 @@ class NotificationPromoTest { ...@@ -279,14 +256,24 @@ class NotificationPromoTest {
notification_promo_.views_ = i; notification_promo_.views_ = i;
EXPECT_TRUE(notification_promo_.CanShow()); EXPECT_TRUE(notification_promo_.CanShow());
} }
notification_promo_.WritePrefs();
} }
void TestClosed() { void TestClosed() {
NotificationPromo new_promo(profile_);
new_promo.InitFromPrefs();
EXPECT_TRUE(new_promo.CanShow());
new_promo.HandleClosed();
EXPECT_FALSE(new_promo.CanShow());
new_promo.InitFromPrefs();
EXPECT_FALSE(new_promo.CanShow());
notification_promo_.closed_ = true; notification_promo_.closed_ = true;
EXPECT_FALSE(notification_promo_.CanShow()); EXPECT_FALSE(notification_promo_.CanShow());
notification_promo_.closed_ = false; notification_promo_.closed_ = false;
EXPECT_TRUE(notification_promo_.CanShow()); EXPECT_TRUE(notification_promo_.CanShow());
notification_promo_.WritePrefs();
} }
void TestPromoText() { void TestPromoText() {
...@@ -421,9 +408,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest) { ...@@ -421,9 +408,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
NotificationPromoTest promo_test(&profile_); NotificationPromoTest promo_test(&profile_);
// Make sure prefs are unset.
promo_test.TestPrefs();
// Set up start and end dates and promo line in a Dictionary as if parsed // Set up start and end dates and promo line in a Dictionary as if parsed
// from the service. // from the service.
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
......
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