1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef SERVICES_DEVICE_DEVICE_SERVICE_TEST_BASE_H_
6 #define SERVICES_DEVICE_DEVICE_SERVICE_TEST_BASE_H_
8 #include "base/task/single_thread_task_runner.h"
9 #include "base/test/task_environment.h"
10 #include "build/build_config.h"
11 #include "mojo/public/cpp/bindings/remote.h"
12 #include "services/device/public/mojom/device_service.mojom.h"
13 #include "services/network/test/test_network_connection_tracker.h"
14 #include "services/network/test/test_url_loader_factory.h"
15 #include "testing/gtest/include/gtest/gtest.h"
20 class FakeGeolocationManager;
22 const char kTestGeolocationApiKey[] = "FakeApiKeyForTest";
24 // Base class responsible to setup Device Service for test.
25 class DeviceServiceTestBase : public testing::Test {
27 DeviceServiceTestBase();
29 DeviceServiceTestBase(const DeviceServiceTestBase&) = delete;
30 DeviceServiceTestBase& operator=(const DeviceServiceTestBase&) = delete;
32 ~DeviceServiceTestBase() override;
34 // NOTE: It's important to do service instantiation within SetUp instead of
35 // the constructor, as subclasses of this fixture may need to initialize some
36 // global state before the service is constructed.
37 void SetUp() override;
40 mojom::DeviceService* device_service() { return service_remote_.get(); }
41 DeviceService* device_service_impl() { return service_.get(); }
43 // Can optionally be called to destroy the service before a child test fixture
44 // shuts down, in case the DeviceService has dependencies on objects created
45 // by the child test fixture.
46 void DestroyDeviceService();
48 base::test::TaskEnvironment task_environment_;
50 // Both of these task runners should be deprecated in favor of individual
51 // components of the device service creating their own.
52 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_;
53 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
55 #if BUILDFLAG(IS_APPLE)
56 std::unique_ptr<FakeGeolocationManager> fake_geolocation_manager_;
59 network::TestURLLoaderFactory test_url_loader_factory_;
62 std::unique_ptr<network::TestNetworkConnectionTracker>
63 network_connection_tracker_;
64 std::unique_ptr<DeviceService> service_;
65 mojo::Remote<mojom::DeviceService> service_remote_;
70 #endif // SERVICES_DEVICE_DEVICE_SERVICE_TEST_BASE_H_