Commit 48c47586 authored by Kinuko Yasuda's avatar Kinuko Yasuda Committed by Commit Bot

Remove some non-NetworkService code in NavigationURLLoaderTest

Also remove some dead code in BrowserContext.

Bug: 934009
Change-Id: I015a1b65086f28304a6f0b0ff36f4341b709b9db
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1723930
Auto-Submit: Kinuko Yasuda <kinuko@chromium.org>
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681810}
parent b5b25aa3
...@@ -64,7 +64,6 @@ ...@@ -64,7 +64,6 @@
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "net/cookies/cookie_store.h" #include "net/cookies/cookie_store.h"
#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_getter.h"
#include "services/content/public/mojom/constants.mojom.h" #include "services/content/public/mojom/constants.mojom.h"
#include "services/content/service.h" #include "services/content/service.h"
#include "services/file/file_service.h" #include "services/file/file_service.h"
...@@ -220,9 +219,7 @@ StoragePartition* GetStoragePartitionFromConfig( ...@@ -220,9 +219,7 @@ StoragePartition* GetStoragePartitionFromConfig(
can_create); can_create);
} }
void SaveSessionStateOnIOThread( void SaveSessionStateOnIOThread(AppCacheServiceImpl* appcache_service) {
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
AppCacheServiceImpl* appcache_service) {
appcache_service->set_force_keep_session_state(); appcache_service->set_force_keep_session_state();
} }
...@@ -604,12 +601,9 @@ void BrowserContext::SaveSessionState(BrowserContext* browser_context) { ...@@ -604,12 +601,9 @@ void BrowserContext::SaveSessionState(BrowserContext* browser_context) {
base::WrapRefCounted(database_tracker))); base::WrapRefCounted(database_tracker)));
if (BrowserThread::IsThreadInitialized(BrowserThread::IO)) { if (BrowserThread::IsThreadInitialized(BrowserThread::IO)) {
scoped_refptr<net::URLRequestContextGetter> context_getter;
if (!base::FeatureList::IsEnabled(network::features::kNetworkService))
context_getter = storage_partition->GetURLRequestContext();
base::PostTaskWithTraits( base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce(&SaveSessionStateOnIOThread, context_getter, base::BindOnce(&SaveSessionStateOnIOThread,
static_cast<AppCacheServiceImpl*>( static_cast<AppCacheServiceImpl*>(
storage_partition->GetAppCacheService()))); storage_partition->GetAppCacheService())));
} }
......
...@@ -133,8 +133,6 @@ class NavigationURLLoaderImplTest : public testing::Test { ...@@ -133,8 +133,6 @@ class NavigationURLLoaderImplTest : public testing::Test {
: thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
network_change_notifier_( network_change_notifier_(
net::test::MockNetworkChangeNotifier::Create()) { net::test::MockNetworkChangeNotifier::Create()) {
feature_list_.InitAndEnableFeature(network::features::kNetworkService);
// Because the network service is enabled we need a system Connector or // Because the network service is enabled we need a system Connector or
// BrowserContext::GetDefaultStoragePartition will segfault when // BrowserContext::GetDefaultStoragePartition will segfault when
// ContentBrowserClient::CreateNetworkContext tries to call // ContentBrowserClient::CreateNetworkContext tries to call
...@@ -296,7 +294,6 @@ class NavigationURLLoaderImplTest : public testing::Test { ...@@ -296,7 +294,6 @@ class NavigationURLLoaderImplTest : public testing::Test {
} }
protected: protected:
base::test::ScopedFeatureList feature_list_;
TestBrowserThreadBundle thread_bundle_; TestBrowserThreadBundle thread_bundle_;
std::unique_ptr<TestBrowserContext> browser_context_; std::unique_ptr<TestBrowserContext> browser_context_;
std::unique_ptr<net::test::MockNetworkChangeNotifier> std::unique_ptr<net::test::MockNetworkChangeNotifier>
......
...@@ -35,9 +35,6 @@ ...@@ -35,9 +35,6 @@
#include "net/traffic_annotation/network_traffic_annotation_test_helper.h" #include "net/traffic_annotation/network_traffic_annotation_test_helper.h"
#include "net/url_request/redirect_info.h" #include "net/url_request/redirect_info.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_test_job.h"
#include "net/url_request/url_request_test_util.h" #include "net/url_request/url_request_test_util.h"
#include "services/network/public/cpp/features.h" #include "services/network/public/cpp/features.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
...@@ -46,32 +43,13 @@ ...@@ -46,32 +43,13 @@
namespace content { namespace content {
namespace {
std::unique_ptr<ResourceHandler> CreateTestResourceHandler(
net::URLRequest* request) {
return std::make_unique<TestResourceHandler>();
}
} // namespace
class NavigationURLLoaderTest : public testing::Test { class NavigationURLLoaderTest : public testing::Test {
public: public:
NavigationURLLoaderTest() NavigationURLLoaderTest()
: thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP), : thread_bundle_(TestBrowserThreadBundle::IO_MAINLOOP),
browser_context_(new TestBrowserContext), browser_context_(new TestBrowserContext) {
host_(base::BindRepeating(&CreateTestResourceHandler),
base::ThreadTaskRunnerHandle::Get(),
/* enable_resource_scheduler */ true) {
host_.SetLoaderDelegate(&loader_delegate_);
BrowserContext::EnsureResourceContextInitialized(browser_context_.get()); BrowserContext::EnsureResourceContextInitialized(browser_context_.get());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
net::URLRequestContext* request_context =
browser_context_->GetRequestContext()->GetURLRequestContext();
// Attach URLRequestTestJob.
job_factory_.SetProtocolHandler(
"test", net::URLRequestTestJob::CreateProtocolHandler());
request_context->set_job_factory(&job_factory_);
} }
std::unique_ptr<NavigationURLLoader> MakeTestLoader( std::unique_ptr<NavigationURLLoader> MakeTestLoader(
...@@ -113,27 +91,9 @@ class NavigationURLLoaderTest : public testing::Test { ...@@ -113,27 +91,9 @@ class NavigationURLLoaderTest : public testing::Test {
std::move(request_info), nullptr, nullptr, nullptr, nullptr, delegate); std::move(request_info), nullptr, nullptr, nullptr, nullptr, delegate);
} }
// Helper function for fetching the body of a URL to a string.
std::string FetchURL(const GURL& url) {
net::TestDelegate delegate;
net::URLRequestContext* request_context =
browser_context_->GetRequestContext()->GetURLRequestContext();
std::unique_ptr<net::URLRequest> request(request_context->CreateRequest(
url, net::DEFAULT_PRIORITY, &delegate, TRAFFIC_ANNOTATION_FOR_TESTS));
request->Start();
base::RunLoop().Run();
EXPECT_TRUE(request->status().is_success());
EXPECT_EQ(200, request->response_headers()->response_code());
return delegate.data_received();
}
protected: protected:
TestBrowserThreadBundle thread_bundle_; TestBrowserThreadBundle thread_bundle_;
net::URLRequestJobFactoryImpl job_factory_;
std::unique_ptr<TestBrowserContext> browser_context_; std::unique_ptr<TestBrowserContext> browser_context_;
LoaderDelegateImpl loader_delegate_;
ResourceDispatcherHostImpl host_;
}; };
// Tests that request failures are propagated correctly. // Tests that request failures are propagated correctly.
...@@ -185,20 +145,12 @@ TEST_F(NavigationURLLoaderTest, RequestFailedCertErrorFatal) { ...@@ -185,20 +145,12 @@ TEST_F(NavigationURLLoaderTest, RequestFailedCertErrorFatal) {
// Set HSTS for the test domain in order to make SSL errors fatal. // Set HSTS for the test domain in order to make SSL errors fatal.
base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000); base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1000);
bool include_subdomains = false; bool include_subdomains = false;
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) { auto* storage_partition =
auto* storage_partition = BrowserContext::GetDefaultStoragePartition(browser_context_.get());
BrowserContext::GetDefaultStoragePartition(browser_context_.get()); base::RunLoop run_loop;
base::RunLoop run_loop; storage_partition->GetNetworkContext()->AddHSTS(
storage_partition->GetNetworkContext()->AddHSTS( url.host(), expiry, include_subdomains, run_loop.QuitClosure());
url.host(), expiry, include_subdomains, run_loop.QuitClosure()); run_loop.Run();
run_loop.Run();
} else {
net::TransportSecurityState* transport_security_state =
browser_context_->GetRequestContext()
->GetURLRequestContext()
->transport_security_state();
transport_security_state->AddHSTS(url.host(), expiry, include_subdomains);
}
TestNavigationURLLoaderDelegate delegate; TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader = MakeTestLoader(url, &delegate); std::unique_ptr<NavigationURLLoader> loader = MakeTestLoader(url, &delegate);
...@@ -216,100 +168,4 @@ TEST_F(NavigationURLLoaderTest, RequestFailedCertErrorFatal) { ...@@ -216,100 +168,4 @@ TEST_F(NavigationURLLoaderTest, RequestFailedCertErrorFatal) {
EXPECT_EQ(1, delegate.on_request_handled_counter()); EXPECT_EQ(1, delegate.on_request_handled_counter());
} }
// Tests that the destroying the loader cancels the request.
TEST_F(NavigationURLLoaderTest, CancelOnDestruct) {
// Specific to non-NetworkService path.
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
return;
// Fake a top-level request. Choose a URL which redirects so the request can
// be paused before the response comes in.
TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader = MakeTestLoader(
net::URLRequestTestJob::test_url_redirect_to_url_2(), &delegate);
// Wait for the request to redirect.
delegate.WaitForRequestRedirected();
// Destroy the loader and verify that URLRequestTestJob no longer has anything
// paused.
loader.reset();
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage());
}
// Test that the delegate is not called if OnResponseStarted and destroying the
// loader race.
TEST_F(NavigationURLLoaderTest, CancelResponseRace) {
// Specific to non-NetworkService path.
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
return;
TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader = MakeTestLoader(
net::URLRequestTestJob::test_url_redirect_to_url_2(), &delegate);
// Wait for the request to redirect.
delegate.WaitForRequestRedirected();
// In the same event loop iteration, follow the redirect (allowing the
// response to go through) and destroy the loader.
loader->FollowRedirect({}, {}, PREVIEWS_OFF);
loader.reset();
// Verify the URLRequestTestJob no longer has anything paused and that no
// response body was received.
base::RunLoop().RunUntilIdle();
EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage());
EXPECT_FALSE(delegate.has_url_loader_client_endpoints());
}
// Tests that the loader may be canceled by context.
TEST_F(NavigationURLLoaderTest, CancelByContext) {
// Specific to non-NetworkService path.
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
return;
TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader = MakeTestLoader(
net::URLRequestTestJob::test_url_redirect_to_url_2(), &delegate);
// Wait for the request to redirect.
delegate.WaitForRequestRedirected();
// Cancel all requests.
host_.CancelRequestsForContext(browser_context_->GetResourceContext());
// Wait for the request to now be aborted.
delegate.WaitForRequestFailed();
EXPECT_EQ(net::ERR_ABORTED, delegate.net_error());
EXPECT_EQ(1, delegate.on_request_handled_counter());
}
// Tests that the request stays alive as long as the URLLoaderClient endpoints
// are not destructed.
TEST_F(NavigationURLLoaderTest, OwnedByHandle) {
// Specific to non-NetworkService path.
if (base::FeatureList::IsEnabled(network::features::kNetworkService))
return;
// Fake a top-level request to a URL whose body does not load immediately.
TestNavigationURLLoaderDelegate delegate;
std::unique_ptr<NavigationURLLoader> loader =
MakeTestLoader(net::URLRequestTestJob::test_url_2(), &delegate);
// Wait for the response to come back.
delegate.WaitForResponseStarted();
// Proceed with the response.
loader->ProceedWithResponse();
// Release the URLLoaderClient endpoints.
delegate.ReleaseURLLoaderClientEndpoints();
base::RunLoop().RunUntilIdle();
// Verify that URLRequestTestJob no longer has anything paused.
EXPECT_FALSE(net::URLRequestTestJob::ProcessOnePendingMessage());
}
} // namespace content } // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment