OLD | NEW |
(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/run_loop.h" |
| 8 #include "base/test/scoped_task_environment.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() |
| 22 : scoped_task_environment_( |
| 23 base::test::ScopedTaskEnvironment::MainThreadType::IO), |
| 24 service_(NetworkService::CreateForTesting()) {} |
| 25 ~NetworkServiceTest() override {} |
| 26 |
| 27 NetworkService* service() const { return service_.get(); } |
| 28 |
| 29 void DestroyService() { service_.reset(); } |
| 30 |
| 31 private: |
| 32 base::test::ScopedTaskEnvironment scoped_task_environment_; |
| 33 std::unique_ptr<NetworkService> service_; |
| 34 }; |
| 35 |
| 36 // Test shutdown in the case a NetworkContext is destroyed before the |
| 37 // NetworkService. |
| 38 TEST_F(NetworkServiceTest, CreateAndDestroyContext) { |
| 39 mojom::NetworkContextPtr network_context; |
| 40 mojom::NetworkContextParamsPtr context_params = |
| 41 mojom::NetworkContextParams::New(); |
| 42 |
| 43 service()->CreateNetworkContext(mojo::MakeRequest(&network_context), |
| 44 std::move(context_params)); |
| 45 network_context.reset(); |
| 46 // Make sure the NetworkContext is destroyed. |
| 47 base::RunLoop().RunUntilIdle(); |
| 48 } |
| 49 |
| 50 // Test shutdown in the case there is still a live NetworkContext when the |
| 51 // NetworkService is destroyed. The service should destroy the NetworkContext |
| 52 // itself. |
| 53 TEST_F(NetworkServiceTest, DestroyingServiceDestroysContext) { |
| 54 mojom::NetworkContextPtr network_context; |
| 55 mojom::NetworkContextParamsPtr context_params = |
| 56 mojom::NetworkContextParams::New(); |
| 57 |
| 58 service()->CreateNetworkContext(mojo::MakeRequest(&network_context), |
| 59 std::move(context_params)); |
| 60 base::RunLoop run_loop; |
| 61 network_context.set_connection_error_handler(run_loop.QuitClosure()); |
| 62 DestroyService(); |
| 63 |
| 64 // Destroying the service should destroy the context, causing a connection |
| 65 // error. |
| 66 run_loop.Run(); |
| 67 } |
| 68 |
| 69 } // namespace |
| 70 |
| 71 } // namespace content |
OLD | NEW |