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

Unified Diff: content/renderer/renderer_webkitplatformsupport_impl.cc

Issue 298263002: Battery Status API: add testing support for LayoutTests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments Created 6 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: content/renderer/renderer_webkitplatformsupport_impl.cc
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 433cca128460c80fe3c84eeac8fa56c3714c8fa0..5f9f398fc7633f3468c00d8925551f14be5ac084 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -38,6 +38,7 @@
#include "content/public/common/webplugininfo.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/battery_status/battery_status_dispatcher.h"
+#include "content/renderer/battery_status/fake_battery_status_dispatcher.h"
#include "content/renderer/device_sensors/device_motion_event_pump.h"
#include "content/renderer/device_sensors/device_orientation_event_pump.h"
#include "content/renderer/dom_storage/webstoragenamespace_impl.h"
@@ -151,6 +152,8 @@ base::LazyInstance<blink::WebDeviceOrientationData>::Leaky
g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<MockScreenOrientationController>::Leaky
g_test_screen_orientation_controller = LAZY_INSTANCE_INITIALIZER;
+base::LazyInstance<FakeBatteryStatusDispatcher>::Leaky
+ g_test_battery_status_dispatcher = LAZY_INSTANCE_INITIALIZER;
} // namespace
@@ -1189,6 +1192,15 @@ void RendererWebKitPlatformSupportImpl::queryStorageUsageAndQuota(
void RendererWebKitPlatformSupportImpl::setBatteryStatusListener(
blink::WebBatteryStatusListener* listener) {
+ if (RenderThreadImpl::current() &&
+ RenderThreadImpl::current()->layout_test_mode()) {
+ // If we are in test mode, we want to use a fake battery status dispatcher,
+ // which does not communicate with the browser process. Battery status
+ // changes are signalled by invoking MockBatteryStatusChangedForTesting().
+ g_test_battery_status_dispatcher.Get().SetListener(listener);
+ return;
+ }
+
if (!battery_status_dispatcher_) {
battery_status_dispatcher_.reset(
new BatteryStatusDispatcher(RenderThreadImpl::current()));
@@ -1196,4 +1208,10 @@ void RendererWebKitPlatformSupportImpl::setBatteryStatusListener(
battery_status_dispatcher_->SetListener(listener);
}
+// static
+void RendererWebKitPlatformSupportImpl::MockBatteryStatusChangedForTesting(
+ const blink::WebBatteryStatus& status) {
+ g_test_battery_status_dispatcher.Get().PostBatteryStatusChange(status);
+}
+
} // namespace content
« no previous file with comments | « content/renderer/renderer_webkitplatformsupport_impl.h ('k') | content/shell/renderer/test_runner/WebTestDelegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698