Index: content/shell/renderer/test_runner/mock_screen_orientation_controller.cc |
diff --git a/content/shell/renderer/test_runner/mock_screen_orientation_controller.cc b/content/shell/renderer/test_runner/mock_screen_orientation_controller.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e00c1d11b1a96a00ef84b38fe1a64491858fe311 |
--- /dev/null |
+++ b/content/shell/renderer/test_runner/mock_screen_orientation_controller.cc |
@@ -0,0 +1,147 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/shell/renderer/test_runner/mock_screen_orientation_controller.h" |
+ |
+#include "base/bind.h" |
+#include "base/logging.h" |
+#include "base/message_loop/message_loop.h" |
+#include "content/renderer/render_view_impl.h" |
+ |
+namespace content { |
+ |
+MockScreenOrientationController::MockScreenOrientationController() |
+ : render_view_(NULL), |
+ current_lock_(blink::WebScreenOrientationLockDefault), |
+ device_orientation_(blink::WebScreenOrientationPortraitPrimary), |
+ current_orientation_(blink::WebScreenOrientationPortraitPrimary) { |
+} |
+ |
+MockScreenOrientationController::~MockScreenOrientationController() { |
+} |
+ |
+void MockScreenOrientationController::ResetData() { |
+ current_lock_ = blink::WebScreenOrientationLockDefault; |
+ device_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
+ current_orientation_ = blink::WebScreenOrientationPortraitPrimary; |
+} |
+ |
+void MockScreenOrientationController::UpdateDeviceOrientation( |
+ RenderView* render_view, |
+ blink::WebScreenOrientationType orientation) { |
+ render_view_ = render_view; |
+ if (device_orientation_ == orientation) |
+ return; |
+ device_orientation_ = orientation; |
+ if (!IsOrientationAllowedByCurrentLock(orientation)) |
+ return; |
+ UpdateScreenOrientation(orientation); |
+} |
+ |
+void MockScreenOrientationController::UpdateScreenOrientation( |
+ blink::WebScreenOrientationType orientation) { |
+ if (current_orientation_ == orientation) |
+ return; |
+ current_orientation_ = orientation; |
+ if (render_view_) |
+ static_cast<RenderViewImpl*>(render_view_) |
Inactive
2014/06/17 17:29:04
This is a layering violation. I don't know how to
mlamouri (slow - plz ping)
2014/06/18 13:47:42
We could from the test_runner.cc notify the WebVie
|
+ ->SetScreenOrientationForTesting(orientation); |
+} |
+ |
+bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( |
+ blink::WebScreenOrientationType orientation) { |
+ if (current_lock_ == blink::WebScreenOrientationLockDefault || |
+ current_lock_ == blink::WebScreenOrientationLockAny) { |
+ return true; |
+ } |
+ |
+ switch (orientation) { |
+ case blink::WebScreenOrientationPortraitPrimary: |
+ return current_lock_ == blink::WebScreenOrientationLockPortraitPrimary || |
+ current_lock_ == blink::WebScreenOrientationLockPortrait; |
+ case blink::WebScreenOrientationPortraitSecondary: |
+ return current_lock_ == |
+ blink::WebScreenOrientationLockPortraitSecondary || |
+ current_lock_ == blink::WebScreenOrientationLockPortrait; |
+ case blink::WebScreenOrientationLandscapePrimary: |
+ return current_lock_ == blink::WebScreenOrientationLockLandscapePrimary || |
+ current_lock_ == blink::WebScreenOrientationLockLandscape; |
+ case blink::WebScreenOrientationLandscapeSecondary: |
+ return current_lock_ == |
+ blink::WebScreenOrientationLockLandscapeSecondary || |
+ current_lock_ == blink::WebScreenOrientationLockLandscape; |
+ default: |
+ return false; |
+ } |
+} |
+ |
+void MockScreenOrientationController::lockOrientation( |
+ blink::WebScreenOrientationLockType orientation, |
+ blink::WebLockOrientationCallback* callback) { |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&MockScreenOrientationController::UpdateLockSync, |
+ base::Unretained(this), |
+ orientation, |
+ callback)); |
+} |
+ |
+void MockScreenOrientationController::unlockOrientation() { |
+ base::MessageLoop::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&MockScreenOrientationController::ResetLockSync, |
+ base::Unretained(this))); |
+} |
+ |
+void MockScreenOrientationController::UpdateLockSync( |
+ blink::WebScreenOrientationLockType lock, |
+ blink::WebLockOrientationCallback* callback) { |
+ DCHECK(lock != blink::WebScreenOrientationLockDefault); |
+ current_lock_ = lock; |
+ if (!IsOrientationAllowedByCurrentLock(current_orientation_)) |
+ UpdateScreenOrientation(SuitableOrientationForCurrentLock()); |
+ // FIXME(ostap): This relationship between orientationType and |
+ // orientationAngle is temporary. The test should be able to specify |
+ // the angle in addition to the orientation type. |
+ unsigned angle; |
+ switch (current_orientation_) { |
+ case blink::WebScreenOrientationLandscapePrimary: |
+ angle = 90; |
+ break; |
+ case blink::WebScreenOrientationLandscapeSecondary: |
+ angle = -90; |
mlamouri (slow - plz ping)
2014/06/18 13:47:42
Do not return negative values, please. This should
|
+ break; |
+ case blink::WebScreenOrientationPortraitSecondary: |
+ angle = 180; |
+ break; |
+ default: |
+ angle = 0; |
+ } |
+ callback->onSuccess(angle, current_orientation_); |
+} |
+ |
+void MockScreenOrientationController::ResetLockSync() { |
+ bool will_screen_orientation_need_updating = |
+ !IsOrientationAllowedByCurrentLock(device_orientation_); |
+ current_lock_ = blink::WebScreenOrientationLockDefault; |
+ if (will_screen_orientation_need_updating) |
+ UpdateScreenOrientation(device_orientation_); |
+} |
+ |
+blink::WebScreenOrientationType |
+MockScreenOrientationController::SuitableOrientationForCurrentLock() { |
+ switch (current_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; |
+ } |
+} |
+ |
+} // namespace content |