summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjustincohen <justincohen@chromium.org>2015-04-03 09:36:03 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-03 16:36:29 +0000
commite30018a1830440f1dca72e11605a69592c472883 (patch)
treef043febc91848af5a1f324e9bf0ea61dc09b182c
parent8828ed3647a456dd46827282c31c451d194c7ca0 (diff)
downloadchromium_src-e30018a1830440f1dca72e11605a69592c472883.zip
chromium_src-e30018a1830440f1dca72e11605a69592c472883.tar.gz
chromium_src-e30018a1830440f1dca72e11605a69592c472883.tar.bz2
Add animated url to LogoTracker.
BUG=414528 Review URL: https://codereview.chromium.org/1054123002 Cr-Commit-Position: refs/heads/master@{#323754}
-rw-r--r--components/search_provider_logos/google_logo_api.cc5
-rw-r--r--components/search_provider_logos/logo_cache.cc3
-rw-r--r--components/search_provider_logos/logo_cache_unittest.cc2
-rw-r--r--components/search_provider_logos/logo_common.h4
-rw-r--r--components/search_provider_logos/logo_tracker_unittest.cc13
5 files changed, 27 insertions, 0 deletions
diff --git a/components/search_provider_logos/google_logo_api.cc b/components/search_provider_logos/google_logo_api.cc
index 1c81bfe..90067c2 100644
--- a/components/search_provider_logos/google_logo_api.cc
+++ b/components/search_provider_logos/google_logo_api.cc
@@ -45,6 +45,7 @@ scoped_ptr<EncodedLogo> GoogleParseLogoResponse(
// "mime_type": "image/png",
// "fingerprint": "db063e32",
// "target": "http://www.google.com.au/search?q=Wilbur+Christiansen",
+ // "url": "http://www.google.com/logos/doodle.png",
// "alt": "Wilbur Christiansen's Birthday"
// "time_to_live": 1389304799
// }}}
@@ -82,6 +83,10 @@ scoped_ptr<EncodedLogo> GoogleParseLogoResponse(
logo->encoded_image = encoded_image_string;
if (!logo_dict->GetString("mime_type", &logo->metadata.mime_type))
return scoped_ptr<EncodedLogo>();
+
+ // Existance of url indicates |data| is a call to action image for an
+ // animated doodle. |url| points to that animated doodle.
+ logo_dict->GetString("url", &logo->metadata.animated_url);
}
// Don't check return values since these fields are optional.
diff --git a/components/search_provider_logos/logo_cache.cc b/components/search_provider_logos/logo_cache.cc
index bb3e8dd..bfa419e 100644
--- a/components/search_provider_logos/logo_cache.cc
+++ b/components/search_provider_logos/logo_cache.cc
@@ -21,6 +21,7 @@ const char kOnClickURLKey[] = "on_click_url";
const char kAltTextKey[] = "alt_text";
const char kMimeTypeKey[] = "mime_type";
const char kNumBytesKey[] = "num_bytes";
+const char kAnimatedUrlKey[] = "animated_url";
bool GetTimeValue(const base::DictionaryValue& dict,
const std::string& key,
@@ -124,6 +125,7 @@ scoped_ptr<LogoMetadata> LogoCache::LogoMetadataFromString(
!dict->GetString(kFingerprintKey, &metadata->fingerprint) ||
!dict->GetString(kOnClickURLKey, &metadata->on_click_url) ||
!dict->GetString(kAltTextKey, &metadata->alt_text) ||
+ !dict->GetString(kAnimatedUrlKey, &metadata->animated_url) ||
!dict->GetString(kMimeTypeKey, &metadata->mime_type) ||
!dict->GetBoolean(kCanShowAfterExpirationKey,
&metadata->can_show_after_expiration) ||
@@ -144,6 +146,7 @@ void LogoCache::LogoMetadataToString(const LogoMetadata& metadata,
dict.SetString(kFingerprintKey, metadata.fingerprint);
dict.SetString(kOnClickURLKey, metadata.on_click_url);
dict.SetString(kAltTextKey, metadata.alt_text);
+ dict.SetString(kAnimatedUrlKey, metadata.animated_url);
dict.SetString(kMimeTypeKey, metadata.mime_type);
dict.SetBoolean(kCanShowAfterExpirationKey,
metadata.can_show_after_expiration);
diff --git a/components/search_provider_logos/logo_cache_unittest.cc b/components/search_provider_logos/logo_cache_unittest.cc
index a483c98..7ed3447 100644
--- a/components/search_provider_logos/logo_cache_unittest.cc
+++ b/components/search_provider_logos/logo_cache_unittest.cc
@@ -24,6 +24,7 @@ LogoMetadata GetExampleMetadata() {
&metadata.expiration_time));
metadata.can_show_after_expiration = true;
metadata.on_click_url = "https://www.google.com/search?q=chicken";
+ metadata.animated_url = "http://www.google.com/logos/doodle.png";
metadata.alt_text = "A logo about chickens";
metadata.mime_type = "image/jpeg";
return metadata;
@@ -73,6 +74,7 @@ void ExpectMetadataEqual(const LogoMetadata& expected_metadata,
actual_metadata.can_show_after_expiration);
EXPECT_EQ(expected_metadata.expiration_time, actual_metadata.expiration_time);
EXPECT_EQ(expected_metadata.on_click_url, actual_metadata.on_click_url);
+ EXPECT_EQ(expected_metadata.animated_url, actual_metadata.animated_url);
EXPECT_EQ(expected_metadata.alt_text, actual_metadata.alt_text);
EXPECT_EQ(expected_metadata.mime_type, actual_metadata.mime_type);
}
diff --git a/components/search_provider_logos/logo_common.h b/components/search_provider_logos/logo_common.h
index 207026b..86b5700 100644
--- a/components/search_provider_logos/logo_common.h
+++ b/components/search_provider_logos/logo_common.h
@@ -29,6 +29,10 @@ struct LogoMetadata {
std::string alt_text;
// The mime type of the logo image.
std::string mime_type;
+ // The URL for an animated image to display when the call to action logo is
+ // clicked. If |animated_url| is not empty, |encoded_image| refers to a call
+ // to action image.
+ std::string animated_url;
// For use by LogoTracker ---------------------------------------------------
diff --git a/components/search_provider_logos/logo_tracker_unittest.cc b/components/search_provider_logos/logo_tracker_unittest.cc
index c5c1f35..13b105e 100644
--- a/components/search_provider_logos/logo_tracker_unittest.cc
+++ b/components/search_provider_logos/logo_tracker_unittest.cc
@@ -97,6 +97,7 @@ Logo GetSampleLogo(const GURL& logo_url, base::Time response_time) {
logo.metadata.source_url = logo_url.spec();
logo.metadata.on_click_url = "http://www.google.com/search?q=potato";
logo.metadata.alt_text = "A logo about potatoes";
+ logo.metadata.animated_url = "http://www.google.com/logos/doodle.png";
logo.metadata.mime_type = "image/png";
return logo;
}
@@ -118,6 +119,7 @@ std::string MakeServerResponse(
const SkBitmap& image,
const std::string& on_click_url,
const std::string& alt_text,
+ const std::string& animated_url,
const std::string& mime_type,
const std::string& fingerprint,
base::TimeDelta time_to_live) {
@@ -128,6 +130,9 @@ std::string MakeServerResponse(
dict.SetString("update.logo.target", on_click_url);
dict.SetString("update.logo.alt", alt_text);
+ if (!animated_url.empty()) {
+ dict.SetString("update.logo.url", animated_url);
+ }
dict.SetString("update.logo.mime_type", mime_type);
dict.SetString("update.logo.fingerprint", fingerprint);
if (time_to_live.ToInternalValue() != 0)
@@ -143,6 +148,7 @@ std::string MakeServerResponse(const Logo& logo, base::TimeDelta time_to_live) {
return MakeServerResponse(logo.image,
logo.metadata.on_click_url,
logo.metadata.alt_text,
+ logo.metadata.animated_url,
logo.metadata.mime_type,
logo.metadata.fingerprint,
time_to_live);
@@ -160,6 +166,12 @@ void ExpectLogosEqual(const Logo* expected_logo,
actual_logo->metadata.on_click_url);
EXPECT_EQ(expected_logo->metadata.source_url,
actual_logo->metadata.source_url);
+ EXPECT_EQ(expected_logo->metadata.animated_url,
+ actual_logo->metadata.animated_url);
+ EXPECT_EQ(expected_logo->metadata.alt_text,
+ actual_logo->metadata.alt_text);
+ EXPECT_EQ(expected_logo->metadata.mime_type,
+ actual_logo->metadata.mime_type);
EXPECT_EQ(expected_logo->metadata.fingerprint,
actual_logo->metadata.fingerprint);
EXPECT_EQ(expected_logo->metadata.can_show_after_expiration,
@@ -424,6 +436,7 @@ TEST_F(LogoTrackerTest, AcceptMinimalLogoResponse) {
logo.image = MakeBitmap(1, 2);
logo.metadata.source_url = logo_url_.spec();
logo.metadata.can_show_after_expiration = true;
+ logo.metadata.mime_type = "image/png";
std::string response = ")]}' {\"update\":{\"logo\":{\"data\":\"" +
EncodeBitmapAsPNGBase64(logo.image) +