Index: chrome/browser/web_resource/promo_resource_service_unittest.cc |
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc |
index b196b128e02c2bcff7e635acc6ba0c21fefdcd08..794051b6788dcc913fe9ff000f5ae57740a005a0 100644 |
--- a/chrome/browser/web_resource/promo_resource_service_unittest.cc |
+++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc |
@@ -15,6 +15,7 @@ |
#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/test/test_url_fetcher_factory.h" |
#include "testing/gtest/include/gtest/gtest.h" |
class PromoResourceServiceTest : public testing::Test { |
@@ -190,19 +191,24 @@ TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) { |
// Initialize a message loop for this to run on. |
MessageLoop loop; |
+ // Set the original logo URL to verify that it gets cleared. |
+ AppsPromo::SetPromoLogoOriginal(GURL("https://www.google.com/test.png")); |
+ |
// Check that prefs are set correctly. |
web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
- PrefService* prefs = profile_.GetPrefs(); |
- ASSERT_TRUE(prefs != NULL); |
- EXPECT_EQ("341252", AppsPromo::GetPromoId()); |
- EXPECT_EQ("The header!", AppsPromo::GetPromoHeaderText()); |
- 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()); |
+ AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
+ EXPECT_EQ("341252", actual_data.id); |
+ EXPECT_EQ("The header!", actual_data.header); |
+ EXPECT_EQ("The button label!", actual_data.button); |
+ EXPECT_EQ(GURL("http://link.com"), actual_data.link); |
+ EXPECT_EQ("No thanks, hide this.", actual_data.expire); |
+ EXPECT_EQ(AppsPromo::USERS_NEW, actual_data.user_group); |
+ |
+ // When we don't download a logo, we revert to the default and clear the |
+ // original pref. |
+ EXPECT_EQ(GURL("chrome://theme/IDR_WEBSTORE_ICON"), actual_data.logo); |
+ EXPECT_EQ(GURL(""), AppsPromo::GetPromoLogoOriginal()); |
} |
// Tests that the "web store active" flag is set even when the web store promo |
@@ -230,6 +236,156 @@ TEST_F(PromoResourceServiceTest, UnpackPartialWebStoreSignal) { |
EXPECT_TRUE(AppsPromo::IsWebStoreSupportedForLocale()); |
} |
+// Tests that we can successfully unpack web store signals with https |
+// logos. |
+TEST_F(PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogo) { |
+ web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV); |
+ |
+ std::string logo_url = "https://www.google.com/image/test.png"; |
+ std::string png_data = "!$#%,./nvl;iadh9oh82"; |
+ std::string png_base64 = "data:image/png;base64,ISQjJSwuL252bDtpYWRoOW9oODI="; |
+ |
+ MessageLoop message_loop; |
+ FakeURLFetcherFactory factory; |
+ factory.SetFakeResponse(logo_url, png_data, true); |
+ |
+ std::string json = |
+ "{ " |
+ " \"topic\": {" |
+ " \"answers\": [" |
+ " {" |
+ " \"answer_id\": \"340252\"," |
+ " \"name\": \"webstore_promo:15:1:" + logo_url + "\"," |
+ " \"question\": \"Header!\"," |
+ " \"inproduct_target\": \"The button label!\"," |
+ " \"inproduct\": \"http://link.com\"," |
+ " \"tooltip\": \"No thanks, hide this.\"" |
+ " }" |
+ " ]" |
+ " }" |
+ "}"; |
+ |
+ scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
+ base::JSONReader::Read(json, false))); |
+ |
+ web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
+ |
+ message_loop.RunAllPending(); |
+ |
+ AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
+ EXPECT_EQ("340252", actual_data.id); |
+ EXPECT_EQ("Header!", actual_data.header); |
+ EXPECT_EQ("The button label!", actual_data.button); |
+ EXPECT_EQ(GURL("http://link.com"), actual_data.link); |
+ EXPECT_EQ("No thanks, hide this.", actual_data.expire); |
+ EXPECT_EQ(AppsPromo::USERS_NEW, actual_data.user_group); |
+ |
+ // The logo should now be a base64 data URL. |
+ EXPECT_EQ(GURL(png_base64), actual_data.logo); |
+ |
+ // And the original pref should hold the original https URL. |
+ EXPECT_EQ(GURL(logo_url), AppsPromo::GetPromoLogoOriginal()); |
+} |
+ |
+// Tests that we revert to the default logo when the fetch fails. |
+TEST_F(PromoResourceServiceTest, UnpackWebStoreSignalHttpsLogoError) { |
+ web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV); |
+ |
+ std::string logo_url = "https://www.google.com/image/test.png"; |
+ std::string png_data = "!$#%,./nvl;iadh9oh82"; |
+ std::string png_base64 = "ISQjJSwuL252bDtpYWRoOW9oODI="; |
+ |
+ MessageLoop message_loop; |
+ FakeURLFetcherFactory factory; |
+ |
+ // Have URLFetcher return a 500 error. |
+ factory.SetFakeResponse(logo_url, png_data, false); |
+ |
+ std::string json = |
+ "{ " |
+ " \"topic\": {" |
+ " \"answers\": [" |
+ " {" |
+ " \"answer_id\": \"340252\"," |
+ " \"name\": \"webstore_promo:15:1:" + logo_url + "\"," |
+ " \"question\": \"Header!\"," |
+ " \"inproduct_target\": \"The button label!\"," |
+ " \"inproduct\": \"http://link.com\"," |
+ " \"tooltip\": \"No thanks, hide this.\"" |
+ " }" |
+ " ]" |
+ " }" |
+ "}"; |
+ |
+ scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
+ base::JSONReader::Read(json, false))); |
+ |
+ web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
+ |
+ message_loop.RunAllPending(); |
+ |
+ AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
+ EXPECT_EQ("340252", actual_data.id); |
+ EXPECT_EQ("Header!", actual_data.header); |
+ EXPECT_EQ("The button label!", actual_data.button); |
+ EXPECT_EQ(GURL("http://link.com"), actual_data.link); |
+ EXPECT_EQ("No thanks, hide this.", actual_data.expire); |
+ EXPECT_EQ(AppsPromo::USERS_NEW, actual_data.user_group); |
+ |
+ // Logos are the default values. |
+ EXPECT_EQ(GURL("chrome://theme/IDR_WEBSTORE_ICON"), actual_data.logo); |
+ EXPECT_EQ(GURL(""), AppsPromo::GetPromoLogoOriginal()); |
+} |
+ |
+// Tests that we don't download images over http. |
+TEST_F(PromoResourceServiceTest, UnpackWebStoreSignalHttpLogo) { |
+ web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV); |
+ |
+ // Use an http URL. |
+ std::string logo_url = "http://www.google.com/image/test.png"; |
+ std::string png_data = "!$#%,./nvl;iadh9oh82"; |
+ std::string png_base64 = "ISQjJSwuL252bDtpYWRoOW9oODI="; |
+ |
+ MessageLoop message_loop; |
+ FakeURLFetcherFactory factory; |
+ factory.SetFakeResponse(logo_url, png_data, true); |
+ |
+ std::string json = |
+ "{ " |
+ " \"topic\": {" |
+ " \"answers\": [" |
+ " {" |
+ " \"answer_id\": \"340252\"," |
+ " \"name\": \"webstore_promo:15:1:" + logo_url + "\"," |
+ " \"question\": \"Header!\"," |
+ " \"inproduct_target\": \"The button label!\"," |
+ " \"inproduct\": \"http://link.com\"," |
+ " \"tooltip\": \"No thanks, hide this.\"" |
+ " }" |
+ " ]" |
+ " }" |
+ "}"; |
+ |
+ scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( |
+ base::JSONReader::Read(json, false))); |
+ |
+ web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); |
+ |
+ message_loop.RunAllPending(); |
+ |
+ AppsPromo::PromoData actual_data = AppsPromo::GetPromo(); |
+ EXPECT_EQ("340252", actual_data.id); |
+ EXPECT_EQ("Header!", actual_data.header); |
+ EXPECT_EQ("The button label!", actual_data.button); |
+ EXPECT_EQ(GURL("http://link.com"), actual_data.link); |
+ EXPECT_EQ("No thanks, hide this.", actual_data.expire); |
+ EXPECT_EQ(AppsPromo::USERS_NEW, actual_data.user_group); |
+ |
+ // Logos should be the default values because http URLs are not valid. |
+ EXPECT_EQ(GURL("chrome://theme/IDR_WEBSTORE_ICON"), actual_data.logo); |
+ EXPECT_EQ(GURL(""), AppsPromo::GetPromoLogoOriginal()); |
+} |
+ |
TEST_F(PromoResourceServiceTest, IsBuildTargeted) { |
// canary |
const chrome::VersionInfo::Channel canary = |