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

Unified Diff: services/device/device_service_test_base.cc

Issue 2812223006: Replace device_sensor browsertest by service unittest. (Closed)
Patch Set: eliminate "unreachable code" warning. Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/device/device_service_test_base.h ('k') | services/device/sensors/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/device/device_service_test_base.cc
diff --git a/services/device/device_service_test_base.cc b/services/device/device_service_test_base.cc
index 595f669d9ce93f35533c3786dc811853ea1bacf0..2314b682d7328c22af77e3fa4a060e5f558e418a 100644
--- a/services/device/device_service_test_base.cc
+++ b/services/device/device_service_test_base.cc
@@ -5,9 +5,8 @@
#include "services/device/device_service_test_base.h"
#include <memory>
-
#include "base/memory/ptr_util.h"
-#include "base/threading/thread.h"
+#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "services/device/device_service.h"
#include "services/device/public/interfaces/constants.mojom.h"
@@ -28,10 +27,12 @@ class ServiceTestClient : public service_manager::test::ServiceTestClient,
public service_manager::InterfaceFactory<
service_manager::mojom::ServiceFactory> {
public:
- explicit ServiceTestClient(service_manager::test::ServiceTest* test)
+ explicit ServiceTestClient(
+ service_manager::test::ServiceTest* test,
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
: service_manager::test::ServiceTestClient(test),
- io_thread_("DeviceServiceTestIOThread"),
- file_thread_("DeviceServiceTestFileThread") {
+ file_thread_("DeviceServiceTestFileThread"),
+ io_task_runner_(std::move(io_task_runner)) {
registry_.AddInterface<service_manager::mojom::ServiceFactory>(this);
}
~ServiceTestClient() override {}
@@ -47,18 +48,15 @@ class ServiceTestClient : public service_manager::test::ServiceTestClient,
void CreateService(service_manager::mojom::ServiceRequest request,
const std::string& name) override {
if (name == device::mojom::kServiceName) {
- io_thread_.Start();
file_thread_.Start();
#if defined(OS_ANDROID)
device_service_context_.reset(new service_manager::ServiceContext(
- CreateDeviceService(file_thread_.task_runner(),
- io_thread_.task_runner(),
+ CreateDeviceService(file_thread_.task_runner(), io_task_runner_,
wake_lock_context_callback_),
std::move(request)));
#else
device_service_context_.reset(new service_manager::ServiceContext(
- CreateDeviceService(file_thread_.task_runner(),
- io_thread_.task_runner()),
+ CreateDeviceService(file_thread_.task_runner(), io_task_runner_),
std::move(request)));
#endif
}
@@ -70,26 +68,38 @@ class ServiceTestClient : public service_manager::test::ServiceTestClient,
}
private:
- base::Thread io_thread_;
base::Thread file_thread_;
service_manager::BinderRegistry registry_;
mojo::BindingSet<service_manager::mojom::ServiceFactory>
service_factory_bindings_;
std::unique_ptr<service_manager::ServiceContext> device_service_context_;
+ scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_;
+
WakeLockContextCallback wake_lock_context_callback_;
};
} // namespace
DeviceServiceTestBase::DeviceServiceTestBase()
- : ServiceTest(kTestServiceName) {}
+ : ServiceTest(kTestServiceName), io_thread_("DeviceServiceTestIOThread") {}
DeviceServiceTestBase::~DeviceServiceTestBase() {}
std::unique_ptr<service_manager::Service>
DeviceServiceTestBase::CreateService() {
- return base::MakeUnique<ServiceTestClient>(this);
+ // Instead of starting a new IO thread, we use the main thread to simulate
+ // the IO thread. This is because there are some sub-services in device
+ // (DeviceSensorService, for example) which are type of
+ // base::Singleton<base::LeakySingletonTraits>, this means the singleton
+ // instance is never deleted. When all the service unit test cases run in
+ // same process the singleton service instance stays alive across multiple
+ // unit test cases. There are some thread_checkers in the singleton
+ // instance so we have to make sure passing the same IO thread to
+ // each test case. We use the main thread to provide this consistency.
+
+ return base::MakeUnique<ServiceTestClient>(
+ this, base::ThreadTaskRunnerHandle::Get());
}
} // namespace device
« no previous file with comments | « services/device/device_service_test_base.h ('k') | services/device/sensors/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698