diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 13:21:08 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-07 13:21:08 +0000 |
commit | 415a01c0101f4323f2288f20a842dac54d1ac242 (patch) | |
tree | 915adcee4585977d3463cd3e9de6ffaadb51225f /chrome/test | |
parent | b28dafd1176f7afa9c99d939112f2069d93e7c1f (diff) | |
download | chromium_src-415a01c0101f4323f2288f20a842dac54d1ac242.zip chromium_src-415a01c0101f4323f2288f20a842dac54d1ac242.tar.gz chromium_src-415a01c0101f4323f2288f20a842dac54d1ac242.tar.bz2 |
Move code duplicated in two tests up into the TestingProfile.
Move TestURLRequestContextGetter and friends from CookieTreeModelTest and
CookiesWindowControllerTest into TestingProfile. In the TestingProfile, return
a valid CookieMonster and URLRequstContextGetter.
BUG=None
TEST=Covered by unit tests
Review URL: http://codereview.chromium.org/525072
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35703 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/testing_profile.cc | 37 | ||||
-rw-r--r-- | chrome/test/testing_profile.h | 18 |
2 files changed, 52 insertions, 3 deletions
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index 39e847a..c102f82 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -9,8 +9,10 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/dom_ui/ntp_resource_cache.h" #include "chrome/browser/history/history_backend.h" +#include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/common/chrome_constants.h" +#include "net/url_request/url_request_context.h" #include "webkit/database/database_tracker.h" #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) @@ -76,6 +78,33 @@ class BookmarkLoadObserver : public BookmarkModelObserver { DISALLOW_COPY_AND_ASSIGN(BookmarkLoadObserver); }; +// This context is used to assist testing the CookieMonster by providing a +// valid CookieStore. This can probably be expanded to test other aspects of +// the context as well. +class TestURLRequestContext : public URLRequestContext { + public: + TestURLRequestContext() { + cookie_store_ = new net::CookieMonster(); + } +}; + +// Used to return a dummy context (normally the context is on the IO thread). +// The one here can be run on the main test thread. Note that this can lead to +// a leak if your test does not have a ChromeThread::IO in it because +// URLRequestContextGetter is defined as a ReferenceCounted object with a +// DeleteOnIOThread trait. +class TestURLRequestContextGetter : public URLRequestContextGetter { + public: + virtual URLRequestContext* GetURLRequestContext() { + if (!context_) + context_ = new TestURLRequestContext(); + return context_.get(); + } + + private: + scoped_refptr<URLRequestContext> context_; +}; + } // namespace TestingProfile::TestingProfile() @@ -202,6 +231,12 @@ void TestingProfile::InitThemes() { } } +URLRequestContextGetter* TestingProfile::GetRequestContext() { + if (!request_context_) + request_context_ = new TestURLRequestContextGetter(); + return request_context_.get(); +} + NTPResourceCache* TestingProfile::GetNTPResourceCache() { if (!ntp_resource_cache_.get()) ntp_resource_cache_.reset(new NTPResourceCache(this)); diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index f59a18b..28d4e58 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2009-2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -13,10 +13,12 @@ #include "chrome/browser/browser_theme_provider.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history.h" +#include "chrome/browser/net/url_request_context_getter.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/sessions/session_service.h" #include "chrome/common/pref_service.h" +#include "net/base/cookie_monster.h" class TestingProfile : public Profile { public: @@ -100,6 +102,9 @@ class TestingProfile : public Profile { void set_has_history_service(bool has_history_service) { has_history_service_ = has_history_service; } + net::CookieMonster* GetCookieMonster() { + return GetRequestContext()->GetCookieStore()->GetCookieMonster(); + } virtual SearchVersusNavigateClassifier* GetSearchVersusNavigateClassifier() { return NULL; } @@ -139,11 +144,16 @@ class TestingProfile : public Profile { InitThemes(); return theme_provider_.get(); } - virtual URLRequestContextGetter* GetRequestContext() { return NULL; } + + // Returns a testing ContextGetter. This getter is currently only capable of + // returning a Context that helps test the CookieMonster. See implementation + // comments for more details. + virtual URLRequestContextGetter* GetRequestContext(); virtual URLRequestContextGetter* GetRequestContextForMedia() { return NULL; } virtual URLRequestContextGetter* GetRequestContextForExtensions() { return NULL; } + virtual net::SSLConfigService* GetSSLConfigService() { return NULL; } virtual BlacklistManager* GetBlacklistManager() { return NULL; } virtual HostZoomMap* GetHostZoomMap() { return NULL; } @@ -230,6 +240,10 @@ class TestingProfile : public Profile { scoped_ptr<BrowserThemeProvider> theme_provider_; bool created_theme_provider_; + // Internally, this is a TestURLRequestContextGetter that creates a dummy + // request context. Currently, only the CookieMonster is hooked up. + scoped_refptr<URLRequestContextGetter> request_context_; + // Do we have a history service? This defaults to the value of // history_service, but can be explicitly set. bool has_history_service_; |