Index: device/wake_lock/wake_lock_provider.cc |
diff --git a/device/wake_lock/wake_lock_provider.cc b/device/wake_lock/wake_lock_provider.cc |
index bbd4922fd998784cc2f43a77b626944bc547a895..dcda701b8431de190fc4afc925059c8b8ce286c9 100644 |
--- a/device/wake_lock/wake_lock_provider.cc |
+++ b/device/wake_lock/wake_lock_provider.cc |
@@ -6,11 +6,14 @@ |
#include <utility> |
+#include "device/wake_lock/fake_wake_lock_service_impl.h" |
#include "device/wake_lock/wake_lock_service_impl.h" |
#include "mojo/public/cpp/bindings/strong_binding.h" |
namespace device { |
+bool WakeLockProvider::is_in_service_unittest_ = false; |
+ |
// static |
void WakeLockProvider::Create( |
mojom::WakeLockProviderRequest request, |
@@ -44,10 +47,18 @@ void WakeLockProvider::GetWakeLockWithoutContext( |
mojom::WakeLockReason reason, |
const std::string& description, |
mojom::WakeLockServiceRequest request) { |
- // WakeLockServiceImpl owns itself. |
- new WakeLockServiceImpl(std::move(request), type, reason, description, |
- WakeLockServiceContext::WakeLockInvalidContextId, |
- native_view_getter_, file_task_runner_); |
+ if (is_in_service_unittest_) { |
+ // Create a fake WakeLockServiceImpl for testing. |
+ new FakeWakeLockServiceImpl( |
ke.he
2017/06/04 10:33:45
If we move the "WakeLockServiceImplForTesting" int
|
+ std::move(request), type, reason, description, |
+ WakeLockServiceContext::WakeLockInvalidContextId, native_view_getter_, |
+ file_task_runner_); |
+ } else { |
+ // WakeLockServiceImpl owns itself. |
+ new WakeLockServiceImpl(std::move(request), type, reason, description, |
+ WakeLockServiceContext::WakeLockInvalidContextId, |
+ native_view_getter_, file_task_runner_); |
+ } |
} |
} // namespace device |