summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-16 07:04:42 +0000
committerglen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-16 07:04:42 +0000
commit76688089aca3fd527d2d4ca3c81170f7e532c811 (patch)
tree993f88a0f62e34754abca1b2d28a82c9ed8141c9
parent449c5e76fcd8fc265b4be054d3783d63648ed6e0 (diff)
downloadchromium_src-76688089aca3fd527d2d4ca3c81170f7e532c811.zip
chromium_src-76688089aca3fd527d2d4ca3c81170f7e532c811.tar.gz
chromium_src-76688089aca3fd527d2d4ca3c81170f7e532c811.tar.bz2
Attempt to fix leaks in DOMUISources test
TBR=arv Review URL: http://codereview.chromium.org/115441 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16232 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc78
-rw-r--r--chrome/test/testing_profile.cc4
-rw-r--r--chrome/test/testing_profile.h9
3 files changed, 52 insertions, 39 deletions
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc b/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc
index 56501d2..b62231c 100644
--- a/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc
+++ b/chrome/browser/dom_ui/dom_ui_theme_source_unittest.cc
@@ -25,63 +25,65 @@ class MockThemeSource : public DOMUIThemeSource {
size_t result_data_size_;
};
-// A mock profile
-class MockProfile : public TestingProfile {
+class DOMUISourcesTest : public testing::Test {
public:
- ThemeProvider* GetThemeProvider() { return new BrowserThemeProvider(); }
-};
+ TestingProfile* profile() const { return profile_.get(); }
+ MockThemeSource* theme_source() const { return theme_source_.get(); }
+ private:
+ virtual void SetUp() {
+ profile_.reset(new TestingProfile());
+ profile_.get()->CreateThemeProvider();
+ theme_source_ = new MockThemeSource(profile_.get());
+ }
+ virtual void TearDown() {
+ theme_source_ = NULL;
+ profile_.reset(NULL);
+ }
-TEST(DOMUISources, ThemeSourceMimeTypes) {
- MockProfile* profile = new MockProfile();
- DOMUIThemeSource* theme_source = new DOMUIThemeSource(profile);
+ scoped_ptr<TestingProfile> profile_;
+ scoped_refptr<MockThemeSource> theme_source_;
+};
- EXPECT_EQ(theme_source->GetMimeType("css/newtab.css"), "text/css");
- EXPECT_EQ(theme_source->GetMimeType("css/newtab.css?foo"), "text/css");
- EXPECT_EQ(theme_source->GetMimeType("WRONGURL"), "image/png");
+TEST_F(DOMUISourcesTest, ThemeSourceMimeTypes) {
+ EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css"), "text/css");
+ EXPECT_EQ(theme_source()->GetMimeType("css/newtab.css?foo"), "text/css");
+ EXPECT_EQ(theme_source()->GetMimeType("WRONGURL"), "image/png");
}
-TEST(DOMUISources, ThemeSourceImages) {
- MockProfile* profile = new MockProfile();
- MockThemeSource* theme_source = new MockThemeSource(profile);
-
+TEST_F(DOMUISourcesTest, ThemeSourceImages) {
// Our test data. Rather than comparing the data itself, we just compare
// its size.
- ThemeProvider* tp = profile->GetThemeProvider();
- SkBitmap* image = tp->GetBitmapNamed(IDR_THEME_FRAME);
+ SkBitmap* image = ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_THEME_FRAME);
std::vector<unsigned char> png_bytes;
PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes);
- theme_source->StartDataRequest("theme_frame", 1);
- EXPECT_EQ(theme_source->result_request_id_, 1);
- EXPECT_EQ(theme_source->result_data_size_, png_bytes.size());
+ theme_source()->StartDataRequest("theme_frame", 1);
+ EXPECT_EQ(theme_source()->result_request_id_, 1);
+ EXPECT_EQ(theme_source()->result_data_size_, png_bytes.size());
- theme_source->StartDataRequest("theme_toolbar", 2);
- EXPECT_EQ(theme_source->result_request_id_, 2);
- EXPECT_NE(theme_source->result_data_size_, png_bytes.size());
+ theme_source()->StartDataRequest("theme_toolbar", 2);
+ EXPECT_EQ(theme_source()->result_request_id_, 2);
+ EXPECT_NE(theme_source()->result_data_size_, png_bytes.size());
}
-// TODO(glen): Reenable.
-/*
-TEST(DOMUISources, ThemeSourceCSS) {
- MockProfile* profile = new MockProfile();
- MockThemeSource* theme_source = new MockThemeSource(profile);
-
+TEST_F(DOMUISourcesTest, ThemeSourceCSS) {
// Generating the test data for the NTP CSS would just involve copying the
// method, or being super brittle and hard-coding the result (requiring
// an update to the unittest every time the CSS template changes), so we
// just check for a successful request and data that is non-null.
- theme_source->StartDataRequest("css/newtab.css", 1);
- EXPECT_EQ(theme_source->result_request_id_, 1);
- EXPECT_NE(theme_source->result_data_size_, 0);
+ size_t empty_size = 0;
+
+ theme_source()->StartDataRequest("css/newtab.css", 1);
+ EXPECT_EQ(theme_source()->result_request_id_, 1);
+ EXPECT_NE(theme_source()->result_data_size_, empty_size);
- theme_source->StartDataRequest("css/newtab.css?pie", 3);
- EXPECT_EQ(theme_source->result_request_id_, 3);
- EXPECT_NE(theme_source->result_data_size_, 0);
+ theme_source()->StartDataRequest("css/newtab.css?pie", 3);
+ EXPECT_EQ(theme_source()->result_request_id_, 3);
+ EXPECT_NE(theme_source()->result_data_size_, empty_size);
// Check that we send NULL back when we can't find what we're looking for.
- theme_source->StartDataRequest("css/WRONGURL", 7);
- EXPECT_EQ(theme_source->result_request_id_, 7);
- EXPECT_EQ(theme_source->result_data_size_, 0);
+ theme_source()->StartDataRequest("css/WRONGURL", 7);
+ EXPECT_EQ(theme_source()->result_request_id_, 7);
+ EXPECT_EQ(theme_source()->result_data_size_, empty_size);
}
-*/
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc
index 08fe09e9..2ea7c51 100644
--- a/chrome/test/testing_profile.cc
+++ b/chrome/test/testing_profile.cc
@@ -165,6 +165,10 @@ void TestingProfile::CreateTemplateURLModel() {
template_url_model_.reset(new TemplateURLModel(this));
}
+void TestingProfile::CreateThemeProvider() {
+ theme_provider_ = new BrowserThemeProvider();
+}
+
void TestingProfile::BlockUntilHistoryProcessesPendingRequests() {
DCHECK(history_service_.get());
DCHECK(MessageLoop::current());
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 533b12e..f83e5e4 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -11,6 +11,7 @@
#include "base/file_util.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/browser_prefs.h"
+#include "chrome/browser/browser_theme_provider.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url_model.h"
@@ -52,6 +53,9 @@ class TestingProfile : public Profile {
// Creates a TemplateURLModel. If not invoked the TemplateURLModel is NULL.
void CreateTemplateURLModel();
+ // Creates a ThemeProvider. If not invoked the ThemeProvider is NULL.
+ void CreateThemeProvider();
+
virtual FilePath GetPath() {
return path_;
}
@@ -123,7 +127,7 @@ class TestingProfile : public Profile {
virtual void SetTheme(Extension* extension) { }
virtual void ClearTheme() { }
virtual ThemeProvider* GetThemeProvider() {
- return NULL;
+ return theme_provider_.get();
}
virtual URLRequestContext* GetRequestContext() {
return NULL;
@@ -228,6 +232,9 @@ class TestingProfile : public Profile {
// The SessionService. Defaults to NULL, but can be set using the setter.
scoped_refptr<SessionService> session_service_;
+ // The theme provider. Only created if CreateThemeProvider is invoked.
+ scoped_refptr<BrowserThemeProvider> theme_provider_;
+
// Do we have a history service? This defaults to the value of
// history_service, but can be explicitly set.
bool has_history_service_;