summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_resource
diff options
context:
space:
mode:
authordbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-04 04:45:32 +0000
committerdbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-04 04:45:32 +0000
commited30448e7fc4a1b753a305c5a63eaf3b54fa027c (patch)
tree2ad9b92bff8faec145962e444287e3d0fd7be907 /chrome/browser/web_resource
parent09d9f1527094f566e73c6a5ef7093352399172ad (diff)
downloadchromium_src-ed30448e7fc4a1b753a305c5a63eaf3b54fa027c.zip
chromium_src-ed30448e7fc4a1b753a305c5a63eaf3b54fa027c.tar.gz
chromium_src-ed30448e7fc4a1b753a305c5a63eaf3b54fa027c.tar.bz2
Move PromoResourceService from Profile to BrowserProcessImpl/local_state().
TBR=rsesek@chromium.org BUG=120996,143773 TEST=tests pass, we still get promos, less crud on profile. Review URL: https://codereview.chromium.org/11689004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175103 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource')
-rw-r--r--chrome/browser/web_resource/notification_promo.cc45
-rw-r--r--chrome/browser/web_resource/notification_promo.h15
-rw-r--r--chrome/browser/web_resource/notification_promo_mobile_ntp.cc9
-rw-r--r--chrome/browser/web_resource/notification_promo_mobile_ntp.h4
-rw-r--r--chrome/browser/web_resource/promo_resource_service.cc27
-rw-r--r--chrome/browser/web_resource/promo_resource_service.h7
-rw-r--r--chrome/browser/web_resource/promo_resource_service_mobile_ntp_unittest.cc36
-rw-r--r--chrome/browser/web_resource/promo_resource_service_unittest.cc99
8 files changed, 79 insertions, 163 deletions
diff --git a/chrome/browser/web_resource/notification_promo.cc b/chrome/browser/web_resource/notification_promo.cc
index 692d305..9cfbd20 100644
--- a/chrome/browser/web_resource/notification_promo.cc
+++ b/chrome/browser/web_resource/notification_promo.cc
@@ -12,10 +12,13 @@
#include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/sys_info.h"
+#include "base/threading/thread_restrictions.h"
#include "base/time.h"
#include "base/values.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile_impl.h"
+#include "chrome/browser/prefs/pref_service_simple.h"
+#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/web_resource/promo_resource_service.h"
#include "chrome/common/chrome_version_info.h"
#include "chrome/common/net/url_util.h"
@@ -53,7 +56,6 @@ const char kPrefPromoMaxViews[] = "max_views";
const char kPrefPromoGroup[] = "group";
const char kPrefPromoViews[] = "views";
const char kPrefPromoClosed[] = "closed";
-const char kPrefPromoGPlusRequired[] = "gplus_required";
// Returns a string suitable for the Promo Server URL 'osname' value.
std::string PlatformString() {
@@ -189,9 +191,8 @@ void AppendQueryParameter(GURL* url,
} // namespace
-NotificationPromo::NotificationPromo(Profile* profile)
- : profile_(profile),
- prefs_(profile_->GetPrefs()),
+NotificationPromo::NotificationPromo()
+ : prefs_(g_browser_process->local_state()),
promo_type_(NO_PROMO),
promo_payload_(new base::DictionaryValue()),
start_(0.0),
@@ -205,9 +206,7 @@ NotificationPromo::NotificationPromo(Profile* profile)
group_(0),
views_(0),
closed_(false),
- gplus_required_(false),
new_notification_(false) {
- DCHECK(profile);
DCHECK(prefs_);
}
@@ -271,9 +270,6 @@ void NotificationPromo::InitFromJson(const DictionaryValue& json,
// Payload.
const DictionaryValue* payload = NULL;
if (promo->GetDictionary("payload", &payload)) {
- payload->GetBoolean("gplus_required", &gplus_required_);
- DVLOG(1) << "gplus_required_ = " << gplus_required_;
-
base::Value* ppcopy = DeepCopyAndResolveStrings(payload, strings);
DCHECK(ppcopy && ppcopy->IsType(base::Value::TYPE_DICTIONARY));
promo_payload_.reset(static_cast<base::DictionaryValue*>(ppcopy));
@@ -296,7 +292,7 @@ void NotificationPromo::InitFromJson(const DictionaryValue& json,
}
void NotificationPromo::CheckForNewNotification() {
- NotificationPromo old_promo(profile_);
+ NotificationPromo old_promo;
old_promo.InitFromPrefs(promo_type_);
const double old_start = old_promo.start_;
const double old_end = old_promo.end_;
@@ -316,10 +312,16 @@ void NotificationPromo::OnNewNotification() {
}
// static
+void NotificationPromo::RegisterPrefs(PrefServiceSimple* local_state) {
+ local_state->RegisterDictionaryPref(kPrefPromoObject);
+}
+
+// static
void NotificationPromo::RegisterUserPrefs(PrefServiceSyncable* prefs) {
+ // TODO(dbeam): Remove in M28 when we're reasonably sure all prefs are gone.
prefs->RegisterDictionaryPref(kPrefPromoObject,
- new base::DictionaryValue,
PrefServiceSyncable::UNSYNCABLE_PREF);
+ prefs->ClearPref(kPrefPromoObject);
}
void NotificationPromo::WritePrefs() {
@@ -341,8 +343,6 @@ void NotificationPromo::WritePrefs() {
ntp_promo->SetInteger(kPrefPromoViews, views_);
ntp_promo->SetBoolean(kPrefPromoClosed, closed_);
- ntp_promo->SetBoolean(kPrefPromoGPlusRequired, gplus_required_);
-
base::ListValue* promo_list = new base::ListValue;
promo_list->Set(0, ntp_promo); // Only support 1 promo for now.
@@ -389,8 +389,6 @@ void NotificationPromo::InitFromPrefs(PromoType promo_type) {
ntp_promo->GetInteger(kPrefPromoGroup, &group_);
ntp_promo->GetInteger(kPrefPromoViews, &views_);
ntp_promo->GetBoolean(kPrefPromoClosed, &closed_);
-
- ntp_promo->GetBoolean(kPrefPromoGPlusRequired, &gplus_required_);
}
bool NotificationPromo::CanShow() const {
@@ -399,14 +397,13 @@ bool NotificationPromo::CanShow() const {
!ExceedsMaxGroup() &&
!ExceedsMaxViews() &&
base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() &&
- base::Time::FromDoubleT(EndTime()) > base::Time::Now() &&
- IsGPlusRequired();
+ base::Time::FromDoubleT(EndTime()) > base::Time::Now();
}
// static
-void NotificationPromo::HandleClosed(Profile* profile, PromoType promo_type) {
+void NotificationPromo::HandleClosed(PromoType promo_type) {
content::RecordAction(UserMetricsAction("NTPPromoClosed"));
- NotificationPromo promo(profile);
+ NotificationPromo promo;
promo.InitFromPrefs(promo_type);
if (!promo.closed_) {
promo.closed_ = true;
@@ -415,9 +412,9 @@ void NotificationPromo::HandleClosed(Profile* profile, PromoType promo_type) {
}
// static
-bool NotificationPromo::HandleViewed(Profile* profile, PromoType promo_type) {
+bool NotificationPromo::HandleViewed(PromoType promo_type) {
content::RecordAction(UserMetricsAction("NTPPromoShown"));
- NotificationPromo promo(profile);
+ NotificationPromo promo;
promo.InitFromPrefs(promo_type);
++promo.views_;
promo.WritePrefs();
@@ -432,10 +429,6 @@ bool NotificationPromo::ExceedsMaxViews() const {
return (max_views_ == 0) ? false : views_ >= max_views_;
}
-bool NotificationPromo::IsGPlusRequired() const {
- return !gplus_required_ || prefs_->GetBoolean(prefs::kIsGooglePlusUser);
-}
-
// static
GURL NotificationPromo::PromoServerURL() {
GURL url(promo_server_url);
diff --git a/chrome/browser/web_resource/notification_promo.h b/chrome/browser/web_resource/notification_promo.h
index f3b2c5b..84c5e2b 100644
--- a/chrome/browser/web_resource/notification_promo.h
+++ b/chrome/browser/web_resource/notification_promo.h
@@ -19,8 +19,8 @@ class ListValue;
}
class PrefService;
+class PrefServiceSimple;
class PrefServiceSyncable;
-class Profile;
// Helper class for PromoResourceService that parses promo notification info
// from json or prefs.
@@ -35,7 +35,7 @@ class NotificationPromo {
MOBILE_NTP_SYNC_PROMO,
};
- explicit NotificationPromo(Profile* profile);
+ NotificationPromo();
~NotificationPromo();
// Initialize from json/prefs.
@@ -52,10 +52,10 @@ class NotificationPromo {
// Helpers for NewTabPageHandler.
// Mark the promo as closed when the user dismisses it.
- static void HandleClosed(Profile* profile, PromoType promo_type);
+ static void HandleClosed(PromoType promo_type);
// Mark the promo has having been viewed. This returns true if views
// exceeds the maximum allowed.
- static bool HandleViewed(Profile* profile, PromoType promo_type);
+ static bool HandleViewed(PromoType promo_type);
bool new_notification() const { return new_notification_; }
@@ -66,6 +66,7 @@ class NotificationPromo {
}
// Register preferences.
+ static void RegisterPrefs(PrefServiceSimple* local_state);
static void RegisterUserPrefs(PrefServiceSyncable* prefs);
private:
@@ -90,10 +91,6 @@ class NotificationPromo {
// When max_views_ is 0, we don't cap the number of views.
bool ExceedsMaxViews() const;
- // True if this promo is not targeted to G+ users, or if this is a G+ user.
- bool IsGPlusRequired() const;
-
- Profile* profile_;
PrefService* prefs_;
PromoType promo_type_;
@@ -118,8 +115,6 @@ class NotificationPromo {
int views_;
bool closed_;
- bool gplus_required_;
-
bool new_notification_;
DISALLOW_COPY_AND_ASSIGN(NotificationPromo);
diff --git a/chrome/browser/web_resource/notification_promo_mobile_ntp.cc b/chrome/browser/web_resource/notification_promo_mobile_ntp.cc
index 3676c81..e8956d1 100644
--- a/chrome/browser/web_resource/notification_promo_mobile_ntp.cc
+++ b/chrome/browser/web_resource/notification_promo_mobile_ntp.cc
@@ -5,15 +5,12 @@
#include "chrome/browser/web_resource/notification_promo_mobile_ntp.h"
#include "base/values.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_resource/notification_promo.h"
-
-NotificationPromoMobileNtp::NotificationPromoMobileNtp(Profile* profile)
+NotificationPromoMobileNtp::NotificationPromoMobileNtp()
: valid_(false),
action_args_(NULL),
- payload_(NULL),
- notification_promo_(profile) {
+ payload_(NULL) {
}
NotificationPromoMobileNtp::~NotificationPromoMobileNtp() {
@@ -55,7 +52,7 @@ bool NotificationPromoMobileNtp::InitFromNotificationPromo() {
return false;
}
- // The rest of the fields is optional.
+ // The rest of the fields are optional.
valid_ = true;
payload_->GetBoolean("promo_requires_mobile_only_sync",
&requires_mobile_only_sync_);
diff --git a/chrome/browser/web_resource/notification_promo_mobile_ntp.h b/chrome/browser/web_resource/notification_promo_mobile_ntp.h
index 90ce5fd..7c8daef 100644
--- a/chrome/browser/web_resource/notification_promo_mobile_ntp.h
+++ b/chrome/browser/web_resource/notification_promo_mobile_ntp.h
@@ -10,8 +10,6 @@
#include "base/basictypes.h"
#include "chrome/browser/web_resource/notification_promo.h"
-class Profile;
-
namespace base {
class DictionaryValue;
class ListValue;
@@ -20,7 +18,7 @@ class ListValue;
// Helper class for NotificationPromo that deals with mobile_ntp promos.
class NotificationPromoMobileNtp {
public:
- explicit NotificationPromoMobileNtp(Profile* profile_);
+ NotificationPromoMobileNtp();
~NotificationPromoMobileNtp();
// Initialize from prefs/JSON.
diff --git a/chrome/browser/web_resource/promo_resource_service.cc b/chrome/browser/web_resource/promo_resource_service.cc
index b354b30..7e34187 100644
--- a/chrome/browser/web_resource/promo_resource_service.cc
+++ b/chrome/browser/web_resource/promo_resource_service.cc
@@ -10,8 +10,8 @@
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/prefs/pref_service_simple.h"
+#include "chrome/browser/prefs/pref_service_syncable.h"
#include "chrome/browser/web_resource/notification_promo.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
@@ -33,7 +33,7 @@ const int kTestCacheUpdateDelay = 3 * 60 * 1000;
// to versions with different types of promos).
const int kPromoServiceVersion = 7;
-// The promotion type used for Unpack() and ScheduleNotificationOnInit.
+// The promotion type used for Unpack() and ScheduleNotificationOnInit().
const NotificationPromo::PromoType kValidPromoTypes[] = {
#if defined(OS_ANDROID) || defined(OS_IOS)
NotificationPromo::MOBILE_NTP_SYNC_PROMO,
@@ -62,32 +62,27 @@ int GetCacheUpdateDelay() {
// static
void PromoResourceService::RegisterPrefs(PrefServiceSimple* local_state) {
- // TODO(achuith): Delete this in M26. http://crbug.com/143773
- // The promo service version number, and last locale.
- const char kNtpPromoVersion[] = "ntp.promo_version";
- const char kNtpPromoLocale[] = "ntp.promo_locale";
- local_state->RegisterIntegerPref(kNtpPromoVersion, 0);
- local_state->RegisterStringPref(kNtpPromoLocale, std::string());
- local_state->ClearPref(kNtpPromoVersion);
- local_state->ClearPref(kNtpPromoLocale);
+ local_state->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate, "0");
+ NotificationPromo::RegisterPrefs(local_state);
}
// static
void PromoResourceService::RegisterUserPrefs(PrefServiceSyncable* prefs) {
+ // TODO(dbeam): remove in M28 when all prefs have been cleared.
prefs->RegisterStringPref(prefs::kNtpPromoResourceCacheUpdate,
"0",
PrefServiceSyncable::UNSYNCABLE_PREF);
+ prefs->ClearPref(prefs::kNtpPromoResourceCacheUpdate);
NotificationPromo::RegisterUserPrefs(prefs);
}
-PromoResourceService::PromoResourceService(Profile* profile)
- : WebResourceService(profile->GetPrefs(),
+PromoResourceService::PromoResourceService()
+ : WebResourceService(g_browser_process->local_state(),
GetPromoResourceURL(),
true, // append locale to URL
prefs::kNtpPromoResourceCacheUpdate,
kStartResourceFetchDelay,
GetCacheUpdateDelay()),
- profile_(profile),
ALLOW_THIS_IN_INITIALIZER_LIST(
weak_ptr_factory_(this)) {
ScheduleNotificationOnInit();
@@ -132,7 +127,7 @@ void PromoResourceService::ScheduleNotificationOnInit() {
// If the promo start is in the future, set a notification task to
// invalidate the NTP cache at the time of the promo start.
for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) {
- NotificationPromo notification_promo(profile_);
+ NotificationPromo notification_promo;
notification_promo.InitFromPrefs(kValidPromoTypes[i]);
ScheduleNotification(notification_promo);
}
@@ -166,7 +161,7 @@ void PromoResourceService::PromoResourceStateChange() {
void PromoResourceService::Unpack(const DictionaryValue& parsed_json) {
for (size_t i = 0; i < arraysize(kValidPromoTypes); ++i) {
- NotificationPromo notification_promo(profile_);
+ NotificationPromo notification_promo;
notification_promo.InitFromJson(parsed_json, kValidPromoTypes[i]);
if (notification_promo.new_notification())
ScheduleNotification(notification_promo);
diff --git a/chrome/browser/web_resource/promo_resource_service.h b/chrome/browser/web_resource/promo_resource_service.h
index e55e59a..22d1ba7 100644
--- a/chrome/browser/web_resource/promo_resource_service.h
+++ b/chrome/browser/web_resource/promo_resource_service.h
@@ -17,7 +17,6 @@ class DictionaryValue;
class NotificationPromo;
class PrefServiceSimple;
class PrefServiceSyncable;
-class Profile;
// A PromoResourceService fetches data from a web resource server to be used to
// dynamically change the appearance of the New Tab Page. For example, it has
@@ -26,10 +25,9 @@ class Profile;
class PromoResourceService : public WebResourceService {
public:
static void RegisterPrefs(PrefServiceSimple* local_state);
-
static void RegisterUserPrefs(PrefServiceSyncable* prefs);
- explicit PromoResourceService(Profile* profile);
+ PromoResourceService();
private:
virtual ~PromoResourceService();
@@ -55,9 +53,6 @@ class PromoResourceService : public WebResourceService {
// WebResourceService override to process the parsed information.
virtual void Unpack(const base::DictionaryValue& parsed_json) OVERRIDE;
- // The profile this service belongs to.
- Profile* profile_;
-
// Allows the creation of tasks to send a notification.
// This allows the PromoResourceService to notify the New Tab Page immediately
// when a new web resource should be shown or removed.
diff --git a/chrome/browser/web_resource/promo_resource_service_mobile_ntp_unittest.cc b/chrome/browser/web_resource/promo_resource_service_mobile_ntp_unittest.cc
index 89c7488..0ed340b 100644
--- a/chrome/browser/web_resource/promo_resource_service_mobile_ntp_unittest.cc
+++ b/chrome/browser/web_resource/promo_resource_service_mobile_ntp_unittest.cc
@@ -11,15 +11,12 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/prefs/browser_prefs.h"
-#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/web_resource/notification_promo.h"
#include "chrome/browser/web_resource/promo_resource_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
-#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -29,24 +26,22 @@
class PromoResourceServiceMobileNtpTest : public testing::Test {
public:
PromoResourceServiceMobileNtpTest()
- : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)),
- web_resource_service_(new PromoResourceService(&profile_)) {
+ : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) {
+ static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(
+ local_state_.Get());
+ // |promo_resource_service_| must be created after local state is set.
+ promo_resource_service_ = new PromoResourceService;
}
protected:
- TestingProfile profile_;
ScopedTestingLocalState local_state_;
- scoped_refptr<PromoResourceService> web_resource_service_;
+ scoped_refptr<PromoResourceService> promo_resource_service_;
MessageLoop loop_;
};
class NotificationPromoMobileNtpTest {
public:
- explicit NotificationPromoMobileNtpTest(Profile* profile)
- : profile_(profile),
- prefs_(profile->GetPrefs()),
- mobile_promo_(profile),
- received_notification_(false) {
+ NotificationPromoMobileNtpTest() : received_notification_(false) {
}
void Init(const std::string& json,
@@ -72,8 +67,7 @@ class NotificationPromoMobileNtpTest {
}
void InitPromoFromJson(bool should_receive_notification) {
- const bool rv = mobile_promo_.InitFromJson(*test_json_);
- EXPECT_TRUE(rv);
+ EXPECT_TRUE(mobile_promo_.InitFromJson(*test_json_));
EXPECT_TRUE(mobile_promo_.valid());
EXPECT_EQ(should_receive_notification,
mobile_promo_.notification_promo().new_notification());
@@ -102,9 +96,8 @@ class NotificationPromoMobileNtpTest {
// Create a new NotificationPromo from prefs and compare to current
// notification.
void TestInitFromPrefs() {
- NotificationPromoMobileNtp prefs_mobile_promo(profile_);
- const bool rv = prefs_mobile_promo.InitFromPrefs();
- EXPECT_TRUE(rv);
+ NotificationPromoMobileNtp prefs_mobile_promo;
+ EXPECT_TRUE(prefs_mobile_promo.InitFromPrefs());
EXPECT_TRUE(prefs_mobile_promo.valid());
EXPECT_TRUE(mobile_promo_.valid());
@@ -131,8 +124,6 @@ class NotificationPromoMobileNtpTest {
}
private:
- Profile* profile_;
- PrefService* prefs_;
NotificationPromoMobileNtp mobile_promo_;
bool received_notification_;
scoped_ptr<DictionaryValue> test_json_;
@@ -144,11 +135,7 @@ class NotificationPromoMobileNtpTest {
};
TEST_F(PromoResourceServiceMobileNtpTest, NotificationPromoMobileNtpTest) {
- // Check that prefs are set correctly.
- PrefService* prefs = profile_.GetPrefs();
- ASSERT_TRUE(prefs);
-
- NotificationPromoMobileNtpTest promo_test(&profile_);
+ NotificationPromoMobileNtpTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed
// from the service.
@@ -175,7 +162,6 @@ TEST_F(PromoResourceServiceMobileNtpTest, NotificationPromoMobileNtpTest) {
" \"payload\":"
" {"
" \"payload_format_version\":3,"
- " \"gplus_required\":false,"
" \"promo_message_long\":"
" \"MOBILE_PROMO_CHROME_LONG_TEXT\","
" \"promo_message_short\":"
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc
index 4a58d69..71f5b28 100644
--- a/chrome/browser/web_resource/promo_resource_service_unittest.cc
+++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc
@@ -17,9 +17,9 @@
#include "chrome/browser/web_resource/promo_resource_service.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_pref_service.h"
-#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
#include "net/url_request/test_url_fetcher_factory.h"
@@ -28,24 +28,23 @@
class PromoResourceServiceTest : public testing::Test {
public:
PromoResourceServiceTest()
- : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)),
- web_resource_service_(new PromoResourceService(&profile_)) {
+ : local_state_(static_cast<TestingBrowserProcess*>(g_browser_process)) {
+ static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(
+ local_state_.Get());
+ // |promo_resource_service_| must be created after local state is set.
+ promo_resource_service_ = new PromoResourceService;
}
protected:
- TestingProfile profile_;
ScopedTestingLocalState local_state_;
- scoped_refptr<PromoResourceService> web_resource_service_;
+ scoped_refptr<PromoResourceService> promo_resource_service_;
MessageLoop loop_;
};
class NotificationPromoTest {
public:
- explicit NotificationPromoTest(Profile* profile)
- : profile_(profile),
- prefs_(profile->GetPrefs()),
- notification_promo_(profile),
- received_notification_(false),
+ NotificationPromoTest()
+ : received_notification_(false),
start_(0.0),
end_(0.0),
num_groups_(0),
@@ -54,16 +53,14 @@ class NotificationPromoTest {
time_slice_(0),
max_group_(0),
max_views_(0),
- closed_(false),
- gplus_required_(false) {
+ closed_(false) {
}
void Init(const std::string& json,
const std::string& promo_text,
double start, double end,
int num_groups, int initial_segment, int increment,
- int time_slice, int max_group, int max_views,
- bool gplus_required) {
+ int time_slice, int max_group, int max_views) {
Value* value(base::JSONReader::Read(json));
ASSERT_TRUE(value);
DictionaryValue* dict = NULL;
@@ -85,8 +82,6 @@ class NotificationPromoTest {
max_views_ = max_views;
- gplus_required_ = gplus_required;
-
closed_ = false;
received_notification_ = false;
}
@@ -122,14 +117,12 @@ class NotificationPromoTest {
// Views should be 0 for now.
EXPECT_EQ(notification_promo_.views_, 0);
-
- EXPECT_EQ(notification_promo_.gplus_required_, gplus_required_);
}
// Create a new NotificationPromo from prefs and compare to current
// notification.
void TestInitFromPrefs() {
- NotificationPromo prefs_notification_promo(profile_);
+ NotificationPromo prefs_notification_promo;
prefs_notification_promo.InitFromPrefs(promo_type_);
EXPECT_EQ(notification_promo_.prefs_,
@@ -158,8 +151,6 @@ class NotificationPromoTest {
prefs_notification_promo.views_);
EXPECT_EQ(notification_promo_.closed_,
prefs_notification_promo.closed_);
- EXPECT_EQ(notification_promo_.gplus_required_,
- prefs_notification_promo.gplus_required_);
}
void TestGroup() {
@@ -189,12 +180,12 @@ class NotificationPromoTest {
notification_promo_.views_ = notification_promo_.max_views_ - 2;
notification_promo_.WritePrefs();
- NotificationPromo::HandleViewed(profile_, promo_type_);
- NotificationPromo new_promo(profile_);
+ NotificationPromo::HandleViewed(promo_type_);
+ NotificationPromo new_promo;
new_promo.InitFromPrefs(promo_type_);
EXPECT_EQ(new_promo.max_views_ - 1, new_promo.views_);
EXPECT_TRUE(new_promo.CanShow());
- NotificationPromo::HandleViewed(profile_, promo_type_);
+ NotificationPromo::HandleViewed(promo_type_);
new_promo.InitFromPrefs(promo_type_);
EXPECT_EQ(new_promo.max_views_, new_promo.views_);
EXPECT_FALSE(new_promo.CanShow());
@@ -214,12 +205,12 @@ class NotificationPromoTest {
}
void TestClosed() {
- NotificationPromo new_promo(profile_);
+ NotificationPromo new_promo;
new_promo.InitFromPrefs(promo_type_);
EXPECT_FALSE(new_promo.closed_);
EXPECT_TRUE(new_promo.CanShow());
- NotificationPromo::HandleClosed(profile_, promo_type_);
+ NotificationPromo::HandleClosed(promo_type_);
new_promo.InitFromPrefs(promo_type_);
EXPECT_TRUE(new_promo.closed_);
EXPECT_FALSE(new_promo.CanShow());
@@ -306,27 +297,7 @@ class NotificationPromoTest {
EXPECT_TRUE(notification_promo_.CanShow());
}
- void TestGplus() {
- notification_promo_.gplus_required_ = true;
-
- // Test G+ required.
- notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, true);
- EXPECT_TRUE(notification_promo_.CanShow());
- notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, false);
- EXPECT_FALSE(notification_promo_.CanShow());
-
- notification_promo_.gplus_required_ = false;
-
- // Test G+ not required.
- notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, true);
- EXPECT_TRUE(notification_promo_.CanShow());
- notification_promo_.prefs_->SetBoolean(prefs::kIsGooglePlusUser, false);
- EXPECT_TRUE(notification_promo_.CanShow());
- }
-
private:
- Profile* profile_;
- PrefService* prefs_;
NotificationPromo notification_promo_;
bool received_notification_;
scoped_ptr<DictionaryValue> test_json_;
@@ -346,8 +317,6 @@ class NotificationPromoTest {
int max_views_;
bool closed_;
-
- bool gplus_required_;
};
// Test that everything gets parsed correctly, notifications are sent,
@@ -356,10 +325,7 @@ class NotificationPromoTest {
// no payload.promo_short_message is specified in the JSON response.
TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
// Check that prefs are set correctly.
- PrefService* prefs = profile_.GetPrefs();
- ASSERT_TRUE(prefs != NULL);
-
- NotificationPromoTest promo_test(&profile_);
+ NotificationPromoTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed
// from the service.
@@ -389,8 +355,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
" \"payload\":"
" {"
" \"days_active\":7,"
- " \"install_age_days\":21,"
- " \"gplus_required\":false"
+ " \"install_age_days\":21"
" },"
" \"max_views\":30"
" }"
@@ -401,7 +366,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
// on Android devices with incorrect or unset date/time.
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT.
1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST.
- 1000, 200, 100, 3600, 400, 30, false);
+ 1000, 200, 100, 3600, 400, 30);
promo_test.InitPromoFromJson(true);
@@ -418,16 +383,12 @@ TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
promo_test.TestPromoText();
promo_test.TestTime();
promo_test.TestIncrement();
- promo_test.TestGplus();
}
// Test that payload.promo_message_short is used if present.
TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
// Check that prefs are set correctly.
- PrefService* prefs = profile_.GetPrefs();
- ASSERT_TRUE(prefs != NULL);
-
- NotificationPromoTest promo_test(&profile_);
+ NotificationPromoTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed
// from the service.
@@ -454,8 +415,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
" \"promo_message_short\":"
" \"What do you think of Chrome?\","
" \"days_active\":7,"
- " \"install_age_days\":21,"
- " \"gplus_required\":false"
+ " \"install_age_days\":21"
" },"
" \"max_views\":30"
" }"
@@ -466,7 +426,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
// on Android devices with incorrect or unset date/time.
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT.
1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST.
- 1000, 200, 100, 3600, 400, 30, false);
+ 1000, 200, 100, 3600, 400, 30);
promo_test.InitPromoFromJson(true);
// Second time should not trigger a notification.
@@ -477,10 +437,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
// Test that strings.|payload.promo_message_short| is used if present.
TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
// Check that prefs are set correctly.
- PrefService* prefs = profile_.GetPrefs();
- ASSERT_TRUE(prefs != NULL);
-
- NotificationPromoTest promo_test(&profile_);
+ NotificationPromoTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed
// from the service.
@@ -513,8 +470,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
" \"promo_message_short\":"
" \"GOOD_STRING\","
" \"days_active\":7,"
- " \"install_age_days\":21,"
- " \"gplus_required\":false"
+ " \"install_age_days\":21"
" },"
" \"max_views\":30"
" }"
@@ -525,7 +481,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
// on Android devices with incorrect or unset date/time.
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT.
1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST.
- 1000, 200, 100, 3600, 400, 30, false);
+ 1000, 200, 100, 3600, 400, 30);
promo_test.InitPromoFromJson(true);
// Second time should not trigger a notification.
@@ -536,6 +492,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
TEST_F(PromoResourceServiceTest, PromoServerURLTest) {
GURL promo_server_url = NotificationPromo::PromoServerURL();
EXPECT_FALSE(promo_server_url.is_empty());
- EXPECT_TRUE(promo_server_url.SchemeIs("https"));
+ EXPECT_TRUE(promo_server_url.is_valid());
+ EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme));
// TODO(achuith): Test this better.
}