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

Unified Diff: device/wake_lock/wake_lock_provider.cc

Issue 2883903002: Add service unittest for WakeLockServiceImpl. (Closed)
Patch Set: Add FakeWakeLockServiceImpl. Created 3 years, 7 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
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

Powered by Google App Engine
This is Rietveld 408576698