blob: 0e30eb95441f0d7b39cea8f4ea9b4d47f92fe651 [file] [log] [blame]
// 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 "services/device/device_service_test_base.h"
#include <memory>
#include "base/bind.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/single_thread_task_runner.h"
#include "base/task/post_task.h"
#include "base/task/thread_pool.h"
#include "services/device/device_service.h"
#include "services/device/public/cpp/geolocation/location_provider.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_network_connection_tracker.h"
namespace device {
namespace {
// Simply return a nullptr which means no CustomLocationProvider from embedder.
std::unique_ptr<LocationProvider> GetCustomLocationProviderForTest() {
return nullptr;
}
std::unique_ptr<DeviceService> CreateTestDeviceService(
scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
mojo::PendingReceiver<mojom::DeviceService> receiver) {
#if defined(OS_ANDROID)
return CreateDeviceService(
file_task_runner, io_task_runner, url_loader_factory,
network::TestNetworkConnectionTracker::GetInstance(),
kTestGeolocationApiKey, false, WakeLockContextCallback(),
base::BindRepeating(&GetCustomLocationProviderForTest), nullptr,
std::move(receiver));
#else
return CreateDeviceService(
file_task_runner, io_task_runner, url_loader_factory,
network::TestNetworkConnectionTracker::GetInstance(),
kTestGeolocationApiKey,
base::BindRepeating(&GetCustomLocationProviderForTest),
std::move(receiver));
#endif
}
} // namespace
DeviceServiceTestBase::DeviceServiceTestBase()
: file_task_runner_(base::ThreadPool::CreateSingleThreadTaskRunner(
{base::MayBlock(), base::TaskPriority::BEST_EFFORT})),
io_task_runner_(base::ThreadPool::CreateSingleThreadTaskRunner(
{base::TaskPriority::USER_VISIBLE})),
network_connection_tracker_(
network::TestNetworkConnectionTracker::CreateInstance()) {}
DeviceServiceTestBase::~DeviceServiceTestBase() = default;
void DeviceServiceTestBase::SetUp() {
service_ = CreateTestDeviceService(
file_task_runner_, io_task_runner_,
base::MakeRefCounted<network::WeakWrapperSharedURLLoaderFactory>(
&test_url_loader_factory_),
service_remote_.BindNewPipeAndPassReceiver());
}
void DeviceServiceTestBase::DestroyDeviceService() {
service_.reset();
}
} // namespace device