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

Unified Diff: content/renderer/renderer_webkitplatformsupport_impl.cc

Issue 268673015: Support screen.lockOrientation() / screen.unlockOrientation() when running layout tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix coding style 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/renderer_webkitplatformsupport_impl.cc
diff --git a/content/renderer/renderer_webkitplatformsupport_impl.cc b/content/renderer/renderer_webkitplatformsupport_impl.cc
index b507a732a1eacb48b0ecdf3cac6f32fa3f736a22..89bf7d86fcd6b2df510784ac88d9952f9d79e8cc 100644
--- a/content/renderer/renderer_webkitplatformsupport_impl.cc
+++ b/content/renderer/renderer_webkitplatformsupport_impl.cc
@@ -145,6 +145,12 @@ base::LazyInstance<blink::WebDeviceMotionData>::Leaky
g_test_device_motion_data = LAZY_INSTANCE_INITIALIZER;
base::LazyInstance<blink::WebDeviceOrientationData>::Leaky
g_test_device_orientation_data = LAZY_INSTANCE_INITIALIZER;
+static blink::WebScreenOrientationLockType g_test_current_screen_lock =
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 i'd rather not have so many variables here. Is it
+ blink::WebScreenOrientationLockDefault;
+static blink::WebScreenOrientationType g_test_device_screen_orientation =
+ blink::WebScreenOrientationPortraitPrimary;
+static blink::WebScreenOrientationType g_test_current_screen_orientation =
+ blink::WebScreenOrientationPortraitPrimary;
static blink::WebScreenOrientationListener*
g_test_screen_orientation_listener = NULL;
@@ -1138,10 +1144,79 @@ void RendererWebKitPlatformSupportImpl::setScreenOrientationListener(
screen_orientation_dispatcher_->setListener(listener);
}
+namespace {
+
+bool isScreenOrientationAllowedByTestingLock(
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 methods should start with capital letters
Inactive 2014/05/07 18:41:05 Done.
+ blink::WebScreenOrientationType orientation) {
+ if (g_test_current_screen_lock == blink::WebScreenOrientationLockDefault ||
+ g_test_current_screen_lock == blink::WebScreenOrientationLockAny)
+ return true;
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 nit { } since the if part is multiline
Inactive 2014/05/07 18:41:05 Done.
+
+ switch (orientation) {
+ case blink::WebScreenOrientationPortraitPrimary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortraitPrimary ||
+ g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortrait;
+ case blink::WebScreenOrientationPortraitSecondary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortraitSecondary ||
+ g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockPortrait;
+ case blink::WebScreenOrientationLandscapePrimary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscapePrimary ||
+ g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscape;
+ case blink::WebScreenOrientationLandscapeSecondary:
+ return g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscapeSecondary ||
+ g_test_current_screen_lock ==
+ blink::WebScreenOrientationLockLandscape;
+ default:
+ return false;
+ }
+}
+
+blink::WebScreenOrientationType suitableScreenOrientationForTestingLock() {
+ switch (g_test_current_screen_lock) {
+ case blink::WebScreenOrientationLockPortraitSecondary:
+ return blink::WebScreenOrientationPortraitSecondary;
+ case blink::WebScreenOrientationLockLandscapePrimary:
+ case blink::WebScreenOrientationLockLandscape:
+ return blink::WebScreenOrientationLandscapePrimary;
+ case blink::WebScreenOrientationLockLandscapeSecondary:
+ return blink::WebScreenOrientationLandscapePrimary;
+ default:
+ return blink::WebScreenOrientationPortraitPrimary;
+ }
+}
+
+void updateScreenOrientationForTesting(
+ blink::WebScreenOrientationType orientation) {
+ if (orientation == g_test_current_screen_orientation)
+ return;
+ g_test_current_screen_orientation = orientation;
+ if (g_test_screen_orientation_listener)
+ g_test_screen_orientation_listener->didChangeScreenOrientation(orientation);
+}
+
+} // namespace
+
void RendererWebKitPlatformSupportImpl::lockOrientation(
blink::WebScreenOrientationLockType orientation) {
if (RenderThreadImpl::current() &&
RenderThreadImpl::current()->layout_test_mode()) {
+ g_test_current_screen_lock = orientation;
+ if (!isScreenOrientationAllowedByTestingLock(
+ g_test_current_screen_orientation)) {
+ g_test_current_screen_orientation =
+ suitableScreenOrientationForTestingLock();
+ if (g_test_screen_orientation_listener) {
+ g_test_screen_orientation_listener->didChangeScreenOrientation(
+ g_test_current_screen_orientation);
+ }
+ }
return;
}
RenderThread::Get()->Send(new ScreenOrientationHostMsg_Lock(orientation));
@@ -1150,6 +1225,12 @@ void RendererWebKitPlatformSupportImpl::lockOrientation(
void RendererWebKitPlatformSupportImpl::unlockOrientation() {
if (RenderThreadImpl::current() &&
RenderThreadImpl::current()->layout_test_mode()) {
+ bool should_update_current_screen_orientation =
+ !isScreenOrientationAllowedByTestingLock(
+ g_test_device_screen_orientation);
+ g_test_current_screen_lock = blink::WebScreenOrientationLockDefault;
+ if (should_update_current_screen_orientation)
+ updateScreenOrientationForTesting(g_test_device_screen_orientation);
return;
}
RenderThread::Get()->Send(new ScreenOrientationHostMsg_Unlock);
@@ -1158,9 +1239,10 @@ void RendererWebKitPlatformSupportImpl::unlockOrientation() {
// static
void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting(
blink::WebScreenOrientationType orientation) {
- if (!g_test_screen_orientation_listener)
+ g_test_device_screen_orientation = orientation;
+ if (!isScreenOrientationAllowedByTestingLock(orientation))
jochen (gone - plz use gerrit) 2014/05/07 06:48:41 what happens if a test fails before it unlocks?
Inactive 2014/05/07 18:41:05 Flakes :) I added a ResetMockScreenOrientationForT
return;
- g_test_screen_orientation_listener->didChangeScreenOrientation(orientation);
+ updateScreenOrientationForTesting(g_test_device_screen_orientation);
}
//------------------------------------------------------------------------------
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698