summaryrefslogtreecommitdiffstats
path: root/content/renderer/renderer_webkitplatformsupport_impl.cc
diff options
context:
space:
mode:
authortimvolodine@chromium.org <timvolodine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-03 22:30:26 +0000
committertimvolodine@chromium.org <timvolodine@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-03 22:30:26 +0000
commitde7c9e700105e4a395897643a5c836c3b451c295 (patch)
tree550d4ae38918a93bb91542cc777bae33bef93851 /content/renderer/renderer_webkitplatformsupport_impl.cc
parentff200183d43aa15ee91dd9bb428f88c5a1119493 (diff)
downloadchromium_src-de7c9e700105e4a395897643a5c836c3b451c295.zip
chromium_src-de7c9e700105e4a395897643a5c836c3b451c295.tar.gz
chromium_src-de7c9e700105e4a395897643a5c836c3b451c295.tar.bz2
Battery Status API: add testing support for LayoutTests.
Adds plumbing to make it possible to test the blink implementation of the Battery Status API using LayoutTests and TestRunner. In test mode a fake battery status dispatcher is used to allow manual triggering of battery status changes using TestRunner.didChangeBatteryStatus method. BUG=122593, 360068 Review URL: https://codereview.chromium.org/298263002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274652 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/renderer_webkitplatformsupport_impl.cc')
-rw-r--r--content/renderer/renderer_webkitplatformsupport_impl.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index 433cca1..5f9f398 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