diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 16:08:52 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-04 16:08:52 +0000 |
commit | 81bb1092f354f3cb3c597ab3c9ed568905078e49 (patch) | |
tree | 7e8c5f324f49fc7302e6f1ee742c39169340e03f /chrome/browser/web_resource/promo_resource_service_unittest.cc | |
parent | 96dcc176c46003af0176f0f4772affc741aa772a (diff) | |
download | chromium_src-81bb1092f354f3cb3c597ab3c9ed568905078e49.zip chromium_src-81bb1092f354f3cb3c597ab3c9ed568905078e49.tar.gz chromium_src-81bb1092f354f3cb3c597ab3c9ed568905078e49.tar.bz2 |
Detach the PromoResourceService and WebResourceService from the Profile; have them store web resource data in local state instead.
We don't need multiple services for different Profiles; instead, there is a single service that captures data in local_state. The only preference stored in the Profile about the promo will be a bool indicating whether it's been closed or not, which will now be set outside the service.
Reviewers:
arv for general changes to PromoResourceService, & unittest.
erg for pulling the service out of the Profile and serving it up as a Singleton.
zmo for the changes I made to gpu_data_manager.
jstritar FYI, for changes to the PromoResourceService.
BUG=77155
TEST=promo resource service unittests.
Review URL: http://codereview.chromium.org/6736028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80318 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource/promo_resource_service_unittest.cc')
-rw-r--r-- | chrome/browser/web_resource/promo_resource_service_unittest.cc | 112 |
1 files changed, 73 insertions, 39 deletions
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc index e84e43b..b80cea4 100644 --- a/chrome/browser/web_resource/promo_resource_service_unittest.cc +++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc @@ -6,13 +6,66 @@ #include "base/time.h" #include "base/utf_string_conversions.h" #include "base/values.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/browser/web_resource/promo_resource_service_factory.h" #include "chrome/common/pref_names.h" -#include "chrome/test/testing_profile.h" +#include "chrome/test/testing_browser_process.h" +#include "chrome/test/testing_pref_service.h" #include "testing/gtest/include/gtest/gtest.h" -typedef testing::Test PromoResourceServiceTest; +class PromoResourceServiceTest : public testing::Test { + public: + TestingPrefService* local_state() { return &local_state_; } + PromoResourceServiceFactory* promo_resource_service_factory() { + return promo_resource_service_factory_; + } + PromoResourceService* web_resource_service() { + return web_resource_service_; + } + + int promo_group() { + return web_resource_service_->promo_group_; + } + + protected: + PromoResourceServiceTest() {} + virtual ~PromoResourceServiceTest() {} + + // testing::Test + virtual void SetUp(); + virtual void TearDown(); + + private: + // weak Singleton + PromoResourceServiceFactory* promo_resource_service_factory_; + scoped_refptr<PromoResourceService> web_resource_service_; + TestingPrefService local_state_; +}; + +void PromoResourceServiceTest::SetUp() { + // Set up the local state preferences. + browser::RegisterLocalState(&local_state_); + TestingBrowserProcess* testing_browser_process = + static_cast<TestingBrowserProcess*>(g_browser_process); + testing_browser_process->SetPrefService(&local_state_); + + promo_resource_service_factory_ = + PromoResourceServiceFactory::GetInstance(); + web_resource_service_ = + promo_resource_service_factory_->promo_resource_service(); + // To get around the weirdness of using a Singleton across multiple tests, we + // may need to initialize the WebResourceService local state here. + if (!local_state()->FindPreference(prefs::kNTPPromoBuild)) + web_resource_service_->Init(); +} + +void PromoResourceServiceTest::TearDown() { + TestingBrowserProcess* testing_browser_process = + static_cast<TestingBrowserProcess*>(g_browser_process); + testing_browser_process->SetPrefService(NULL); +} namespace { @@ -28,11 +81,6 @@ enum BuildType { // 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; - scoped_refptr<PromoResourceService> web_resource_service( - new PromoResourceService(&profile)); - // Set up start and end dates in a Dictionary as if parsed from the service. std::string json = "{ " " \"topic\": {" @@ -52,15 +100,13 @@ TEST_F(PromoResourceServiceTest, UnpackLogoSignal) { base::JSONReader::Read(json, false))); // Check that prefs are set correctly. - web_resource_service->UnpackLogoSignal(*(test_json.get())); - PrefService* prefs = profile.GetPrefs(); - ASSERT_TRUE(prefs != NULL); + web_resource_service()->UnpackLogoSignal(*(test_json.get())); double logo_start = - prefs->GetDouble(prefs::kNTPCustomLogoStart); + local_state()->GetDouble(prefs::kNTPCustomLogoStart); EXPECT_EQ(logo_start, 1264899600); // unix epoch for Jan 31 2010 0100 GMT. double logo_end = - prefs->GetDouble(prefs::kNTPCustomLogoEnd); + local_state()->GetDouble(prefs::kNTPCustomLogoEnd); EXPECT_EQ(logo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. // Change the start only and recheck. @@ -83,9 +129,9 @@ TEST_F(PromoResourceServiceTest, UnpackLogoSignal) { base::JSONReader::Read(json, false))); // Check that prefs are set correctly. - web_resource_service->UnpackLogoSignal(*(test_json.get())); + web_resource_service()->UnpackLogoSignal(*(test_json.get())); - logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); + logo_start = local_state()->GetDouble(prefs::kNTPCustomLogoStart); EXPECT_EQ(logo_start, 1267365600); // date changes to Feb 28 2010 1400 GMT. // If no date is included in the prefs, reset custom logo dates to 0. @@ -102,19 +148,14 @@ TEST_F(PromoResourceServiceTest, UnpackLogoSignal) { base::JSONReader::Read(json, false))); // Check that prefs are set correctly. - web_resource_service->UnpackLogoSignal(*(test_json.get())); - logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); + web_resource_service()->UnpackLogoSignal(*(test_json.get())); + logo_start = local_state()->GetDouble(prefs::kNTPCustomLogoStart); EXPECT_EQ(logo_start, 0); // date value reset to 0; - logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); + logo_end = local_state()->GetDouble(prefs::kNTPCustomLogoEnd); EXPECT_EQ(logo_end, 0); // date value reset to 0; } TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { - // Set up a testing profile and create a promo resource service. - TestingProfile profile; - scoped_refptr<PromoResourceService> web_resource_service( - new PromoResourceService(&profile)); - // Set up start and end dates and promo line in a Dictionary as if parsed // from the service. std::string json = "{ " @@ -140,33 +181,26 @@ TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { MessageLoop loop; // Check that prefs are set correctly. - web_resource_service->UnpackPromoSignal(*(test_json.get())); - PrefService* prefs = profile.GetPrefs(); - ASSERT_TRUE(prefs != NULL); + web_resource_service()->UnpackPromoSignal(*(test_json.get())); - std::string promo_line = prefs->GetString(prefs::kNTPPromoLine); + std::string promo_line = local_state()->GetString(prefs::kNTPPromoLine); EXPECT_EQ(promo_line, "Eat more pie!"); - int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup); - EXPECT_GE(promo_group, 0); - EXPECT_LT(promo_group, 16); - - int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild); + int promo_build_type = local_state()->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); - int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice); - EXPECT_EQ(promo_time_slice, 2); - double promo_start = - prefs->GetDouble(prefs::kNTPPromoStart); - int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT. - promo_group * 2 * 60 * 60; - EXPECT_EQ(promo_start, actual_start); + local_state()->GetDouble(prefs::kNTPPromoStart); // In seconds. + int timeslice = 2; // From the second part of the "question" field. + // Start date for group 0, unix epoch for Jan 31 2010 0100 GMT. + int64 start_date = 1264899600; + // Add promo_group * timeslice converted to seconds for actual start. + EXPECT_EQ(promo_start, start_date + promo_group() * timeslice * 60 * 60); double promo_end = - prefs->GetDouble(prefs::kNTPPromoEnd); + local_state()->GetDouble(prefs::kNTPPromoEnd); EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. } |