Skip to content

Commit

Permalink
More out-of-lining of test code, along with a bunch of GMOCK objects.
Browse files Browse the repository at this point in the history
Most notably, rename various mock_objects.h files in remoting/ because after deinlining, there were compile failures. This fixes Windows compiling because you can't have two implementation files with the same name in a project, even if they are in different directories. (The output from one compile will clobber the others!)

BUG=none
TEST=compiles

Review URL: http://codereview.chromium.org/6250198

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74059 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
erg@google.com committed Feb 8, 2011
1 parent cfbf0a1 commit 0a071a3
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 216 deletions.
4 changes: 4 additions & 0 deletions chrome/browser/extensions/extension_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,10 @@ void ExtensionService::UpdateExtensionBlacklist(
}
}

Profile* ExtensionService::profile() {
return profile_;
}

void ExtensionService::DestroyingProfile() {
if (updater_.get()) {
updater_->Stop();
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/extensions/extension_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class ExtensionService
return show_extensions_prompts_;
}

Profile* profile() { return profile_; }
virtual Profile* profile();

// Profile calls this when it is being destroyed so that we know not to call
// it.
Expand Down
10 changes: 10 additions & 0 deletions chrome/browser/profiles/profile_io_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ ProfileIOData::Handle::GetExtensionsRequestContextGetter() const {
return extensions_request_context_getter_;
}


ProfileIOData::LazyParams::LazyParams()
: cache_max_size(0),
media_cache_max_size(0),
io_thread(NULL),
profile(NULL) {
}

ProfileIOData::LazyParams::~LazyParams() {}

class ProfileIOData::RequestContext : public ChromeURLRequestContext {
public:
RequestContext();
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/profiles/profile_io_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class ProfileIOData : public base::RefCountedThreadSafe<ProfileIOData> {
// TODO(willchan): Move this to the private section when
// ChromeURLRequestContextFactory subclasses don't need it anymore.
struct LazyParams {
LazyParams();
~LazyParams();

// All of these parameters are intended to be read on the IO thread.
FilePath cookie_path;
FilePath cache_path;
Expand Down
5 changes: 3 additions & 2 deletions chrome/chrome_tests.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@
'test/test_location_bar.h',
'test/test_switches.cc',
'test/test_switches.h',
'test/test_url_request_context_getter.cc',
'test/test_url_request_context_getter.h',
'test/testing_browser_process.cc',
'test/testing_browser_process.h',
'test/testing_device_token_fetcher.cc',
'test/testing_device_token_fetcher.h',
'test/testing_pref_service.cc',
Expand Down Expand Up @@ -193,7 +196,6 @@
'test/automated_ui_tests/automated_ui_test_base.h',
'test/automation/proxy_launcher.cc',
'test/automation/proxy_launcher.h',
'test/testing_browser_process.h',
'test/ui/javascript_test_util.cc',
'test/ui/npapi_test_helper.cc',
'test/ui/npapi_test_helper.h',
Expand Down Expand Up @@ -2939,7 +2941,6 @@
'test/live_sync/two_client_live_themes_sync_test.cc',
'test/test_notification_tracker.cc',
'test/test_notification_tracker.h',
'test/testing_browser_process.h',
'test/ui_test_utils_linux.cc',
'test/ui_test_utils_mac.mm',
'test/ui_test_utils_win.cc',
Expand Down
8 changes: 8 additions & 0 deletions chrome/common/net/test_url_fetcher_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ TestURLFetcher::TestURLFetcher(int id,
original_url_(url) {
}

TestURLFetcherFactory::TestURLFetcherFactory() {}

TestURLFetcherFactory::~TestURLFetcherFactory() {}

URLFetcher* TestURLFetcherFactory::CreateURLFetcher(
int id,
const GURL& url,
Expand Down Expand Up @@ -87,6 +91,10 @@ class FakeURLFetcher : public URLFetcher {
DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher);
};

FakeURLFetcherFactory::FakeURLFetcherFactory() {}

FakeURLFetcherFactory::~FakeURLFetcherFactory() {}

URLFetcher* FakeURLFetcherFactory::CreateURLFetcher(
int id,
const GURL& url,
Expand Down
6 changes: 4 additions & 2 deletions chrome/common/net/test_url_fetcher_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class TestURLFetcher : public URLFetcher {
// are registered in a map by the id passed to the create method.
class TestURLFetcherFactory : public URLFetcher::Factory {
public:
TestURLFetcherFactory() {}
TestURLFetcherFactory();
virtual ~TestURLFetcherFactory();

virtual URLFetcher* CreateURLFetcher(int id,
const GURL& url,
Expand Down Expand Up @@ -128,7 +129,8 @@ class TestURLFetcherFactory : public URLFetcher::Factory {

class FakeURLFetcherFactory : public URLFetcher::Factory {
public:
FakeURLFetcherFactory() {}
FakeURLFetcherFactory();
virtual ~FakeURLFetcherFactory();

// If no fake response is set for the given URL this method will return NULL.
// Otherwise, it will return a URLFetcher object which will respond with the
Expand Down
2 changes: 2 additions & 0 deletions chrome/service/service_process_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ ServiceProcessPrefs::ServiceProcessPrefs(
: prefs_(new JsonPrefStore(pref_filename, file_message_loop_proxy)) {
}

ServiceProcessPrefs::~ServiceProcessPrefs() {}

void ServiceProcessPrefs::ReadPrefs() {
prefs_->ReadPrefs();
}
Expand Down
1 change: 1 addition & 0 deletions chrome/service/service_process_prefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ServiceProcessPrefs {
// file I/O can be done.
ServiceProcessPrefs(const FilePath& pref_filename,
base::MessageLoopProxy* file_message_loop_proxy);
~ServiceProcessPrefs();

// Read preferences from the backing file.
void ReadPrefs();
Expand Down
23 changes: 23 additions & 0 deletions chrome/test/test_url_request_context_getter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) 2011 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.

#include "chrome/test/test_url_request_context_getter.h"

#include "chrome/browser/browser_thread.h"
#include "net/url_request/url_request_test_util.h"

TestURLRequestContextGetter::TestURLRequestContextGetter() {}

TestURLRequestContextGetter::~TestURLRequestContextGetter() {}

net::URLRequestContext* TestURLRequestContextGetter::GetURLRequestContext() {
if (!context_)
context_ = new TestURLRequestContext();
return context_.get();
}

scoped_refptr<base::MessageLoopProxy>
TestURLRequestContextGetter::GetIOMessageLoopProxy() const {
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
}
20 changes: 10 additions & 10 deletions chrome/test/test_url_request_context_getter.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
#pragma once

#include "base/ref_counted.h"
#include "chrome/browser/browser_thread.h"
#include "chrome/common/net/url_request_context_getter.h"
#include "net/url_request/url_request_test_util.h"

namespace base {
class MessageLoopProxy;
}

// 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
Expand All @@ -18,14 +20,12 @@
// special trait that deletes it on the IO thread.
class TestURLRequestContextGetter : public URLRequestContextGetter {
public:
virtual net::URLRequestContext* GetURLRequestContext() {
if (!context_)
context_ = new TestURLRequestContext();
return context_.get();
}
virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const {
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
}
TestURLRequestContextGetter();
virtual ~TestURLRequestContextGetter();

// URLRequestContextGetter:
virtual net::URLRequestContext* GetURLRequestContext();
virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const;

private:
scoped_refptr<net::URLRequestContext> context_;
Expand Down
194 changes: 194 additions & 0 deletions chrome/test/testing_browser_process.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
// Copyright (c) 2011 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.

#include "chrome/test/testing_browser_process.h"

#include "base/string_util.h"
#include "base/synchronization/waitable_event.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/policy/configuration_policy_pref_store.h"
#include "chrome/browser/policy/configuration_policy_provider.h"
#include "chrome/browser/policy/configuration_policy_provider_keeper.h"
#include "chrome/browser/policy/dummy_configuration_policy_provider.h"
#include "ui/base/clipboard/clipboard.h"

TestingBrowserProcess::TestingBrowserProcess()
: shutdown_event_(new base::WaitableEvent(true, false)),
module_ref_count_(0),
app_locale_("en"),
pref_service_(NULL),
created_configuration_policy_provider_keeper_(false) {
}

TestingBrowserProcess::~TestingBrowserProcess() {
}

void TestingBrowserProcess::EndSession() {
}

ResourceDispatcherHost* TestingBrowserProcess::resource_dispatcher_host() {
return NULL;
}

MetricsService* TestingBrowserProcess::metrics_service() {
return NULL;
}

IOThread* TestingBrowserProcess::io_thread() {
return NULL;
}

#if defined(OS_LINUX)
base::Thread* TestingBrowserProcess::background_x11_thread() {
return NULL;
}
#endif

base::Thread* TestingBrowserProcess::file_thread() {
return NULL;
}

base::Thread* TestingBrowserProcess::db_thread() {
return NULL;
}

base::Thread* TestingBrowserProcess::cache_thread() {
return NULL;
}

ProfileManager* TestingBrowserProcess::profile_manager() {
return NULL;
}

PrefService* TestingBrowserProcess::local_state() {
return pref_service_;
}

policy::ConfigurationPolicyProviderKeeper*
TestingBrowserProcess::configuration_policy_provider_keeper() {
if (!created_configuration_policy_provider_keeper_) {
DCHECK(configuration_policy_provider_keeper_.get() == NULL);
created_configuration_policy_provider_keeper_ = true;
const policy::ConfigurationPolicyProvider::PolicyDefinitionList*
policy_list = policy::ConfigurationPolicyPrefStore::
GetChromePolicyDefinitionList();
configuration_policy_provider_keeper_.reset(
new policy::ConfigurationPolicyProviderKeeper(
new policy::DummyConfigurationPolicyProvider(policy_list),
new policy::DummyConfigurationPolicyProvider(policy_list),
new policy::DummyConfigurationPolicyProvider(policy_list)));
}
return configuration_policy_provider_keeper_.get();
}

IconManager* TestingBrowserProcess::icon_manager() {
return NULL;
}

ThumbnailGenerator* TestingBrowserProcess::GetThumbnailGenerator() {
return NULL;
}

DevToolsManager* TestingBrowserProcess::devtools_manager() {
return NULL;
}

SidebarManager* TestingBrowserProcess::sidebar_manager() {
return NULL;
}

TabCloseableStateWatcher* TestingBrowserProcess::tab_closeable_state_watcher() {
return NULL;
}

safe_browsing::ClientSideDetectionService*
TestingBrowserProcess::safe_browsing_detection_service() {
return NULL;
}

ui::Clipboard* TestingBrowserProcess::clipboard() {
if (!clipboard_.get()) {
// Note that we need a MessageLoop for the next call to work.
clipboard_.reset(new ui::Clipboard);
}
return clipboard_.get();
}

NotificationUIManager* TestingBrowserProcess::notification_ui_manager() {
return NULL;
}

GoogleURLTracker* TestingBrowserProcess::google_url_tracker() {
return google_url_tracker_.get();
}

IntranetRedirectDetector* TestingBrowserProcess::intranet_redirect_detector() {
return NULL;
}

AutomationProviderList* TestingBrowserProcess::InitAutomationProviderList() {
return NULL;
}

void TestingBrowserProcess::InitDevToolsHttpProtocolHandler(
const std::string& ip,
int port,
const std::string& frontend_url) {
}

void TestingBrowserProcess::InitDevToolsLegacyProtocolHandler(int port) {
}

unsigned int TestingBrowserProcess::AddRefModule() {
return ++module_ref_count_;
}

unsigned int TestingBrowserProcess::ReleaseModule() {
DCHECK(module_ref_count_ > 0);
return --module_ref_count_;
}

bool TestingBrowserProcess::IsShuttingDown() {
return false;
}

printing::PrintJobManager* TestingBrowserProcess::print_job_manager() {
return NULL;
}

printing::PrintPreviewTabController*
TestingBrowserProcess::print_preview_tab_controller() {
return NULL;
}

const std::string& TestingBrowserProcess::GetApplicationLocale() {
return app_locale_;
}

void TestingBrowserProcess::SetApplicationLocale(
const std::string& app_locale) {
app_locale_ = app_locale;
}

DownloadStatusUpdater* TestingBrowserProcess::download_status_updater() {
return NULL;
}

base::WaitableEvent* TestingBrowserProcess::shutdown_event() {
return shutdown_event_.get();
}

bool TestingBrowserProcess::have_inspector_files() const {
return true;
}

void TestingBrowserProcess::SetPrefService(PrefService* pref_service) {
pref_service_ = pref_service;
}

void TestingBrowserProcess::SetGoogleURLTracker(
GoogleURLTracker* google_url_tracker) {
google_url_tracker_.reset(google_url_tracker);
}
Loading

0 comments on commit 0a071a3

Please sign in to comment.