Skip to content

Commit

Permalink
Remove a couple unused URLFetcher test classes.
Browse files Browse the repository at this point in the history
A bunch of tests were instantiating them but not using them, so also
remove the classes from those tests.

TBR=lambroslambrou@chromium.org
TBR=rogerm@chromium.org
TBR=dvadym@chromium.org
TBR=hendrich@chromium.org

Bug: 1010491
Change-Id: I0528cd61f69e0010eefa45f5c65edf63a09fc6d7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1834926
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: Rohit Rao <rohitrao@chromium.org>
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Reviewed-by: Jian Li <jianli@chromium.org>
Reviewed-by: Eric Roman <eroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702474}
  • Loading branch information
Matt Menke authored and Commit Bot committed Oct 3, 2019
1 parent b2a92c6 commit 9d04509
Show file tree
Hide file tree
Showing 10 changed files with 3 additions and 167 deletions.
4 changes: 0 additions & 4 deletions chrome/browser/autofill/autofill_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/keycodes/keyboard_codes.h"
Expand Down Expand Up @@ -215,9 +214,6 @@ class AutofillTest : public InProcessBrowserTest {
content::WebContents* web_contents() {
return browser()->tab_strip_model()->GetActiveWebContents();
}

private:
net::TestURLFetcherFactory url_fetcher_factory_;
};

