Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Unified Diff: content/network/url_loader_unittest.cc

Issue 2951293002: NetworkService: Destroy URLLoaders when a NetworkContext is destroyed. (Closed)
Patch Set: Response to comment, change why destruction is safe Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/network/url_loader_impl.cc ('k') | net/test/embedded_test_server/default_handlers.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/network/url_loader_unittest.cc
diff --git a/content/network/url_loader_unittest.cc b/content/network/url_loader_unittest.cc
index b2021eb0e58547c50756b8f3732f031417fc469c..0612ee3dec792cc83387523318b440a24f60a885 100644
--- a/content/network/url_loader_unittest.cc
+++ b/content/network/url_loader_unittest.cc
@@ -70,7 +70,7 @@ class URLLoaderImplTest : public testing::Test {
~URLLoaderImplTest() override {}
void SetUp() override {
- test_server_.ServeFilesFromSourceDirectory(
+ test_server_.AddDefaultHandlers(
base::FilePath(FILE_PATH_LITERAL("content/test/data")));
ASSERT_TRUE(test_server_.Start());
}
@@ -112,6 +112,7 @@ class URLLoaderImplTest : public testing::Test {
net::EmbeddedTestServer* test_server() { return &test_server_; }
NetworkContext* context() { return context_.get(); }
+ void DestroyContext() { context_.reset(); }
private:
base::MessageLoopForIO message_loop_;
@@ -155,4 +156,36 @@ TEST_F(URLLoaderImplTest, SSLSentOnlyWhenRequested) {
ASSERT_FALSE(!!client.ssl_info());
}
+TEST_F(URLLoaderImplTest, DestroyContextWithLiveRequest) {
+ TestURLLoaderClient client;
+ GURL url = test_server()->GetURL("/hung-after-headers");
+ ResourceRequest request =
+ CreateResourceRequest("GET", RESOURCE_TYPE_MAIN_FRAME, url);
+
+ mojom::URLLoaderAssociatedPtr loader;
+ // The loader is implicitly owned by the client and the NetworkContext, so
+ // don't hold on to a pointer to it.
+ base::WeakPtr<URLLoaderImpl> loader_impl =
+ (new URLLoaderImpl(context(), mojo::MakeIsolatedRequest(&loader), 0,
+ request, client.CreateInterfacePtr(),
+ TRAFFIC_ANNOTATION_FOR_TESTS))
+ ->GetWeakPtrForTests();
+
+ client.RunUntilResponseReceived();
+ EXPECT_TRUE(client.has_received_response());
+ EXPECT_FALSE(client.has_received_completion());
+
+ // Request hasn't completed, so the loader should not have been destroyed.
+ EXPECT_TRUE(loader_impl);
+
+ // Destroying the context should result in destroying the loader and the
+ // client receiving a connection error.
+ DestroyContext();
+ EXPECT_FALSE(loader_impl);
+
+ client.RunUntilConnectionError();
+ EXPECT_FALSE(client.has_received_completion());
+ EXPECT_EQ(0u, client.download_data_length());
+}
+
} // namespace content
« no previous file with comments | « content/network/url_loader_impl.cc ('k') | net/test/embedded_test_server/default_handlers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698