| 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
|
|
|