diff options
34 files changed, 129 insertions, 193 deletions
diff --git a/chrome/browser/autocomplete/search_provider_unittest.cc b/chrome/browser/autocomplete/search_provider_unittest.cc index 7a2da19..cc27f2d 100644 --- a/chrome/browser/autocomplete/search_provider_unittest.cc +++ b/chrome/browser/autocomplete/search_provider_unittest.cc @@ -20,7 +20,7 @@ #include "chrome/test/testing_browser_process_test.h" #include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" @@ -152,8 +152,6 @@ void SearchProviderTest::SetUp() { provider_ = new SearchProvider(this, &profile_); - URLFetcher::set_factory(&test_factory_); - // Prevent the Instant field trial from kicking in. PrefService* service = profile_.GetPrefs(); service->SetBoolean(prefs::kInstantEnabledOnce, true); @@ -209,8 +207,6 @@ void SearchProviderTest::QueryForInputAndSetWYTMatch( void SearchProviderTest::TearDown() { message_loop_.RunAllPending(); - URLFetcher::set_factory(NULL); - // Shutdown the provider before the profile. provider_ = NULL; } diff --git a/chrome/browser/autofill/autofill_browsertest.cc b/chrome/browser/autofill/autofill_browsertest.cc index 66c1197..8f5263f 100644 --- a/chrome/browser/autofill/autofill_browsertest.cc +++ b/chrome/browser/autofill/autofill_browsertest.cc @@ -27,7 +27,7 @@ #include "content/browser/renderer_host/mock_render_process_host.h" #include "content/browser/renderer_host/render_view_host.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/base/keycodes/keyboard_codes.h" @@ -70,10 +70,6 @@ class AutofillTest : public InProcessBrowserTest { EnableDOMAutomation(); } - virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { - URLFetcher::set_factory(&url_fetcher_factory_); - } - void CreateTestProfile() { autofill_test::DisableSystemServices(browser()->profile()); diff --git a/chrome/browser/autofill/autofill_download_unittest.cc b/chrome/browser/autofill/autofill_download_unittest.cc index f62383f0..aa064a2 100644 --- a/chrome/browser/autofill/autofill_download_unittest.cc +++ b/chrome/browser/autofill/autofill_download_unittest.cc @@ -16,7 +16,7 @@ #include "chrome/test/testing_browser_process.h" #include "chrome/test/testing_browser_process_test.h" #include "chrome/test/testing_profile.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_status.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -121,7 +121,6 @@ TEST_F(AutofillDownloadTest, QueryAndUploadTest) { // Create and register factory. AutofillDownloadTestHelper helper; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); FormData form; form.method = ASCIIToUTF16("post"); @@ -363,9 +362,6 @@ TEST_F(AutofillDownloadTest, QueryAndUploadTest) { FieldTypeSet())); fetcher = factory.GetFetcherByID(5); EXPECT_EQ(NULL, fetcher); - - // Make sure consumer of URLFetcher does the right thing. - URLFetcher::set_factory(NULL); } TEST_F(AutofillDownloadTest, CacheQueryTest) { @@ -373,7 +369,6 @@ TEST_F(AutofillDownloadTest, CacheQueryTest) { AutofillDownloadTestHelper helper; // Create and register factory. TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); helper.InitContextGetter(); FormData form; @@ -545,8 +540,5 @@ TEST_F(AutofillDownloadTest, CacheQueryTest) { std::string(responses[0])); ASSERT_EQ(static_cast<size_t>(1), helper.responses_.size()); EXPECT_EQ(responses[0], helper.responses_.front().response); - - // Make sure consumer of URLFetcher does the right thing. - URLFetcher::set_factory(NULL); } diff --git a/chrome/browser/chromeos/login/google_authenticator_unittest.cc b/chrome/browser/chromeos/login/google_authenticator_unittest.cc index 6cf3913..1db3fe4 100644 --- a/chrome/browser/chromeos/login/google_authenticator_unittest.cc +++ b/chrome/browser/chromeos/login/google_authenticator_unittest.cc @@ -558,7 +558,6 @@ TEST_F(GoogleAuthenticatorTest, FullLogin) { TestingProfile profile; MockFactory<MockFetcher> factory; - URLFetcher::set_factory(&factory); scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); EXPECT_CALL(*user_manager_.get(), IsKnownUser(username_)) @@ -568,7 +567,6 @@ TEST_F(GoogleAuthenticatorTest, FullLogin) { auth->AuthenticateToLogin( &profile, username_, password_, std::string(), std::string()); - URLFetcher::set_factory(NULL); message_loop_ui_.RunAllPending(); } @@ -595,7 +593,6 @@ TEST_F(GoogleAuthenticatorTest, FullHostedLoginFailure) { TestingProfile profile; MockFactory<HostedFetcher> factory_invalid; - URLFetcher::set_factory(&factory_invalid); scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); auth->set_user_manager(user_manager_.get()); @@ -612,7 +609,6 @@ TEST_F(GoogleAuthenticatorTest, FullHostedLoginFailure) { // Run the UI thread until we exit it gracefully. message_loop_ui_.Run(); - URLFetcher::set_factory(NULL); } TEST_F(GoogleAuthenticatorTest, CancelLogin) { @@ -643,7 +639,6 @@ TEST_F(GoogleAuthenticatorTest, CancelLogin) { // and then come back on the UI thread after a small delay. They expect to // be canceled before they come back, and the test will fail if they are not. MockFactory<ExpectCanceledFetcher> factory; - URLFetcher::set_factory(&factory); scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); // For when |auth| tries to load the localaccount file. @@ -658,8 +653,6 @@ TEST_F(GoogleAuthenticatorTest, CancelLogin) { // Post a task to cancel the login attempt. CancelLogin(auth.get()); - URLFetcher::set_factory(NULL); - // Run the UI thread until we exit it gracefully. message_loop_ui_.Run(); } @@ -692,7 +685,6 @@ TEST_F(GoogleAuthenticatorTest, CancelLoginAlreadyGotLocalaccount) { // and then come back on the UI thread after a small delay. They expect to // be canceled before they come back, and the test will fail if they are not. MockFactory<ExpectCanceledFetcher> factory; - URLFetcher::set_factory(&factory); scoped_refptr<GoogleAuthenticator> auth(new GoogleAuthenticator(&consumer)); // This time, instead of allowing |auth| to go get the localaccount file @@ -708,8 +700,6 @@ TEST_F(GoogleAuthenticatorTest, CancelLoginAlreadyGotLocalaccount) { // Post a task to cancel the login attempt. CancelLogin(auth.get()); - URLFetcher::set_factory(NULL); - // Run the UI thread until we exit it gracefully. message_loop_ui_.Run(); } diff --git a/chrome/browser/chromeos/login/online_attempt_unittest.cc b/chrome/browser/chromeos/login/online_attempt_unittest.cc index 1222e25..04e1b93 100644 --- a/chrome/browser/chromeos/login/online_attempt_unittest.cc +++ b/chrome/browser/chromeos/login/online_attempt_unittest.cc @@ -132,7 +132,6 @@ TEST_F(OnlineAttemptTest, LoginCancelRetry) { // This factory creates fake URLFetchers that Start() a fake fetch attempt // and then come back on the IO thread saying they've been canceled. MockFactory<GotCanceledFetcher> factory; - URLFetcher::set_factory(&factory); attempt_->Initiate(&profile); BrowserThread::PostTask( @@ -144,7 +143,6 @@ TEST_F(OnlineAttemptTest, LoginCancelRetry) { EXPECT_TRUE(error == state_.online_outcome().error()); EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, state_.online_outcome().reason()); - URLFetcher::set_factory(NULL); } TEST_F(OnlineAttemptTest, LoginTimeout) { @@ -159,7 +157,6 @@ TEST_F(OnlineAttemptTest, LoginTimeout) { // This factory creates fake URLFetchers that Start() a fake fetch attempt // and then come back on the IO thread saying they've been canceled. MockFactory<ExpectCanceledFetcher> factory; - URLFetcher::set_factory(&factory); attempt_->Initiate(&profile); BrowserThread::PostTask( @@ -172,7 +169,6 @@ TEST_F(OnlineAttemptTest, LoginTimeout) { MessageLoop::current()->Run(); EXPECT_EQ(LoginFailure::LOGIN_TIMED_OUT, state_.online_outcome().reason()); - URLFetcher::set_factory(NULL); } TEST_F(OnlineAttemptTest, HostedLoginRejected) { @@ -188,7 +184,6 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) { // This is how we inject fake URLFetcher objects, with a factory. MockFactory<HostedFetcher> factory; - URLFetcher::set_factory(&factory); TestAttemptState local_state("", "", "", "", "", true); attempt_ = new OnlineAttempt(&local_state, resolver_.get()); @@ -202,7 +197,6 @@ TEST_F(OnlineAttemptTest, HostedLoginRejected) { EXPECT_EQ(error, local_state.online_outcome()); EXPECT_EQ(LoginFailure::NETWORK_AUTH_FAILED, local_state.online_outcome().reason()); - URLFetcher::set_factory(NULL); } TEST_F(OnlineAttemptTest, FullLogin) { @@ -214,7 +208,6 @@ TEST_F(OnlineAttemptTest, FullLogin) { // This is how we inject fake URLFetcher objects, with a factory. MockFactory<SuccessFetcher> factory; - URLFetcher::set_factory(&factory); TestAttemptState local_state("", "", "", "", "", true); attempt_ = new OnlineAttempt(&local_state, resolver_.get()); @@ -226,7 +219,6 @@ TEST_F(OnlineAttemptTest, FullLogin) { MessageLoop::current()->Run(); EXPECT_EQ(LoginFailure::None(), local_state.online_outcome()); - URLFetcher::set_factory(NULL); } TEST_F(OnlineAttemptTest, LoginNetFailure) { diff --git a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc index 62bba47..0714929 100644 --- a/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc +++ b/chrome/browser/chromeos/login/parallel_authenticator_unittest.cc @@ -570,7 +570,6 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetNewPassword) { ExpectLoginSuccess(username_, password_, result_, false); MockFactory<SuccessFetcher> factory; - URLFetcher::set_factory(&factory); TestingProfile profile; auth_->RetryAuth(&profile, @@ -613,7 +612,6 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { ExpectLoginFailure(failure); MockFactory<CaptchaFetcher> factory; - URLFetcher::set_factory(&factory); TestingProfile profile; auth_->RetryAuth(&profile, diff --git a/chrome/browser/component_updater/component_updater_service_unittest.cc b/chrome/browser/component_updater/component_updater_service_unittest.cc index 8b47036..6248356 100644 --- a/chrome/browser/component_updater/component_updater_service_unittest.cc +++ b/chrome/browser/component_updater/component_updater_service_unittest.cc @@ -16,7 +16,7 @@ #include "chrome/test/test_url_request_context_getter.h" #include "content/common/notification_observer.h" #include "content/common/notification_service.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/extensions/extension_updater_unittest.cc b/chrome/browser/extensions/extension_updater_unittest.cc index 6e6319d..010f245 100644 --- a/chrome/browser/extensions/extension_updater_unittest.cc +++ b/chrome/browser/extensions/extension_updater_unittest.cc @@ -27,7 +27,7 @@ #include "chrome/common/pref_names.h" #include "chrome/test/testing_profile.h" #include "content/browser/browser_thread.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "libxml/globals.h" #include "net/base/escape.h" #include "net/base/load_flags.h" @@ -337,7 +337,6 @@ class ExtensionUpdaterTest : public testing::Test { // Set up and start the updater. TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); ExtensionUpdater updater( &service, service.extension_prefs(), service.pref_service(), service.profile(), 60*60*24); @@ -390,7 +389,6 @@ class ExtensionUpdaterTest : public testing::Test { io_thread.Start(); TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); ExtensionUpdater updater( &service, service.extension_prefs(), service.pref_service(), service.profile(), 60*60*24); @@ -579,7 +577,6 @@ class ExtensionUpdaterTest : public testing::Test { TestURLFetcherFactory factory; TestURLFetcher* fetcher = NULL; - URLFetcher::set_factory(&factory); scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests); ExtensionUpdater updater(service.get(), service->extension_prefs(), @@ -659,7 +656,6 @@ class ExtensionUpdaterTest : public testing::Test { TestURLFetcherFactory factory; TestURLFetcher* fetcher = NULL; - URLFetcher::set_factory(&factory); scoped_ptr<ServiceForDownloadTests> service(new ServiceForDownloadTests); ExtensionUpdater updater(service.get(), service->extension_prefs(), service->pref_service(), @@ -714,8 +710,6 @@ class ExtensionUpdaterTest : public testing::Test { // because of ImportantFileWriter. file_thread.Start(); service.reset(); - - URLFetcher::set_factory(NULL); } static void TestBlacklistDownloading() { @@ -727,7 +721,6 @@ class ExtensionUpdaterTest : public testing::Test { TestURLFetcherFactory factory; TestURLFetcher* fetcher = NULL; - URLFetcher::set_factory(&factory); ServiceForBlacklistTests service; ExtensionUpdater updater( &service, service.extension_prefs(), service.pref_service(), @@ -764,8 +757,6 @@ class ExtensionUpdaterTest : public testing::Test { EXPECT_EQ(version, service.pref_service()-> GetString(prefs::kExtensionBlacklistUpdateVersion)); - - URLFetcher::set_factory(NULL); } // Two extensions are updated. If |updates_start_running| is true, the @@ -781,7 +772,6 @@ class ExtensionUpdaterTest : public testing::Test { TestURLFetcherFactory factory; TestURLFetcher* fetcher = NULL; - URLFetcher::set_factory(&factory); ServiceForDownloadTests service; ExtensionUpdater updater( &service, service.extension_prefs(), service.pref_service(), @@ -911,7 +901,6 @@ class ExtensionUpdaterTest : public testing::Test { BrowserThread file_thread(BrowserThread::FILE, &message_loop); TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); // Set up 2 mock extensions, one with a google.com update url and one // without. @@ -1198,7 +1187,6 @@ TEST(ExtensionUpdaterTest, TestStartUpdateCheckMemory) { ServiceForManifestTests service; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); ExtensionUpdater updater( &service, service.extension_prefs(), service.pref_service(), service.profile(), kUpdateFrequencySecs); @@ -1220,7 +1208,6 @@ TEST(ExtensionUpdaterTest, TestCheckSoon) { ServiceForManifestTests service; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); ExtensionUpdater updater( &service, service.extension_prefs(), service.pref_service(), service.profile(), kUpdateFrequencySecs); diff --git a/chrome/browser/google/google_url_tracker_unittest.cc b/chrome/browser/google/google_url_tracker_unittest.cc index a704795..646a370 100644 --- a/chrome/browser/google/google_url_tracker_unittest.cc +++ b/chrome/browser/google/google_url_tracker_unittest.cc @@ -15,8 +15,8 @@ #include "chrome/test/testing_pref_service.h" #include "content/browser/browser_thread.h" #include "content/common/notification_service.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_test_util.h" @@ -157,13 +157,11 @@ void GoogleURLTrackerTest::SetUp() { MessageLoop::current()->RunAllPending(); testing_browser_process_.get()->SetGoogleURLTracker(tracker); - URLFetcher::set_factory(&fetcher_factory_); g_browser_process->google_url_tracker()->infobar_creator_ = &CreateTestInfobar; } void GoogleURLTrackerTest::TearDown() { - URLFetcher::set_factory(NULL); testing_browser_process_.get()->SetGoogleURLTracker(NULL); network_change_notifier_.reset(); } diff --git a/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc b/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc index a5bf9af..cfef458 100644 --- a/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc +++ b/chrome/browser/net/gaia/gaia_oauth_fetcher_unittest.cc @@ -17,8 +17,8 @@ #include "chrome/common/net/http_return.h" #include "chrome/test/testing_profile.h" #include "content/common/notification_service.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/url_request/url_request_status.h" diff --git a/chrome/browser/net/gaia/token_service_unittest.cc b/chrome/browser/net/gaia/token_service_unittest.cc index 0a6d598..05f0fe8 100644 --- a/chrome/browser/net/gaia/token_service_unittest.cc +++ b/chrome/browser/net/gaia/token_service_unittest.cc @@ -13,7 +13,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/net/gaia/gaia_auth_fetcher_unittest.h" #include "chrome/common/net/gaia/gaia_constants.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" TokenAvailableTracker::TokenAvailableTracker() {} @@ -71,8 +71,6 @@ void TokenServiceTestHarness::SetUp() { Source<TokenService>(&service_)); service_.Initialize("test", profile_.get()); - - URLFetcher::set_factory(NULL); } void TokenServiceTestHarness::TearDown() { @@ -191,7 +189,6 @@ TEST_F(TokenServiceTest, ResetSimple) { TEST_F(TokenServiceTest, ResetComplex) { TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); service_.StartFetchingTokens(); // You have to call delegates by hand with the test fetcher, // Let's pretend only one returned. @@ -220,14 +217,15 @@ TEST_F(TokenServiceTest, ResetComplex) { } TEST_F(TokenServiceTest, FullIntegration) { - MockFactory<MockFetcher> factory; std::string result = "SID=sid\nLSID=lsid\nAuth=auth\n"; - factory.set_results(result); - URLFetcher::set_factory(&factory); - EXPECT_FALSE(service_.HasTokenForService(GaiaConstants::kSyncService)); - EXPECT_FALSE(service_.HasTokenForService(GaiaConstants::kTalkService)); - service_.StartFetchingTokens(); - URLFetcher::set_factory(NULL); + + { + MockFactory<MockFetcher> factory; + factory.set_results(result); + EXPECT_FALSE(service_.HasTokenForService(GaiaConstants::kSyncService)); + EXPECT_FALSE(service_.HasTokenForService(GaiaConstants::kTalkService)); + service_.StartFetchingTokens(); + } EXPECT_TRUE(service_.HasTokenForService(GaiaConstants::kSyncService)); EXPECT_TRUE(service_.HasTokenForService(GaiaConstants::kTalkService)); diff --git a/chrome/browser/policy/cloud_policy_subsystem_unittest.cc b/chrome/browser/policy/cloud_policy_subsystem_unittest.cc index c5b11d7..7c1c16a 100644 --- a/chrome/browser/policy/cloud_policy_subsystem_unittest.cc +++ b/chrome/browser/policy/cloud_policy_subsystem_unittest.cc @@ -114,7 +114,6 @@ class CloudPolicySubsystemTestBase : public TESTBASE { logger_.reset(new EventLogger); factory_.reset(new TestingPolicyURLFetcherFactory(logger_.get())); - URLFetcher::set_factory(factory_.get()); ASSERT_TRUE(temp_user_data_dir_.CreateUniqueTempDir()); data_store_.reset(CloudPolicyDataStore::CreateForUserPolicies()); cache_ = new UserPolicyCache( @@ -127,7 +126,7 @@ class CloudPolicySubsystemTestBase : public TESTBASE { } virtual void TearDown() { - ((TestingBrowserProcess*) g_browser_process)->SetLocalState(NULL); + static_cast<TestingBrowserProcess*>(g_browser_process)->SetLocalState(NULL); cloud_policy_subsystem_->Shutdown(); cloud_policy_subsystem_.reset(); data_store_.reset(); diff --git a/chrome/browser/policy/device_management_service_unittest.cc b/chrome/browser/policy/device_management_service_unittest.cc index 01f6740..0c3c242 100644 --- a/chrome/browser/policy/device_management_service_unittest.cc +++ b/chrome/browser/policy/device_management_service_unittest.cc @@ -11,7 +11,7 @@ #include "chrome/browser/policy/device_management_service.h" #include "chrome/browser/policy/proto/device_management_constants.h" #include "content/browser/browser_thread.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/base/escape.h" #include "net/url_request/url_request_status.h" #include "net/url_request/url_request_test_util.h" @@ -50,15 +50,11 @@ class DeviceManagementServiceTestBase : public TESTBASE { InitializeService(); } - virtual void SetUp() { - URLFetcher::set_factory(&factory_); - } - virtual void TearDown() { - URLFetcher::set_factory(NULL); backend_.reset(); service_.reset(); loop_.RunAllPending(); + TESTBASE::TearDown(); } void ResetService() { diff --git a/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc b/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc index fc191a8..3924095 100644 --- a/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc +++ b/chrome/browser/policy/enterprise_metrics_enrollment_browsertest.cc @@ -12,7 +12,7 @@ #include "chrome/browser/policy/enterprise_metrics.h" #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/gaia/google_service_auth_error.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "testing/gtest/include/gtest/gtest.h" namespace chromeos { @@ -36,9 +36,6 @@ class EnterpriseMetricsEnrollmentTest : public WizardInProcessBrowserTest { ASSERT_TRUE(controller() != NULL); - // Use mock URLFetchers. - URLFetcher::set_factory(&factory_); - screen_ = controller()->GetEnterpriseEnrollmentScreen(); ASSERT_TRUE(screen_ != NULL); diff --git a/chrome/browser/policy/testing_policy_url_fetcher_factory.cc b/chrome/browser/policy/testing_policy_url_fetcher_factory.cc index de36d3b..97feda1 100644 --- a/chrome/browser/policy/testing_policy_url_fetcher_factory.cc +++ b/chrome/browser/policy/testing_policy_url_fetcher_factory.cc @@ -92,9 +92,10 @@ void TestingPolicyURLFetcher::Respond() { TestingPolicyURLFetcherFactory::TestingPolicyURLFetcherFactory( EventLogger* logger) - : logger_(logger), - scheduler_(new LoggingWorkScheduler(logger)), - ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + logger_(logger), + scheduler_(new LoggingWorkScheduler(logger)), + ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { } TestingPolicyURLFetcherFactory::~TestingPolicyURLFetcherFactory() { diff --git a/chrome/browser/policy/testing_policy_url_fetcher_factory.h b/chrome/browser/policy/testing_policy_url_fetcher_factory.h index 328cd3e..2c27145 100644 --- a/chrome/browser/policy/testing_policy_url_fetcher_factory.h +++ b/chrome/browser/policy/testing_policy_url_fetcher_factory.h @@ -12,6 +12,7 @@ #include "base/memory/weak_ptr.h" #include "chrome/browser/policy/logging_work_scheduler.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "testing/gmock/include/gmock/gmock.h" @@ -25,9 +26,9 @@ struct TestURLResponse { }; // Creates mock URLFetchers whose behavior can be controlled in tests. To do so -// specify this factory with URLFetcher::set_factory, and set mock expectations -// on the method |Intercept|. -class TestingPolicyURLFetcherFactory : public URLFetcher::Factory { +// set mock expectations on the method |Intercept|. +class TestingPolicyURLFetcherFactory : public URLFetcher::Factory, + public ScopedURLFetcherFactory { public: explicit TestingPolicyURLFetcherFactory(EventLogger* logger); virtual ~TestingPolicyURLFetcherFactory(); diff --git a/chrome/browser/safe_browsing/client_side_detection_service_unittest.cc b/chrome/browser/safe_browsing/client_side_detection_service_unittest.cc index 0e526b3..fbebf27 100644 --- a/chrome/browser/safe_browsing/client_side_detection_service_unittest.cc +++ b/chrome/browser/safe_browsing/client_side_detection_service_unittest.cc @@ -16,8 +16,8 @@ #include "chrome/common/safe_browsing/client_model.pb.h" #include "chrome/common/safe_browsing/csd.pb.h" #include "content/browser/browser_thread.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "crypto/sha2.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_request_status.h" @@ -50,7 +50,6 @@ class ClientSideDetectionServiceTest : public testing::Test { file_thread_.reset(new BrowserThread(BrowserThread::FILE, &msg_loop_)); factory_.reset(new FakeURLFetcherFactory()); - URLFetcher::set_factory(factory_.get()); browser_thread_.reset(new BrowserThread(BrowserThread::UI, &msg_loop_)); } @@ -58,7 +57,6 @@ class ClientSideDetectionServiceTest : public testing::Test { virtual void TearDown() { msg_loop_.RunAllPending(); csd_service_.reset(); - URLFetcher::set_factory(NULL); file_thread_.reset(); browser_thread_.reset(); } diff --git a/chrome/browser/sync/glue/http_bridge_unittest.cc b/chrome/browser/sync/glue/http_bridge_unittest.cc index 6e7026e..2e45415 100644 --- a/chrome/browser/sync/glue/http_bridge_unittest.cc +++ b/chrome/browser/sync/glue/http_bridge_unittest.cc @@ -7,7 +7,7 @@ #include "chrome/browser/sync/glue/http_bridge.h" #include "chrome/test/test_url_request_context_getter.h" #include "content/browser/browser_thread.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/test/test_server.h" #include "net/url_request/url_request_test_util.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/sync/glue/sync_backend_host_unittest.cc b/chrome/browser/sync/glue/sync_backend_host_unittest.cc index bee87a6..f642a50 100644 --- a/chrome/browser/sync/glue/sync_backend_host_unittest.cc +++ b/chrome/browser/sync/glue/sync_backend_host_unittest.cc @@ -16,7 +16,7 @@ #include "chrome/test/test_url_request_context_getter.h" #include "content/browser/browser_thread.h" #include "content/common/url_fetcher.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -81,7 +81,6 @@ TEST_F(SyncBackendHostTest, InitShutdown) { FakeURLFetcherFactory test_factory_; test_factory_.SetFakeResponse(k_mock_url + "/time?command=get_time", "", false); - URLFetcher::set_factory(&test_factory_); TestingProfile profile; profile.CreateRequestContext(); @@ -107,7 +106,6 @@ TEST_F(SyncBackendHostTest, InitShutdown) { credentials, true); backend.Shutdown(false); - URLFetcher::set_factory(NULL); } TEST_F(SyncBackendHostTest, MakePendingConfigModeState) { diff --git a/chrome/browser/sync/signin_manager_unittest.cc b/chrome/browser/sync/signin_manager_unittest.cc index 7d1325a..9c60ce0 100644 --- a/chrome/browser/sync/signin_manager_unittest.cc +++ b/chrome/browser/sync/signin_manager_unittest.cc @@ -12,7 +12,7 @@ #include "chrome/common/net/gaia/gaia_urls.h" #include "chrome/test/signaling_task.h" #include "chrome/test/testing_profile.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_status.h" @@ -28,8 +28,6 @@ class SigninManagerTest : public TokenServiceTestHarness { Source<Profile>(profile_.get())); google_login_failure_.ListenFor(chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, Source<Profile>(profile_.get())); - - URLFetcher::set_factory(&factory_); } void SimulateValidResponse() { diff --git a/chrome/browser/translate/translate_manager_browsertest.cc b/chrome/browser/translate/translate_manager_browsertest.cc index 3ecc3ff..431f9d4 100644 --- a/chrome/browser/translate/translate_manager_browsertest.cc +++ b/chrome/browser/translate/translate_manager_browsertest.cc @@ -32,8 +32,8 @@ #include "content/common/notification_details.h" #include "content/common/notification_observer_mock.h" #include "content/common/notification_registrar.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/view_messages.h" +#include "content/test/test_url_fetcher_factory.h" #include "grit/generated_resources.h" #include "ipc/ipc_test_sink.h" #include "testing/gmock/include/gmock/gmock.h" @@ -147,8 +147,6 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, protected: virtual void SetUp() { - URLFetcher::set_factory(&url_fetcher_factory_); - // Access the TranslateManager singleton so it is created before we call // RenderViewHostTestHarness::SetUp() to match what's done in Chrome, where // the TranslateManager is created before the TabContents. This matters as @@ -176,8 +174,6 @@ class TranslateManagerTest : public TabContentsWrapperTestHarness, Source<TabContentsWrapper>(contents_wrapper())); TabContentsWrapperTestHarness::TearDown(); - - URLFetcher::set_factory(NULL); } void SimulateTranslateScriptURLFetch(bool success) { diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index f872890..bd2b96f 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -34,6 +34,7 @@ 'theme_resources_standard', '../base/base.gyp:test_support_base', '../content/content.gyp:content_gpu', + '../content/content.gyp:test_support_content', '../ipc/ipc.gyp:test_support_ipc', '../media/media.gyp:media_test_support', '../net/net.gyp:net', @@ -214,8 +215,6 @@ '../content/common/notification_observer_mock.h', '../content/common/test_url_constants.cc', '../content/common/test_url_constants.h', - '../content/common/test_url_fetcher_factory.cc', - '../content/common/test_url_fetcher_factory.h', '../content/renderer/mock_content_renderer_client.cc', '../ui/gfx/image/image_unittest_util.h', '../ui/gfx/image/image_unittest_util.cc', @@ -1377,7 +1376,7 @@ 'browser/component_updater/component_updater_interceptor.cc', 'browser/component_updater/component_updater_interceptor.h', 'browser/content_settings/content_settings_mock_observer.cc', - 'browser/content_settings/content_settings_mock_observer.h', + 'browser/content_settings/content_settings_mock_observer.h', 'browser/content_settings/content_settings_mock_provider.cc', 'browser/content_settings/content_settings_mock_provider.h', 'browser/content_settings/content_settings_origin_identifier_value_map_unittest.cc', diff --git a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc index 26160e9..bb65598 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc +++ b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.cc @@ -17,8 +17,8 @@ #include "chrome/common/net/gaia/google_service_auth_error.h" #include "chrome/common/net/http_return.h" #include "chrome/test/testing_profile.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/url_request/url_request_status.h" @@ -386,7 +386,6 @@ TEST_F(GaiaAuthFetcherTest, FullLogin) { TestingProfile profile; MockFactory<MockFetcher> factory; - URLFetcher::set_factory(&factory); GaiaAuthFetcher auth(&consumer, std::string(), profile_.GetRequestContext()); @@ -396,8 +395,6 @@ TEST_F(GaiaAuthFetcherTest, FullLogin) { std::string(), std::string(), GaiaAuthFetcher::HostedAccountsAllowed); - - URLFetcher::set_factory(NULL); } TEST_F(GaiaAuthFetcherTest, FullLoginFailure) { @@ -408,7 +405,6 @@ TEST_F(GaiaAuthFetcherTest, FullLoginFailure) { TestingProfile profile; MockFactory<MockFetcher> factory; - URLFetcher::set_factory(&factory); factory.set_success(false); GaiaAuthFetcher auth(&consumer, std::string(), @@ -419,8 +415,6 @@ TEST_F(GaiaAuthFetcherTest, FullLoginFailure) { std::string(), std::string(), GaiaAuthFetcher::HostedAccountsAllowed); - - URLFetcher::set_factory(NULL); } TEST_F(GaiaAuthFetcherTest, ClientFetchPending) { @@ -430,7 +424,6 @@ TEST_F(GaiaAuthFetcherTest, ClientFetchPending) { TestingProfile profile; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); GaiaAuthFetcher auth(&consumer, std::string(), profile_.GetRequestContext()); @@ -441,7 +434,6 @@ TEST_F(GaiaAuthFetcherTest, ClientFetchPending) { std::string(), GaiaAuthFetcher::HostedAccountsAllowed); - URLFetcher::set_factory(NULL); EXPECT_TRUE(auth.HasPendingFetch()); auth.OnURLFetchComplete( NULL, @@ -459,14 +451,12 @@ TEST_F(GaiaAuthFetcherTest, FullTokenSuccess) { .Times(1); TestingProfile profile; - TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); + TestURLFetcherFactory factory; GaiaAuthFetcher auth(&consumer, std::string(), - profile_.GetRequestContext()); + profile_.GetRequestContext()); auth.StartIssueAuthToken("sid", "lsid", "service"); - URLFetcher::set_factory(NULL); EXPECT_TRUE(auth.HasPendingFetch()); auth.OnURLFetchComplete( NULL, @@ -485,13 +475,11 @@ TEST_F(GaiaAuthFetcherTest, FullTokenFailure) { TestingProfile profile; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); GaiaAuthFetcher auth(&consumer, std::string(), profile_.GetRequestContext()); auth.StartIssueAuthToken("sid", "lsid", "service"); - URLFetcher::set_factory(NULL); EXPECT_TRUE(auth.HasPendingFetch()); auth.OnURLFetchComplete( NULL, @@ -510,13 +498,11 @@ TEST_F(GaiaAuthFetcherTest, TokenAuthSuccess) { TestingProfile profile; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); GaiaAuthFetcher auth(&consumer, std::string(), profile_.GetRequestContext()); auth.StartTokenAuth("myubertoken"); - URLFetcher::set_factory(NULL); EXPECT_TRUE(auth.HasPendingFetch()); auth.OnURLFetchComplete( NULL, @@ -535,13 +521,11 @@ TEST_F(GaiaAuthFetcherTest, TokenAuthUnauthorizedFailure) { TestingProfile profile; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); GaiaAuthFetcher auth(&consumer, std::string(), profile_.GetRequestContext()); auth.StartTokenAuth("badubertoken"); - URLFetcher::set_factory(NULL); EXPECT_TRUE(auth.HasPendingFetch()); auth.OnURLFetchComplete( NULL, @@ -560,13 +544,11 @@ TEST_F(GaiaAuthFetcherTest, TokenAuthNetFailure) { TestingProfile profile; TestURLFetcherFactory factory; - URLFetcher::set_factory(&factory); GaiaAuthFetcher auth(&consumer, std::string(), profile_.GetRequestContext()); auth.StartTokenAuth("badubertoken"); - URLFetcher::set_factory(NULL); EXPECT_TRUE(auth.HasPendingFetch()); auth.OnURLFetchComplete( NULL, diff --git a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h index f7d406c..6cea31c 100644 --- a/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h +++ b/chrome/common/net/gaia/gaia_auth_fetcher_unittest.h @@ -14,6 +14,7 @@ #include "chrome/common/net/gaia/gaia_auth_fetcher.h" #include "chrome/common/net/http_return.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_status.h" // Responds as though ClientLogin returned from the server. @@ -37,10 +38,13 @@ class MockFetcher : public URLFetcher { }; template<typename T> -class MockFactory : public URLFetcher::Factory { +class MockFactory : public URLFetcher::Factory, + public ScopedURLFetcherFactory { public: MockFactory() - : success_(true) {} + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + success_(true) { + } ~MockFactory() {} URLFetcher* CreateURLFetcher(int id, const GURL& url, diff --git a/chrome/common/net/gaia/gaia_oauth_client_unittest.cc b/chrome/common/net/gaia/gaia_oauth_client_unittest.cc index 6e1f20a..e29527b 100644 --- a/chrome/common/net/gaia/gaia_oauth_client_unittest.cc +++ b/chrome/common/net/gaia/gaia_oauth_client_unittest.cc @@ -12,8 +12,8 @@ #include "chrome/common/net/gaia/gaia_oauth_client.h" #include "chrome/common/net/http_return.h" #include "chrome/test/testing_profile.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" #include "net/url_request/url_request_status.h" @@ -69,10 +69,13 @@ class MockOAuthFetcher : public URLFetcher { DISALLOW_COPY_AND_ASSIGN(MockOAuthFetcher); }; -class MockOAuthFetcherFactory : public URLFetcher::Factory { +class MockOAuthFetcherFactory : public URLFetcher::Factory, + public ScopedURLFetcherFactory { public: MockOAuthFetcherFactory() - : response_code_(RC_REQUEST_OK) {} + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + response_code_(RC_REQUEST_OK) { + } ~MockOAuthFetcherFactory() {} virtual URLFetcher* CreateURLFetcher( int id, @@ -152,7 +155,6 @@ TEST_F(GaiaOAuthClientTest, NetworkFailure) { TestingProfile profile; MockOAuthFetcherFactory factory; - URLFetcher::set_factory(&factory); factory.set_response_code(response_code); factory.set_max_failure_count(4); @@ -162,7 +164,6 @@ TEST_F(GaiaOAuthClientTest, NetworkFailure) { GaiaOAuthClient auth(kGaiaOAuth2Url, profile_.GetRequestContext()); auth.GetTokensFromAuthCode(client_info, "auth_code", 2, &delegate); - URLFetcher::set_factory(NULL); } TEST_F(GaiaOAuthClientTest, NetworkFailureRecover) { @@ -175,7 +176,6 @@ TEST_F(GaiaOAuthClientTest, NetworkFailureRecover) { TestingProfile profile; MockOAuthFetcherFactory factory; - URLFetcher::set_factory(&factory); factory.set_response_code(response_code); factory.set_max_failure_count(4); factory.set_results(kDummyGetTokensResult); @@ -186,7 +186,6 @@ TEST_F(GaiaOAuthClientTest, NetworkFailureRecover) { GaiaOAuthClient auth(kGaiaOAuth2Url, profile_.GetRequestContext()); auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); - URLFetcher::set_factory(NULL); } TEST_F(GaiaOAuthClientTest, OAuthFailure) { @@ -198,7 +197,6 @@ TEST_F(GaiaOAuthClientTest, OAuthFailure) { TestingProfile profile; MockOAuthFetcherFactory factory; - URLFetcher::set_factory(&factory); factory.set_response_code(response_code); factory.set_max_failure_count(-1); factory.set_results(kDummyGetTokensResult); @@ -209,7 +207,6 @@ TEST_F(GaiaOAuthClientTest, OAuthFailure) { GaiaOAuthClient auth(kGaiaOAuth2Url, profile_.GetRequestContext()); auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); - URLFetcher::set_factory(NULL); } @@ -221,7 +218,6 @@ TEST_F(GaiaOAuthClientTest, GetTokensSuccess) { TestingProfile profile; MockOAuthFetcherFactory factory; - URLFetcher::set_factory(&factory); factory.set_results(kDummyGetTokensResult); OAuthClientInfo client_info; @@ -230,7 +226,6 @@ TEST_F(GaiaOAuthClientTest, GetTokensSuccess) { GaiaOAuthClient auth(kGaiaOAuth2Url, profile_.GetRequestContext()); auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); - URLFetcher::set_factory(NULL); } TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { @@ -241,7 +236,6 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { TestingProfile profile; MockOAuthFetcherFactory factory; - URLFetcher::set_factory(&factory); factory.set_results(kDummyRefreshTokenResult); OAuthClientInfo client_info; @@ -250,6 +244,5 @@ TEST_F(GaiaOAuthClientTest, RefreshTokenSuccess) { GaiaOAuthClient auth(kGaiaOAuth2Url, profile_.GetRequestContext()); auth.GetTokensFromAuthCode(client_info, "auth_code", -1, &delegate); - URLFetcher::set_factory(NULL); } } // namespace gaia diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index 04152f4..48b4369 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -29,8 +29,8 @@ #include "chrome/test/ui_test_utils.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/tab_contents.h" -#include "content/common/test_url_fetcher_factory.h" #include "content/common/url_fetcher.h" +#include "content/test/test_url_fetcher_factory.h" #include "googleurl/src/gurl.h" #include "net/base/escape.h" #include "net/base/network_change_notifier.h" @@ -321,10 +321,6 @@ void LiveSyncTest::SetUpInProcessBrowserTestFixture() { void LiveSyncTest::TearDownInProcessBrowserTestFixture() { mock_host_resolver_override_.reset(); - - // Switch back to using the default URLFetcher factory. This is a no-op if - // a fake factory wasn't used. - URLFetcher::set_factory(NULL); } void LiveSyncTest::ReadPasswordFile() { @@ -356,7 +352,6 @@ void LiveSyncTest::SetupMockGaiaResponses() { factory_->SetFakeResponse(kGetUserInfoUrl, "email=user@gmail.com", true); factory_->SetFakeResponse(kIssueAuthTokenUrl, "auth", true); factory_->SetFakeResponse(kSearchDomainCheckUrl, ".google.com", true); - URLFetcher::set_factory(factory_.get()); } // Start up a local sync server based on the value of server_type_, which diff --git a/content/DEPS b/content/DEPS index 71029d0..954e378 100644 --- a/content/DEPS +++ b/content/DEPS @@ -18,6 +18,7 @@ include_rules = [ # directories in content/ so we disallow all of them. "-content", "+content/common", + "+content/test", "+grit", "+gpu", diff --git a/content/browser/geolocation/network_location_provider_unittest.cc b/content/browser/geolocation/network_location_provider_unittest.cc index 1192531..6f1e6d8 100644 --- a/content/browser/geolocation/network_location_provider_unittest.cc +++ b/content/browser/geolocation/network_location_provider_unittest.cc @@ -9,7 +9,7 @@ #include "base/values.h" #include "content/browser/geolocation/fake_access_token_store.h" #include "content/browser/geolocation/network_location_provider.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" @@ -115,7 +115,6 @@ MockDeviceDataProviderImpl<DataType>::instance_ = NULL; class GeolocationNetworkProviderTest : public testing::Test { public: virtual void SetUp() { - URLFetcher::set_factory(&url_fetcher_factory_); access_token_store_ = new FakeAccessTokenStore; gateway_data_provider_ = MockDeviceDataProviderImpl<GatewayData>::CreateInstance(); @@ -129,7 +128,6 @@ class GeolocationNetworkProviderTest : public testing::Test { WifiDataProvider::ResetFactory(); RadioDataProvider::ResetFactory(); GatewayDataProvider::ResetFactory(); - URLFetcher::set_factory(NULL); } LocationProviderBase* CreateProvider(bool set_permission_granted) { diff --git a/content/browser/speech/speech_recognition_request_unittest.cc b/content/browser/speech/speech_recognition_request_unittest.cc index bb5e715..f41649c 100644 --- a/content/browser/speech/speech_recognition_request_unittest.cc +++ b/content/browser/speech/speech_recognition_request_unittest.cc @@ -4,7 +4,7 @@ #include "base/utf_string_conversions.h" #include "content/browser/speech/speech_recognition_request.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "net/url_request/url_request_context_getter.h" #include "net/url_request/url_request_status.h" #include "testing/gtest/include/gtest/gtest.h" @@ -27,15 +27,6 @@ class SpeechRecognitionRequestTest : public SpeechRecognitionRequestDelegate, result_ = result; } - // testing::Test methods. - virtual void SetUp() { - URLFetcher::set_factory(&url_fetcher_factory_); - } - - virtual void TearDown() { - URLFetcher::set_factory(NULL); - } - protected: MessageLoop message_loop_; TestURLFetcherFactory url_fetcher_factory_; diff --git a/content/browser/speech/speech_recognizer_unittest.cc b/content/browser/speech/speech_recognizer_unittest.cc index aefde20..d70df62 100644 --- a/content/browser/speech/speech_recognizer_unittest.cc +++ b/content/browser/speech/speech_recognizer_unittest.cc @@ -6,7 +6,7 @@ #include "content/browser/browser_thread.h" #include "content/browser/speech/speech_recognizer.h" -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include "media/audio/test_audio_input_controller_factory.h" #include "net/base/net_errors.h" #include "net/url_request/url_request_status.h" @@ -75,12 +75,10 @@ class SpeechRecognizerTest : public SpeechRecognizerDelegate, // testing::Test methods. virtual void SetUp() { - URLFetcher::set_factory(&url_fetcher_factory_); AudioInputController::set_factory(&audio_input_controller_factory_); } virtual void TearDown() { - URLFetcher::set_factory(NULL); AudioInputController::set_factory(NULL); } diff --git a/content/common/url_fetcher.h b/content/common/url_fetcher.h index 1a54a69..a888868 100644 --- a/content/common/url_fetcher.h +++ b/content/common/url_fetcher.h @@ -11,8 +11,8 @@ // temporary situation. We will work on allowing support for multiple "io" // threads per process. -#ifndef CONTENT_COMMON_NET_URL_FETCHER_H_ -#define CONTENT_COMMON_NET_URL_FETCHER_H_ +#ifndef CONTENT_COMMON_URL_FETCHER_H_ +#define CONTENT_COMMON_URL_FETCHER_H_ #pragma once #include <string> @@ -117,20 +117,10 @@ class URLFetcher { // |request_type| is the type of request to make. // |d| the object that will receive the callback on fetch completion. URLFetcher(const GURL& url, RequestType request_type, Delegate* d); - virtual ~URLFetcher(); - // Sets the factory used by the static method Create to create a URLFetcher. - // URLFetcher does not take ownership of |factory|. A value of NULL results - // in a URLFetcher being created directly. -#if defined(UNIT_TEST) - static void set_factory(Factory* factory) { - factory_ = factory; - } -#endif - // Normally interception is disabled for URLFetcher, but you can use this - // to enable it for tests. Also see the set_factory method for another way + // to enable it for tests. Also see ScopedURLFetcherFactory for another way // of testing code that uses an URLFetcher. static void enable_interception_for_tests(bool enabled) { g_interception_enabled = enabled; @@ -295,13 +285,25 @@ class URLFetcher { virtual ResponseDestinationType GetResponseDestinationForTesting() const; private: - friend class URLFetcherTest; + friend class ScopedURLFetcherFactory; friend class TestURLFetcher; + friend class URLFetcherTest; // Only used by URLFetcherTest, returns the number of URLFetcher::Core objects // actively running. static int GetNumFetcherCores(); + static Factory* factory() { return factory_; } + + // Sets the factory used by the static method Create to create a URLFetcher. + // URLFetcher does not take ownership of |factory|. A value of NULL results + // in a URLFetcher being created directly. + // + // NOTE: for safety, this should only be used through ScopedURLFetcherFactory! + static void set_factory(Factory* factory) { + factory_ = factory; + } + class Core; scoped_refptr<Core> core_; @@ -315,4 +317,4 @@ class URLFetcher { DISALLOW_COPY_AND_ASSIGN(URLFetcher); }; -#endif // CONTENT_COMMON_NET_URL_FETCHER_H_ +#endif // CONTENT_COMMON_URL_FETCHER_H_ diff --git a/content/content_tests.gypi b/content/content_tests.gypi index 5920993..15a48cd5 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -5,9 +5,24 @@ { 'targets': [ { + 'target_name': 'test_support_content', + 'type': 'static_library', + 'dependencies': [ + 'content_common', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'test/test_url_fetcher_factory.cc', + 'test/test_url_fetcher_factory.h', + ], + }, + { 'target_name': 'content_unittests', 'type': 'executable', 'dependencies': [ + 'test_support_content', '../base/base.gyp:test_support_base', ], 'include_dirs': [ diff --git a/content/common/test_url_fetcher_factory.cc b/content/test/test_url_fetcher_factory.cc index c92ae0f..ad6e512 100644 --- a/content/common/test_url_fetcher_factory.cc +++ b/content/test/test_url_fetcher_factory.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "content/common/test_url_fetcher_factory.h" +#include "content/test/test_url_fetcher_factory.h" #include <string> @@ -10,6 +10,16 @@ #include "base/message_loop.h" #include "net/url_request/url_request_status.h" +ScopedURLFetcherFactory::ScopedURLFetcherFactory(URLFetcher::Factory* factory) { + DCHECK(!URLFetcher::factory()); + URLFetcher::set_factory(factory); +} + +ScopedURLFetcherFactory::~ScopedURLFetcherFactory() { + DCHECK(URLFetcher::factory()); + URLFetcher::set_factory(NULL); +} + TestURLFetcher::TestURLFetcher(int id, const GURL& url, URLFetcher::RequestType request_type, @@ -62,7 +72,9 @@ bool TestURLFetcher::GetResponseAsFilePath( return true; } -TestURLFetcherFactory::TestURLFetcherFactory() {} +TestURLFetcherFactory::TestURLFetcherFactory() + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} TestURLFetcherFactory::~TestURLFetcherFactory() {} @@ -146,10 +158,15 @@ class FakeURLFetcher : public URLFetcher { DISALLOW_COPY_AND_ASSIGN(FakeURLFetcher); }; -FakeURLFetcherFactory::FakeURLFetcherFactory() {} +FakeURLFetcherFactory::FakeURLFetcherFactory() + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { +} FakeURLFetcherFactory::FakeURLFetcherFactory( - URLFetcher::Factory* default_factory) : default_factory_(default_factory) {} + URLFetcher::Factory* default_factory) + : ScopedURLFetcherFactory(ALLOW_THIS_IN_INITIALIZER_LIST(this)), + default_factory_(default_factory) { +} FakeURLFetcherFactory::~FakeURLFetcherFactory() {} diff --git a/content/common/test_url_fetcher_factory.h b/content/test/test_url_fetcher_factory.h index 70cf6f8..f402875 100644 --- a/content/common/test_url_fetcher_factory.h +++ b/content/test/test_url_fetcher_factory.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CONTENT_COMMON_TEST_URL_FETCHER_FACTORY_H_ -#define CONTENT_COMMON_TEST_URL_FETCHER_FACTORY_H_ +#ifndef CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ +#define CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ #pragma once #include <list> @@ -11,9 +11,21 @@ #include <string> #include <utility> +#include "base/threading/non_thread_safe.h" #include "content/common/url_fetcher.h" -#include "net/url_request/url_request_status.h" #include "googleurl/src/gurl.h" +#include "net/url_request/url_request_status.h" + +// Changes URLFetcher's Factory for the lifetime of the object. +// Note that this scoper cannot be nested (to make it even harder to misuse). +class ScopedURLFetcherFactory : public base::NonThreadSafe { + public: + explicit ScopedURLFetcherFactory(URLFetcher::Factory* factory); + virtual ~ScopedURLFetcherFactory(); + + private: + DISALLOW_COPY_AND_ASSIGN(ScopedURLFetcherFactory); +}; // TestURLFetcher and TestURLFetcherFactory are used for testing consumers of // URLFetcher. TestURLFetcherFactory is a URLFetcher::Factory that creates @@ -26,9 +38,8 @@ // MessageLoopForUI message_loop; // // And io_thread to release URLRequestContextGetter in URLFetcher::Core. // BrowserThread io_thread(BrowserThread::IO, &message_loop); -// // Create and register factory. +// // Create factory (it automatically sets itself as URLFetcher's factory). // TestURLFetcherFactory factory; -// URLFetcher::set_factory(&factory); // // Do something that triggers creation of a URLFetcher. // TestURLFetcher* fetcher = factory.GetFetcherByID(expected_id); // DCHECK(fetcher); @@ -36,8 +47,6 @@ // fetcher->delegate()->OnURLFetchComplete(...); // // Make sure consumer of URLFetcher does the right thing. // ... -// // Reset factory. -// URLFetcher::set_factory(NULL); // // Note: if you don't know when your request objects will be created you // might want to use the FakeUrlFetcher and FakeUrlFetcherFactory classes @@ -118,7 +127,8 @@ class TestURLFetcher : public URLFetcher { // Simple URLFetcher::Factory method that creates TestURLFetchers. All fetchers // are registered in a map by the id passed to the create method. -class TestURLFetcherFactory : public URLFetcher::Factory { +class TestURLFetcherFactory : public URLFetcher::Factory, + public ScopedURLFetcherFactory { public: TestURLFetcherFactory(); virtual ~TestURLFetcherFactory(); @@ -157,7 +167,6 @@ class TestURLFetcherFactory : public URLFetcher::Factory { // // Example usage: // FakeURLFetcherFactory factory; -// URLFetcher::set_factory(&factory); // // // You know that class SomeService will request url http://a.com/ and you // // want to test the service class by returning an error. @@ -171,7 +180,8 @@ class TestURLFetcherFactory : public URLFetcher::Factory { // SomeService service; // service.Run(); // Will eventually request these two URLs. -class FakeURLFetcherFactory : public URLFetcher::Factory { +class FakeURLFetcherFactory : public URLFetcher::Factory, + public ScopedURLFetcherFactory { public: FakeURLFetcherFactory(); // FakeURLFetcherFactory that will delegate creating URLFetcher for unknown @@ -224,4 +234,4 @@ class URLFetcherFactory : public URLFetcher::Factory { }; -#endif // CONTENT_COMMON_TEST_URL_FETCHER_FACTORY_H_ +#endif // CONTENT_TEST_TEST_URL_FETCHER_FACTORY_H_ |