summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_resource
diff options
context:
space:
mode:
authorjeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 01:42:14 +0000
committerjeremya@chromium.org <jeremya@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-20 01:42:14 +0000
commitffe65f40321c7eb3b4ddfa4f2516226a0c02da31 (patch)
tree65454b63997709d03c4249ccca01b4d76af3f84c /chrome/browser/web_resource
parentf250da5b5963b560199fba444e7bc1276a2a96a1 (diff)
downloadchromium_src-ffe65f40321c7eb3b4ddfa4f2516226a0c02da31.zip
chromium_src-ffe65f40321c7eb3b4ddfa4f2516226a0c02da31.tar.gz
chromium_src-ffe65f40321c7eb3b4ddfa4f2516226a0c02da31.tar.bz2
Add an is_app_launcher_promo key to NotificationPromo.
If the "is_app_launcher_promo" key is set in the promo payload, the promo won't be shown if the user has enabled the app launcher. Which is useful if the promo is asking the user to enable the app launcher :) R=rsesek@chromium.org BUG=178936 Review URL: https://chromiumcodereview.appspot.com/12601014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource')
-rw-r--r--chrome/browser/web_resource/notification_promo.cc11
-rw-r--r--chrome/browser/web_resource/notification_promo.h5
-rw-r--r--chrome/browser/web_resource/promo_resource_service_unittest.cc49
3 files changed, 64 insertions, 1 deletions
diff --git a/chrome/browser/web_resource/notification_promo.cc b/chrome/browser/web_resource/notification_promo.cc
index a088f32..ab89853 100644
--- a/chrome/browser/web_resource/notification_promo.cc
+++ b/chrome/browser/web_resource/notification_promo.cc
@@ -7,6 +7,7 @@
#include <cmath>
#include <vector>
+#include "apps/pref_names.h"
#include "base/bind.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/pref_service.h"
@@ -395,11 +396,21 @@ void NotificationPromo::InitFromPrefs(PromoType promo_type) {
ntp_promo->GetBoolean(kPrefPromoClosed, &closed_);
}
+bool NotificationPromo::CheckAppLauncher() const {
+ bool is_app_launcher_promo = false;
+ if (!promo_payload_->GetBoolean("is_app_launcher_promo",
+ &is_app_launcher_promo))
+ return true;
+ return !is_app_launcher_promo ||
+ !prefs_->GetBoolean(apps::prefs::kAppLauncherIsEnabled);
+}
+
bool NotificationPromo::CanShow() const {
return !closed_ &&
!promo_text_.empty() &&
!ExceedsMaxGroup() &&
!ExceedsMaxViews() &&
+ CheckAppLauncher() &&
base::Time::FromDoubleT(StartTimeForGroup()) < base::Time::Now() &&
base::Time::FromDoubleT(EndTime()) > base::Time::Now();
}
diff --git a/chrome/browser/web_resource/notification_promo.h b/chrome/browser/web_resource/notification_promo.h
index 38f57c2..f92eb1d 100644
--- a/chrome/browser/web_resource/notification_promo.h
+++ b/chrome/browser/web_resource/notification_promo.h
@@ -92,12 +92,15 @@ class NotificationPromo {
// When max_views_ is 0, we don't cap the number of views.
bool ExceedsMaxViews() const;
+ // Returns false if this promo should not be displayed because it is a promo
+ // for the app launcher, and the user has already enabled the app launcher.
+ bool CheckAppLauncher() const;
+
PrefService* prefs_;
PromoType promo_type_;
std::string promo_text_;
- // Note that promo_payload_ isn't currently used for desktop promos.
scoped_ptr<const base::DictionaryValue> promo_payload_;
double start_;
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc
index dc39286..c903c38 100644
--- a/chrome/browser/web_resource/promo_resource_service_unittest.cc
+++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc
@@ -5,6 +5,7 @@
#include <utility>
#include <vector>
+#include "apps/pref_names.h"
#include "base/json/json_reader.h"
#include "base/message_loop.h"
#include "base/prefs/pref_service.h"
@@ -334,6 +335,8 @@ class NotificationPromoTest {
EXPECT_TRUE(notification_promo_.CanShow());
}
+ const NotificationPromo& promo() const { return notification_promo_; }
+
private:
NotificationPromo notification_promo_;
bool received_notification_;
@@ -530,3 +533,49 @@ TEST_F(PromoResourceServiceTest, PromoServerURLTest) {
EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme));
// TODO(achuith): Test this better.
}
+
+TEST_F(PromoResourceServiceTest, AppLauncherPromoTest) {
+ // Check that prefs are set correctly.
+ NotificationPromoTest promo_test;
+
+ // Set up start date and promo line in a Dictionary as if parsed from the
+ // service. date[0].end is replaced with a date 1 year in the future.
+ promo_test.Init("{"
+ " \"ntp_notification_promo\": ["
+ " {"
+ " \"date\":"
+ " ["
+ " {"
+ " \"start\":\"3 Aug 1999 9:26:06 GMT\","
+ " \"end\":\"$1\""
+ " }"
+ " ],"
+ " \"grouping\":"
+ " {"
+ " \"buckets\":1000,"
+ " \"segment\":200,"
+ " \"increment\":100,"
+ " \"increment_frequency\":3600,"
+ " \"increment_max\":400"
+ " },"
+ " \"payload\":"
+ " {"
+ " \"promo_message_short\":"
+ " \"What do you think of Chrome?\","
+ " \"days_active\":7,"
+ " \"install_age_days\":21,"
+ " \"is_app_launcher_promo\":true"
+ " },"
+ " \"max_views\":30"
+ " }"
+ " ]"
+ "}",
+ "What do you think of Chrome?",
+ // The starting date is in 1999 to make tests pass
+ // on Android devices with incorrect or unset date/time.
+ 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT.
+ 1000, 200, 100, 3600, 400, 30);
+ promo_test.InitPromoFromJson(true);
+ local_state_.Get()->SetBoolean(apps::prefs::kAppLauncherIsEnabled, true);
+ EXPECT_FALSE(promo_test.promo().CanShow());
+}