diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 05:36:04 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 05:36:04 +0000 |
commit | 812b3a3ee935e0398382eb5e112dd93f6df9510c (patch) | |
tree | 3d4df126a2c5d828b834bb5f78c5998f621a0148 /chrome/test/testing_profile.cc | |
parent | b9289a192e590565ae012fd6f613fd1c1a7b244a (diff) | |
download | chromium_src-812b3a3ee935e0398382eb5e112dd93f6df9510c.zip chromium_src-812b3a3ee935e0398382eb5e112dd93f6df9510c.tar.gz chromium_src-812b3a3ee935e0398382eb5e112dd93f6df9510c.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, if CreateRequestContext() is
called.
Original CL: http://codereview.chromium.org/525072/show
BUG=None
TEST=Covered by unit tests
Review URL: http://codereview.chromium.org/525106
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35776 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/testing_profile.cc')
-rw-r--r-- | chrome/test/testing_profile.cc | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index 39e847a..e5d6740 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,15 @@ void TestingProfile::InitThemes() { } } +URLRequestContextGetter* TestingProfile::GetRequestContext() { + return request_context_.get(); +} + +void TestingProfile::CreateRequestContext() { + if (!request_context_) + request_context_ = new TestURLRequestContextGetter(); +} + NTPResourceCache* TestingProfile::GetNTPResourceCache() { if (!ntp_resource_cache_.get()) ntp_resource_cache_.reset(new NTPResourceCache(this)); |