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..b56f183975a99bdce9d48cd948b11eb95b3d9509 |
--- /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. |
+ DEFINE_STATIC_LOCAL(Vector<ScreenOrientationValue>, supportedOrientationValues, ()); |
+ if (supportedOrientationValues.isEmpty()) { |
+ supportedOrientationValues.append(OrientationPortraitPrimary); |
+ supportedOrientationValues.append(OrientationLandscapePrimary); |
+ supportedOrientationValues.append(OrientationPortraitSecondary); |
+ supportedOrientationValues.append(OrientationLandscapeSecondary); |
+ } |
+ for (unsigned i = 0; i < supportedOrientationValues.size(); ++i) { |
Peter Beverloo
2014/02/13 16:33:42
nit: we can avoid the static local here by just us
Inactive
2014/02/13 17:03:24
Done.
|
+ 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 |