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

Side by Side 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, 5 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 unified diff | Download patch
« no previous file with comments | « content/network/network_service.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <memory>
6
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "content/common/network_service.mojom.h"
11 #include "content/network/network_context.h"
12 #include "content/network/network_service.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace content {
16
17 namespace {
18
19 class NetworkServiceTest : public testing::Test {
20 public:
21 NetworkServiceTest() : service_(NetworkService::CreateForTesting()) {}
22 ~NetworkServiceTest() override {}
23
24 NetworkService* service() const { return service_.get(); }
25
26 void DestroyService() { service_.reset(); }
27
28 private:
29 base::MessageLoopForIO message_loop_;
30 std::unique_ptr<NetworkService> service_;
31 };
32
33 // Test shutdown in the case a NetworkContext is destroyed before the
34 // NetworkService.
35 TEST_F(NetworkServiceTest, CreateAndDestroyContext) {
36 mojom::NetworkContextPtr network_context;
37 mojom::NetworkContextParamsPtr context_params =
38 mojom::NetworkContextParams::New();
39
40 service()->CreateNetworkContext(mojo::MakeRequest(&network_context),
41 std::move(context_params));
42 network_context.reset();
43 // Make sure the NetworkContext is destroyed.
44 base::RunLoop().RunUntilIdle();
45 }
46
47 // Test shutdown in the case there is still a live NetworkContext when the
48 // NetworkService is destroyed. The service should destroy the NetworkContext
49 // itself.
50 TEST_F(NetworkServiceTest, DestroyingServiceDestroysContext) {
51 mojom::NetworkContextPtr network_context;
52 mojom::NetworkContextParamsPtr context_params =
53 mojom::NetworkContextParams::New();
54
55 service()->CreateNetworkContext(mojo::MakeRequest(&network_context),
56 std::move(context_params));
57 base::RunLoop run_loop;
58 network_context.set_connection_error_handler(run_loop.QuitClosure());
59 DestroyService();
60
61 // Destroying the service should destroy the context, causing a connection
62 // error.
63 run_loop.Run();
64 }
65
66 } // namespace
67
68 } // namespace content
OLDNEW
« 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