summaryrefslogtreecommitdiffstats
path: root/chrome/browser/web_resource
diff options
context:
space:
mode:
authorjstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-07 00:16:33 +0000
committerjstritar@chromium.org <jstritar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-07 00:16:33 +0000
commitb6aed736288188a2b52d8d514f767cfcd666b897 (patch)
treefe53a149d1e5a7706de09eea372749da9524e2e0 /chrome/browser/web_resource
parentfe8fec4d1562053f464fc6b2c960e51498e6a74f (diff)
downloadchromium_src-b6aed736288188a2b52d8d514f767cfcd666b897.zip
chromium_src-b6aed736288188a2b52d8d514f767cfcd666b897.tar.gz
chromium_src-b6aed736288188a2b52d8d514f767cfcd666b897.tar.bz2
Updates when the web store promo and apps section is displayed on NTP.
The NTP will now show the apps section even if the web store promo fails to parse. The presence of part of the promo triggers the apps section. This also adds the ability to choose what users will maximize a given web store promo and apps section. The promo can be maximized for no users, existing users, new users or everyone. BUG=84561 TEST=PromoResourceServiceTest, ExtensionAppsPromo Review URL: http://codereview.chromium.org/7054076 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88061 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource')
-rw-r--r--chrome/browser/web_resource/promo_resource_service.cc20
-rw-r--r--chrome/browser/web_resource/promo_resource_service.h2
-rw-r--r--chrome/browser/web_resource/promo_resource_service_unittest.cc30
3 files changed, 47 insertions, 5 deletions
diff --git a/chrome/browser/web_resource/promo_resource_service.cc b/chrome/browser/web_resource/promo_resource_service.cc
index f66e791..5c55bea 100644
--- a/chrome/browser/web_resource/promo_resource_service.cc
+++ b/chrome/browser/web_resource/promo_resource_service.cc
@@ -303,6 +303,7 @@ void PromoResourceService::UnpackWebStoreSignal(
DictionaryValue* topic_dict;
ListValue* answer_list;
+ bool is_webstore_active = false;
bool signal_found = false;
std::string promo_id = "";
std::string promo_header = "";
@@ -310,6 +311,7 @@ void PromoResourceService::UnpackWebStoreSignal(
std::string promo_link = "";
std::string promo_expire = "";
std::string promo_logo = "";
+ int maximize_setting = 0;
int target_builds = 0;
if (!parsed_json.GetDictionary("topic", &topic_dict) ||
@@ -334,6 +336,10 @@ void PromoResourceService::UnpackWebStoreSignal(
if (split == std::string::npos || name.substr(0, split) != "webstore_promo")
continue;
+ // If the "webstore_promo" string was found, that's enough to activate the
+ // apps section even if the rest of the promo fails parsing.
+ is_webstore_active = true;
+
// (2) an integer specifying which builds the promo targets
name = name.substr(split+1);
split = name.find(':');
@@ -341,7 +347,14 @@ void PromoResourceService::UnpackWebStoreSignal(
!base::StringToInt(name.substr(0, split), &target_builds))
continue;
- // (3) optional text that specifies a URL of a logo image
+ // (3) an integer specifying what users should maximize the promo
+ name = name.substr(split+1);
+ split = name.find(':');
+ if (split == std::string::npos ||
+ !base::StringToInt(name.substr(0, split), &maximize_setting))
+ continue;
+
+ // (4) optional text that specifies a URL of a logo image
promo_logo = name.substr(split+1);
if (!a_dic->GetString(kAnswerIdProperty, &promo_id) ||
@@ -354,7 +367,8 @@ void PromoResourceService::UnpackWebStoreSignal(
if (IsThisBuildTargeted(target_builds)) {
// Store the first web store promo that targets the current build.
AppsPromo::SetPromo(promo_id, promo_header, promo_button,
- GURL(promo_link), promo_expire, GURL(promo_logo));
+ GURL(promo_link), promo_expire, GURL(promo_logo),
+ maximize_setting);
signal_found = true;
break;
}
@@ -365,6 +379,8 @@ void PromoResourceService::UnpackWebStoreSignal(
AppsPromo::ClearPromo();
}
+ AppsPromo::SetWebStoreSupportedForLocale(is_webstore_active);
+
NotificationService::current()->Notify(
NotificationType::WEB_STORE_PROMO_LOADED,
Source<PromoResourceService>(this),
diff --git a/chrome/browser/web_resource/promo_resource_service.h b/chrome/browser/web_resource/promo_resource_service.h
index ad1af83..469abf0 100644
--- a/chrome/browser/web_resource/promo_resource_service.h
+++ b/chrome/browser/web_resource/promo_resource_service.h
@@ -48,6 +48,8 @@ class PromoResourceService
FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackLogoSignal);
FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackPromoSignal);
FRIEND_TEST_ALL_PREFIXES(PromoResourceServiceTest, UnpackWebStoreSignal);
+ FRIEND_TEST_ALL_PREFIXES(
+ PromoResourceServiceTest, UnpackPartialWebStoreSignal);
// Identifies types of Chrome builds for promo targeting.
enum BuildType {
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc
index cd6f141..218af2f 100644
--- a/chrome/browser/web_resource/promo_resource_service_unittest.cc
+++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc
@@ -169,14 +169,12 @@ TEST_F(PromoResourceServiceTest, UnpackPromoSignal) {
TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) {
web_resource_service_->set_channel(platform_util::CHANNEL_DEV);
- // Set up start and end dates and promo line in a Dictionary as if parsed
- // from the service.
std::string json = "{ "
" \"topic\": {"
" \"answers\": ["
" {"
" \"answer_id\": \"341252\","
- " \"name\": \"webstore_promo:15:\","
+ " \"name\": \"webstore_promo:15:1:\","
" \"question\": \"The header!\","
" \"inproduct_target\": \"The button label!\","
" \"inproduct\": \"http://link.com\","
@@ -201,10 +199,36 @@ TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) {
EXPECT_EQ("The button label!", AppsPromo::GetPromoButtonText());
EXPECT_EQ(GURL("http://link.com"), AppsPromo::GetPromoLink());
EXPECT_EQ("No thanks, hide this.", AppsPromo::GetPromoExpireText());
+ EXPECT_EQ(AppsPromo::USERS_NEW, AppsPromo::GetPromoUserGroup());
EXPECT_EQ(GURL("chrome://theme/IDR_WEBSTORE_ICON"),
AppsPromo::GetPromoLogo());
}
+// Tests that the "web store active" flag is set even when the web store promo
+// fails parsing.
+TEST_F(PromoResourceServiceTest, UnpackPartialWebStoreSignal) {
+ std::string json = "{ "
+ " \"topic\": {"
+ " \"answers\": ["
+ " {"
+ " \"answer_id\": \"sdlfj32\","
+ " \"name\": \"webstore_promo:#klsdjlfSD\""
+ " }"
+ " ]"
+ " }"
+ "}";
+ scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>(
+ base::JSONReader::Read(json, false)));
+
+ // Initialize a message loop for this to run on.
+ MessageLoop loop;
+
+ // Check that prefs are set correctly.
+ web_resource_service_->UnpackWebStoreSignal(*(test_json.get()));
+ EXPECT_FALSE(AppsPromo::IsPromoSupportedForLocale());
+ EXPECT_TRUE(AppsPromo::IsWebStoreSupportedForLocale());
+}
+
TEST_F(PromoResourceServiceTest, IsBuildTargeted) {
// canary
const platform_util::Channel canary = platform_util::CHANNEL_CANARY;