| 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 e84e43bac7e0acab3133565527031ab6b706330e..6e1f714fb5c5f1185cd6241ff59ae13d09719229 100644
|
| --- a/chrome/browser/web_resource/promo_resource_service_unittest.cc
|
| +++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc
|
| @@ -6,30 +6,29 @@
|
| #include "base/time.h"
|
| #include "base/utf_string_conversions.h"
|
| #include "base/values.h"
|
| +#include "chrome/browser/extensions/apps_promo.h"
|
| +#include "chrome/browser/prefs/browser_prefs.h"
|
| #include "chrome/browser/prefs/pref_service.h"
|
| #include "chrome/browser/web_resource/promo_resource_service.h"
|
| #include "chrome/common/pref_names.h"
|
| +#include "chrome/test/testing_browser_process.h"
|
| +#include "chrome/test/testing_pref_service.h"
|
| #include "chrome/test/testing_profile.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| typedef testing::Test PromoResourceServiceTest;
|
|
|
| -namespace {
|
| -
|
| -// From promo_resource_service.cc
|
| -enum BuildType {
|
| - DEV_BUILD = 1,
|
| - BETA_BUILD = 1 << 1,
|
| - STABLE_BUILD = 1 << 2,
|
| -};
|
| -
|
| -} // namespace
|
| -
|
| // Verifies that custom dates read from a web resource server are written to
|
| // the preferences file.
|
| TEST_F(PromoResourceServiceTest, UnpackLogoSignal) {
|
| // Set up a testing profile and create a promo resource service.
|
| TestingProfile profile;
|
| + TestingPrefService local_state;
|
| + TestingBrowserProcess* testing_browser_process =
|
| + static_cast<TestingBrowserProcess*>(g_browser_process);
|
| + testing_browser_process->SetPrefService(&local_state);
|
| + browser::RegisterLocalState(&local_state);
|
| +
|
| scoped_refptr<PromoResourceService> web_resource_service(
|
| new PromoResourceService(&profile));
|
|
|
| @@ -112,6 +111,12 @@ TEST_F(PromoResourceServiceTest, UnpackLogoSignal) {
|
| TEST_F(PromoResourceServiceTest, UnpackPromoSignal) {
|
| // Set up a testing profile and create a promo resource service.
|
| TestingProfile profile;
|
| + TestingPrefService local_state;
|
| + TestingBrowserProcess* testing_browser_process =
|
| + static_cast<TestingBrowserProcess*>(g_browser_process);
|
| + testing_browser_process->SetPrefService(&local_state);
|
| + browser::RegisterLocalState(&local_state);
|
| +
|
| scoped_refptr<PromoResourceService> web_resource_service(
|
| new PromoResourceService(&profile));
|
|
|
| @@ -152,9 +157,11 @@ TEST_F(PromoResourceServiceTest, UnpackPromoSignal) {
|
| EXPECT_LT(promo_group, 16);
|
|
|
| int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild);
|
| - EXPECT_EQ(promo_build_type & DEV_BUILD, DEV_BUILD);
|
| - EXPECT_EQ(promo_build_type & BETA_BUILD, BETA_BUILD);
|
| - EXPECT_EQ(promo_build_type & STABLE_BUILD, 0);
|
| + EXPECT_EQ(promo_build_type & PromoResourceService::DEV_BUILD,
|
| + PromoResourceService::DEV_BUILD);
|
| + EXPECT_EQ(promo_build_type & PromoResourceService::BETA_BUILD,
|
| + PromoResourceService::BETA_BUILD);
|
| + EXPECT_EQ(promo_build_type & PromoResourceService::STABLE_BUILD, 0);
|
|
|
| int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice);
|
| EXPECT_EQ(promo_time_slice, 2);
|
| @@ -170,4 +177,86 @@ TEST_F(PromoResourceServiceTest, UnpackPromoSignal) {
|
| EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT.
|
| }
|
|
|
| +TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) {
|
| + // Set up a testing profile and create a promo resource service.
|
| + TestingProfile profile;
|
| + TestingPrefService local_state;
|
| + TestingBrowserProcess* testing_browser_process =
|
| + static_cast<TestingBrowserProcess*>(g_browser_process);
|
| + testing_browser_process->SetPrefService(&local_state);
|
| +
|
| + browser::RegisterLocalState(&local_state);
|
| +
|
| + scoped_refptr<PromoResourceService> web_resource_service(
|
| + new PromoResourceService(&profile));
|
| +
|
| + web_resource_service->set_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\","
|
| + " \"question\": \"The 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)));
|
| +
|
| + // Initialize a message loop for this to run on.
|
| + MessageLoop loop;
|
| +
|
| + // 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());
|
| +}
|
| +
|
| +TEST_F(PromoResourceServiceTest, IsBuildTargeted) {
|
| + // canary
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("canary", 1));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("canary", 3));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("canary", 7));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("canary", 15));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("canary", 8));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("canary", 11));
|
| +
|
| + // dev
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 1));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 3));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 7));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 15));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("dev", 8));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 11));
|
|
|
| + // beta
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("beta", 1));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 3));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 7));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 15));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("beta", 8));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 11));
|
| +
|
| + // stable
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 1));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 3));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("", 7));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("", 15));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 8));
|
| + EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 11));
|
| + EXPECT_TRUE(PromoResourceService::IsBuildTargeted("", 12));
|
| +}
|
|
|