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

Unified Diff: content/network/network_service_unittest.cc

Issue 2962693002: NetworkService: Destroy NetworkContexts on NetworkService teardown. (Closed)
Patch Set: Fix a couple comments 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/network_service.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/network/network_service_unittest.cc
diff --git a/content/network/network_service_unittest.cc b/content/network/network_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4897e121b70781ebc2404ddb6a96ac1878e89117
--- /dev/null
+++ b/content/network/network_service_unittest.cc
@@ -0,0 +1,68 @@
+// Copyright 2017 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 <memory>
+
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "content/common/network_service.mojom.h"
+#include "content/network/network_context.h"
+#include "content/network/network_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+namespace {
+
+class NetworkServiceTest : public testing::Test {
+ public:
+ NetworkServiceTest() : service_(NetworkService::CreateForTesting()) {}
+ ~NetworkServiceTest() override {}
+
+ NetworkService* service() const { return service_.get(); }
+
+ void DestroyService() { service_.reset(); }
+
+ private:
+ base::MessageLoopForIO message_loop_;
+ std::unique_ptr<NetworkService> service_;
+};
+
+// Test shutdown in the case a NetworkContext is destroyed before the
+// NetworkService.
+TEST_F(NetworkServiceTest, CreateAndDestroyContext) {
+ mojom::NetworkContextPtr network_context;
+ mojom::NetworkContextParamsPtr context_params =
+ mojom::NetworkContextParams::New();
+
+ service()->CreateNetworkContext(mojo::MakeRequest(&network_context),
+ std::move(context_params));
+ network_context.reset();
+ // Make sure the NetworkContext is destroyed.
+ base::RunLoop().RunUntilIdle();
+}
+
+// Test shutdown in the case there is still a live NetworkContext when the
+// NetworkService is destroyed. The service should destroy the NetworkContext
+// itself.
+TEST_F(NetworkServiceTest, DestroyingServiceDestroysContext) {
+ mojom::NetworkContextPtr network_context;
+ mojom::NetworkContextParamsPtr context_params =
+ mojom::NetworkContextParams::New();
+
+ service()->CreateNetworkContext(mojo::MakeRequest(&network_context),
+ std::move(context_params));
+ base::RunLoop run_loop;
+ network_context.set_connection_error_handler(run_loop.QuitClosure());
+ DestroyService();
+
+ // Destroying the service should destroy the context, causing a connection
+ // error.
+ run_loop.Run();
+}
+
+} // namespace
+
+} // namespace content
« no previous file with comments | « content/network/network_service.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698