diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-21 12:47:38 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-21 12:47:38 +0000 |
commit | 7deb6a02fdebb5d7228fbde9818db456bac9e308 (patch) | |
tree | 75c8085c12cb7cfd6eac7433615f4904ac6eca89 /chrome/browser/web_resource | |
parent | 8aee776c2a59a338499ec91deff736c822067216 (diff) | |
download | chromium_src-7deb6a02fdebb5d7228fbde9818db456bac9e308.zip chromium_src-7deb6a02fdebb5d7228fbde9818db456bac9e308.tar.gz chromium_src-7deb6a02fdebb5d7228fbde9818db456bac9e308.tar.bz2 |
Add a ScopedTestingLocalState for unit tests which need Local State.
BUG=79691
TEST=unit tests work
Review URL: http://codereview.chromium.org/6873037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82478 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/web_resource')
-rw-r--r-- | chrome/browser/web_resource/promo_resource_service_unittest.cc | 73 |
1 files changed, 22 insertions, 51 deletions
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc index 38f3a31..a9c0e22 100644 --- a/chrome/browser/web_resource/promo_resource_service_unittest.cc +++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc @@ -11,27 +11,27 @@ #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_browser_process_test.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; +class PromoResourceServiceTest : public TestingBrowserProcessTest { + public: + PromoResourceServiceTest() + : local_state_(testing_browser_process_.get()), + web_resource_service_(new PromoResourceService(&profile_)) { + } + + protected: + TestingProfile profile_; + ScopedTestingLocalState local_state_; + scoped_refptr<PromoResourceService> web_resource_service_; +}; // 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)); - // Set up start and end dates in a Dictionary as if parsed from the service. std::string json = "{ " " \"topic\": {" @@ -51,8 +51,8 @@ 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(); + web_resource_service_->UnpackLogoSignal(*(test_json.get())); + PrefService* prefs = profile_.GetPrefs(); ASSERT_TRUE(prefs != NULL); double logo_start = @@ -82,7 +82,7 @@ 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); EXPECT_EQ(logo_start, 1267365600); // date changes to Feb 28 2010 1400 GMT. @@ -101,27 +101,14 @@ 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); EXPECT_EQ(logo_start, 0); // date value reset to 0; logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); EXPECT_EQ(logo_end, 0); // date value reset to 0; - - testing_browser_process->SetPrefService(NULL); } 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)); - // Set up start and end dates and promo line in a Dictionary as if parsed // from the service. std::string json = "{ " @@ -147,8 +134,8 @@ TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { MessageLoop loop; // Check that prefs are set correctly. - web_resource_service->UnpackPromoSignal(*(test_json.get())); - PrefService* prefs = profile.GetPrefs(); + web_resource_service_->UnpackPromoSignal(*(test_json.get())); + PrefService* prefs = profile_.GetPrefs(); ASSERT_TRUE(prefs != NULL); std::string promo_line = prefs->GetString(prefs::kNTPPromoLine); @@ -177,24 +164,10 @@ TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { double promo_end = prefs->GetDouble(prefs::kNTPPromoEnd); EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. - - testing_browser_process->SetPrefService(NULL); } 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"); + web_resource_service_->set_channel("dev"); // Set up start and end dates and promo line in a Dictionary as if parsed // from the service. @@ -219,8 +192,8 @@ TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) { MessageLoop loop; // Check that prefs are set correctly. - web_resource_service->UnpackWebStoreSignal(*(test_json.get())); - PrefService* prefs = profile.GetPrefs(); + web_resource_service_->UnpackWebStoreSignal(*(test_json.get())); + PrefService* prefs = profile_.GetPrefs(); ASSERT_TRUE(prefs != NULL); EXPECT_EQ("341252", AppsPromo::GetPromoId()); @@ -228,8 +201,6 @@ 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()); - - testing_browser_process->SetPrefService(NULL); } TEST_F(PromoResourceServiceTest, IsBuildTargeted) { |