Index: Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp |
diff --git a/Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp b/Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..48a0c1b08113e9d6bf141703ad13759e2a75a697 |
--- /dev/null |
+++ b/Source/modules/screen_orientation/testing/ScreenOrientationClientMock.cpp |
@@ -0,0 +1,91 @@ |
+// 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 "config.h" |
+#include "ScreenOrientationClientMock.h" |
+ |
+#include "modules/screen_orientation/ScreenOrientationController.h" |
+ |
+namespace WebCore { |
+ |
+ScreenOrientationClientMock::ScreenOrientationClientMock() |
+ : m_controllerTimer(this, &ScreenOrientationClientMock::controllerTimerFired) |
+ , m_controller(0) |
+ , m_orientation(OrientationPortraitPrimary) |
+ , m_lockedOrientations(OrientationAny) |
+{ |
+} |
+ |
+ScreenOrientationClientMock::~ScreenOrientationClientMock() |
+{ |
+} |
+ |
+void ScreenOrientationClientMock::setController(ScreenOrientationController* controller) |
+{ |
+ ASSERT(controller && !m_controller); |
+ m_controller = controller; |
+} |
+ |
+void ScreenOrientationClientMock::setScreenOrientation(ScreenOrientationValue orientation) |
+{ |
+ if (orientation == m_orientation) |
+ return; |
+ |
+ m_orientation = orientation; |
+ if (m_lockedOrientations & orientation) |
+ asyncUpdateController(); |
+} |
+ |
+void ScreenOrientationClientMock::asyncUpdateController() |
+{ |
+ ASSERT(m_controller); |
+ if (!m_controllerTimer.isActive()) |
+ m_controllerTimer.startOneShot(0); |
+} |
+ |
+void ScreenOrientationClientMock::controllerTimerFired(Timer<ScreenOrientationClientMock>* timer) |
+{ |
+ ASSERT_UNUSED(timer, timer == &m_controllerTimer); |
+ ASSERT(m_controller); |
+ |
+ m_controller->orientationChanged(m_orientation); |
+} |
+ |
+void ScreenOrientationClientMock::maybeUpdateOrientationAfterLocking() |
+{ |
+ if (m_orientation & m_lockedOrientations) |
+ return; |
+ |
+ // We need to change our current screen orientation to meet the locking requirements. |
+ ScreenOrientationValue supportedOrientationValues[] = { |
+ OrientationPortraitPrimary, |
+ OrientationLandscapePrimary, |
+ OrientationPortraitSecondary, |
+ OrientationLandscapeSecondary |
+ }; |
+ |
+ for (unsigned i = 0; i < WTF_ARRAY_LENGTH(supportedOrientationValues); ++i) { |
+ if (m_lockedOrientations & supportedOrientationValues[i]) { |
+ m_orientation = supportedOrientationValues[i]; |
+ asyncUpdateController(); |
+ return; |
+ } |
+ } |
+ ASSERT_NOT_REACHED(); |
+} |
+ |
+void ScreenOrientationClientMock::lockOrientation(ScreenOrientationValues orientations) |
+{ |
+ m_lockedOrientations = orientations; |
+ maybeUpdateOrientationAfterLocking(); |
+} |
+ |
+void ScreenOrientationClientMock::unlockOrientation() |
+{ |
+ m_lockedOrientations = OrientationAny; |
+ if (m_orientation != m_controller->orientation()) |
+ asyncUpdateController(); |
+} |
+ |
+} // namespace WebCore |