// Test that Autofill aggregates a minimum valid profile.
Expand Down
3 changes: 0 additions & 3 deletions chrome/browser/autofill/autofill_interactive_uitest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "net/url_request/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"
Expand Down Expand Up @@ -684,8 +683,6 @@ class AutofillInteractiveTestBase : public AutofillUiTest {
// used by the NetworkService.
content::ContentMockCertVerifier cert_verifier_;

net::TestURLFetcherFactory url_fetcher_factory_;

// KeyPressEventCallback that serves as a sink to ensure that every key press
// event the tests create and have the WebContents forward is handled by some
// key press event callback. It is necessary to have this sinkbecause if no
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@
#include "google_apis/gaia/gaia_constants.h"
#include "google_apis/gaia/gaia_urls.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_context_getter.h"
#include "net/url_request/url_request_status.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
Expand Down Expand Up @@ -357,7 +353,6 @@ class UserCloudPolicyManagerChromeOSTest
PolicyBundle expected_bundle_;

// Policy infrastructure.
net::TestURLFetcherFactory test_url_fetcher_factory_;
TestingPrefServiceSimple prefs_;
MockConfigurationPolicyObserver observer_;
MockDeviceManagementService device_management_service_;
Expand Down Expand Up @@ -759,10 +754,6 @@ TEST_P(UserCloudPolicyManagerChromeOSTest, NonBlockingFirstFetch) {
EXPECT_TRUE(manager_->IsInitializationComplete(POLICY_DOMAIN_CHROME));
EXPECT_FALSE(manager_->core()->client()->is_registered());

// The manager is waiting for the refresh token, and hasn't started any
// fetchers.
EXPECT_FALSE(test_url_fetcher_factory_.GetFetcherByID(0));

AccountInfo account_info =
identity_test_env()->MakePrimaryAccountAvailable(kEmail);
EXPECT_TRUE(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
#include "net/base/filename_util.h"
#include "net/test/embedded_test_server/http_request.h"
#include "net/test/embedded_test_server/http_response.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/platform/web_input_event.h"
#include "ui/base/ui_base_switches.h"
Expand Down Expand Up @@ -916,8 +915,6 @@ IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptIfLinkClicked) {
#endif
IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
MAYBE_VerifyPasswordGenerationUpload) {
// Prevent Autofill requests from actually going over the wire.
net::TestURLFetcherFactory factory;
// Disable Autofill requesting access to AddressBook data. This causes
// the test to hang on Mac.
autofill::test::DisableSystemServices(browser()->profile()->GetPrefs());
Expand Down
23 changes: 2 additions & 21 deletions components/gcm_driver/gcm_client_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
#include "google_apis/gcm/protocol/mcs.pb.h"
#include "net/test/gtest_util.h"
#include "net/test/scoped_disable_exit_on_dfatal.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "services/network/test/test_url_loader_factory.h"
Expand Down Expand Up @@ -191,7 +188,7 @@ class AutoAdvancingTestClock : public base::Clock {
~AutoAdvancingTestClock() override;

base::Time Now() const override;
void Advance(TimeDelta delta);
void Advance(base::TimeDelta delta);
int call_count() const { return call_count_; }

private:
Expand Down Expand Up @@ -294,7 +291,6 @@ class GCMClientImplTest : public testing::Test,
void SetFeatureParams(const base::Feature& feature,
const base::FieldTrialParams& params);

void SetUpUrlFetcherFactory();
void InitializeInvalidationFieldTrial();

void BuildGCMClient(base::TimeDelta clock_step);
Expand Down Expand Up @@ -416,9 +412,6 @@ class GCMClientImplTest : public testing::Test,
AutoAdvancingTestClock* clock() const {
return static_cast<AutoAdvancingTestClock*>(gcm_client_->clock_);
}
net::TestURLFetcherFactory* url_fetcher_factory() {
return &url_fetcher_factory_;
}
network::TestURLLoaderFactory* url_loader_factory() {
return &test_url_loader_factory_;
}
Expand Down Expand Up @@ -448,19 +441,13 @@ class GCMClientImplTest : public testing::Test,

std::unique_ptr<GCMClientImpl> gcm_client_;

net::TestURLFetcherFactory url_fetcher_factory_;

// Injected to GCM client.
scoped_refptr<net::TestURLRequestContextGetter> url_request_context_getter_;
network::TestURLLoaderFactory test_url_loader_factory_;
base::test::ScopedFeatureList scoped_feature_list_;
};

GCMClientImplTest::GCMClientImplTest()
: last_event_(NONE),
last_result_(GCMClient::UNKNOWN_ERROR),
url_request_context_getter_(new net::TestURLRequestContextGetter(
task_environment_.GetMainThreadTaskRunner())) {}
: last_event_(NONE), last_result_(GCMClient::UNKNOWN_ERROR) {}

GCMClientImplTest::~GCMClientImplTest() {}

Expand All @@ -470,7 +457,6 @@ void GCMClientImplTest::SetUp() {
BuildGCMClient(base::TimeDelta());
InitializeGCMClient();
StartGCMClient();
SetUpUrlFetcherFactory();
InitializeInvalidationFieldTrial();
ASSERT_NO_FATAL_FAILURE(
CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken, std::string(),
Expand All @@ -480,10 +466,6 @@ void GCMClientImplTest::SetUp() {
void GCMClientImplTest::TearDown() {
}

void GCMClientImplTest::SetUpUrlFetcherFactory() {
url_fetcher_factory_.set_remove_fetcher_on_delete(true);
}

void GCMClientImplTest::SetFeatureParams(const base::Feature& feature,
const base::FieldTrialParams& params) {
scoped_feature_list_.InitAndEnableFeatureWithParameters(feature, params);
Expand Down Expand Up @@ -1422,7 +1404,6 @@ void GCMClientImplStartAndStopTest::SetUp() {
}

void GCMClientImplStartAndStopTest::DefaultCompleteCheckin() {
SetUpUrlFetcherFactory();
ASSERT_NO_FATAL_FAILURE(
CompleteCheckin(kDeviceAndroidId, kDeviceSecurityToken, std::string(),
std::map<std::string, std::string>()));
Expand Down
4 changes: 0 additions & 4 deletions ios/chrome/browser/prerender/preload_controller_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/prerender/preload_controller.h"
#include "ios/web/public/test/web_task_environment.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/platform_test.h"

Expand Down Expand Up @@ -60,8 +59,6 @@ void SetUp() override {
// cellular connection.
network_change_notifier_.reset(new TestNetworkChangeNotifier);

test_url_fetcher_factory_.reset(new net::TestURLFetcherFactory());

controller_ = [[PreloadController alloc]
initWithBrowserState:chrome_browser_state_.get()];
}
Expand Down Expand Up @@ -101,7 +98,6 @@ void SimulateCellularConnection() {
web::WebTaskEnvironment task_environment_;
std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
std::unique_ptr<TestNetworkChangeNotifier> network_change_notifier_;
std::unique_ptr<net::TestURLFetcherFactory> test_url_fetcher_factory_;
PreloadController* controller_;
};

Expand Down
4 changes: 0 additions & 4 deletions ios/chrome/browser/ui/open_in/open_in_controller_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#import "ios/chrome/browser/ui/open_in/open_in_controller_testing.h"
#import "ios/web/public/test/fakes/test_web_state.h"
#include "ios/web/public/test/test_web_thread.h"
#include "net/url_request/test_url_fetcher_factory.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/platform_test.h"
Expand Down Expand Up @@ -78,7 +76,6 @@ void SetUp() override {
scoped_refptr<network::SharedURLLoaderFactory>
test_shared_url_loader_factory_;

net::TestURLFetcherFactory factory_;
OpenInController* open_in_controller_;
UIView* parent_view_;
base::HistogramTester histogram_tester_;
Expand All @@ -98,7 +95,6 @@ void SetUp() override {

auto* pending_request = test_url_loader_factory_.GetPendingRequest(0);
ASSERT_TRUE(pending_request);
// Set the response for the set URLFetcher to be a blank PDF.
std::string pdf_str = CreatePdfString();
test_url_loader_factory_.SimulateResponseForPendingRequest(
pending_request->request.url.spec(), pdf_str);
Expand Down
56 changes: 1 addition & 55 deletions net/url_request/test_url_fetcher_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ ScopedURLFetcherFactory::~ScopedURLFetcherFactory() {
}

TestURLFetcher::TestURLFetcher(int id, const GURL& url, URLFetcherDelegate* d)
: owner_(nullptr),
id_(id),
: id_(id),
original_url_(url),
delegate_(d),
delegate_for_tests_(nullptr),
Expand All @@ -61,8 +60,6 @@ TestURLFetcher::TestURLFetcher(int id, const GURL& url, URLFetcherDelegate* d)
TestURLFetcher::~TestURLFetcher() {
if (delegate_for_tests_)
delegate_for_tests_->OnRequestEnd(id_);
if (owner_)
owner_->RemoveFetcherFromMap(id_);
}

void TestURLFetcher::SetUploadData(const std::string& upload_content_type,
Expand Down Expand Up @@ -317,43 +314,6 @@ void TestURLFetcher::SetResponseFilePath(const base::FilePath& path) {
fake_response_file_path_ = path;
}

TestURLFetcherFactory::TestURLFetcherFactory()
: ScopedURLFetcherFactory(this),
delegate_for_tests_(nullptr),
remove_fetcher_on_delete_(false) {}

TestURLFetcherFactory::~TestURLFetcherFactory() = default;

std::unique_ptr<URLFetcher> TestURLFetcherFactory::CreateURLFetcher(
int id,
const GURL& url,
URLFetcher::RequestType request_type,
URLFetcherDelegate* d,
NetworkTrafficAnnotationTag traffic_annotation) {
TestURLFetcher* fetcher = new TestURLFetcher(id, url, d);
if (remove_fetcher_on_delete_)
fetcher->set_owner(this);
fetcher->SetDelegateForTests(delegate_for_tests_);
fetchers_[id] = fetcher;
return std::unique_ptr<URLFetcher>(fetcher);
}

TestURLFetcher* TestURLFetcherFactory::GetFetcherByID(int id) const {
auto i = fetchers_.find(id);
return i == fetchers_.end() ? NULL : i->second;
}

void TestURLFetcherFactory::RemoveFetcherFromMap(int id) {
auto i = fetchers_.find(id);
DCHECK(i != fetchers_.end());
fetchers_.erase(i);
}

void TestURLFetcherFactory::SetDelegateForTests(
TestURLFetcherDelegateForTests* delegate_for_tests) {
delegate_for_tests_ = delegate_for_tests;
}

FakeURLFetcher::FakeURLFetcher(const GURL& url,
URLFetcherDelegate* d,
const std::string& response_data,
Expand Down Expand Up @@ -474,18 +434,4 @@ void FakeURLFetcherFactory::ClearFakeResponses() {
fake_responses_.clear();
}

URLFetcherImplFactory::URLFetcherImplFactory() = default;

URLFetcherImplFactory::~URLFetcherImplFactory() = default;

std::unique_ptr<URLFetcher> URLFetcherImplFactory::CreateURLFetcher(
int id,
const GURL& url,
URLFetcher::RequestType request_type,
URLFetcherDelegate* d,
NetworkTrafficAnnotationTag traffic_annotation) {
return std::unique_ptr<URLFetcher>(
new URLFetcherImpl(url, request_type, d, traffic_annotation));
}

} // namespace net
61 changes: 0 additions & 61 deletions net/url_request/test_url_fetcher_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ class TestURLFetcher : public URLFetcher {

void GetExtraRequestHeaders(HttpRequestHeaders* headers) const;

// Sets owner of this class. Set it to a non-NULL value if you want
// to automatically unregister this fetcher from the owning factory
// upon destruction.
void set_owner(TestURLFetcherFactory* owner) { owner_ = owner; }

// Unique ID in our factory.
int id() const { return id_; }

Expand Down Expand Up @@ -210,7 +205,6 @@ class TestURLFetcher : public URLFetcher {
TEMP_FILE // Write to a temp file
};

TestURLFetcherFactory* owner_;
const int id_;
const GURL original_url_;
URLFetcherDelegate* delegate_;
Expand Down Expand Up @@ -245,43 +239,6 @@ class TestURLFetcher : public URLFetcher {
DISALLOW_COPY_AND_ASSIGN(TestURLFetcher);
};

typedef TestURLFetcher::DelegateForTests TestURLFetcherDelegateForTests;

// Simple URLFetcherFactory method that creates TestURLFetchers. All fetchers
// are registered in a map by the id passed to the create method.
// Optionally, a fetcher may be automatically unregistered from the map upon
// its destruction.
class TestURLFetcherFactory : public URLFetcherFactory,
public ScopedURLFetcherFactory {
public:
TestURLFetcherFactory();
~TestURLFetcherFactory() override;

std::unique_ptr<URLFetcher> CreateURLFetcher(
int id,
const GURL& url,
URLFetcher::RequestType request_type,
URLFetcherDelegate* d,
NetworkTrafficAnnotationTag traffic_annotation) override;
TestURLFetcher* GetFetcherByID(int id) const;
void RemoveFetcherFromMap(int id);
void SetDelegateForTests(TestURLFetcherDelegateForTests* delegate_for_tests);
void set_remove_fetcher_on_delete(bool remove_fetcher_on_delete) {
remove_fetcher_on_delete_ = remove_fetcher_on_delete;
}

private:
// Maps from id passed to create to the returned URLFetcher.
typedef std::map<int, TestURLFetcher*> Fetchers;
Fetchers fetchers_;
TestURLFetcherDelegateForTests* delegate_for_tests_;
// Whether to automatically unregister a fetcher from this factory upon its
// destruction, false by default.
bool remove_fetcher_on_delete_;

DISALLOW_COPY_AND_ASSIGN(TestURLFetcherFactory);
};

// The FakeURLFetcher and FakeURLFetcherFactory classes are similar to the
// ones above but don't require you to know when exactly the URLFetcher objects
// will be created.
Expand Down Expand Up @@ -464,24 +421,6 @@ class FakeURLFetcherFactory : public URLFetcherFactory,
DISALLOW_COPY_AND_ASSIGN(FakeURLFetcherFactory);
};

// This is an implementation of URLFetcherFactory that will create a
// URLFetcherImpl. It can be use in conjunction with a FakeURLFetcherFactory in
// integration tests to control the behavior of some requests but execute
// all the other ones.
class URLFetcherImplFactory : public URLFetcherFactory {
public:
URLFetcherImplFactory();
~URLFetcherImplFactory() override;

// This method will create a real URLFetcher.
std::unique_ptr<URLFetcher> CreateURLFetcher(
int id,
const GURL& url,
URLFetcher::RequestType request_type,
URLFetcherDelegate* d,
NetworkTrafficAnnotationTag traffic_annotation) override;
};

} // namespace net

#endif // NET_URL_REQUEST_TEST_URL_FETCHER_FACTORY_H_
Loading

0 comments on commit 9d04509

Please sign in to comment.