Call RenderViewImpl::SetScreenOrientationForTesting from...

Call RenderViewImpl::SetScreenOrientationForTesting from MockScreenOrientationController::UpdateScreenOrientation() to make sure that events are not sent when orientation is locked.

Existing implementation calls SetScreenOrientationForTesting and sends screen
orientation events even when the test screen orientation is locked.

BUG=162827

Review URL: https://codereview.chromium.org/302553007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@275535 0039d316-1c4b-4281-b951-d872f2087c98
parent 5eced8f7
......@@ -13,7 +13,7 @@ namespace content {
RenderViewObserver::RenderViewObserver(RenderView* render_view)
: render_view_(render_view),
routing_id_(MSG_ROUTING_NONE) {
// |render_view| can be NULL on unit testing.
// |render_view| can be NULL on unit testing or if Observe() is used.
if (render_view) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view);
routing_id_ = impl->routing_id();
......@@ -53,4 +53,19 @@ void RenderViewObserver::RenderViewGone() {
render_view_ = NULL;
}
void RenderViewObserver::Observe(RenderView* render_view) {
RenderViewImpl* impl = static_cast<RenderViewImpl*>(render_view_);
if (impl) {
impl->RemoveObserver(this);
routing_id_ = 0;
}
render_view_ = render_view;
impl = static_cast<RenderViewImpl*>(render_view_);
if (impl) {
routing_id_ = impl->routing_id();
impl->AddObserver(this);
}
}
} // namespace content
......@@ -109,6 +109,12 @@ class CONTENT_EXPORT RenderViewObserver : public IPC::Listener,
explicit RenderViewObserver(RenderView* render_view);
virtual ~RenderViewObserver();
// Sets |render_view_| to track.
// Removes itself of previous (if any) |render_view_| observer list and adds
// to the new |render_view|. Since it assumes that observer outlives
// render_view, OnDestruct should be overridden.
void Observe(RenderView* render_view);
private:
friend class RenderViewImpl;
......
......@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/metrics/histogram.h"
......@@ -1083,6 +1084,7 @@ void RendererWebKitPlatformSupportImpl::SetMockDeviceMotionDataForTesting(
// static
void RendererWebKitPlatformSupportImpl::ResetMockScreenOrientationForTesting()
{
DCHECK(!(g_test_screen_orientation_controller == 0));
g_test_screen_orientation_controller.Get().ResetData();
}
......@@ -1177,9 +1179,10 @@ void RendererWebKitPlatformSupportImpl::unlockOrientation() {
// static
void RendererWebKitPlatformSupportImpl::SetMockScreenOrientationForTesting(
RenderView* render_view,
blink::WebScreenOrientationType orientation) {
g_test_screen_orientation_controller.Get()
.UpdateDeviceOrientation(orientation);
.UpdateDeviceOrientation(render_view, orientation);
}
//------------------------------------------------------------------------------
......
......@@ -41,6 +41,7 @@ class DeviceMotionEventPump;
class DeviceOrientationEventPump;
class QuotaMessageFilter;
class RendererClipboardClient;
class RenderView;
class ScreenOrientationDispatcher;
class ThreadSafeSender;
class WebClipboardImpl;
......@@ -183,6 +184,7 @@ class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
const blink::WebDeviceOrientationData& data);
// Forces the screen orientation for testing purposes.
static void SetMockScreenOrientationForTesting(
RenderView* render_view,
blink::WebScreenOrientationType);
// Resets the mock screen orientation data used for testing.
static void ResetMockScreenOrientationForTesting();
......
......@@ -7,12 +7,14 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
namespace content {
MockScreenOrientationController::MockScreenOrientationController()
: current_lock_(blink::WebScreenOrientationLockDefault),
: RenderViewObserver(NULL),
current_lock_(blink::WebScreenOrientationLockDefault),
device_orientation_(blink::WebScreenOrientationPortraitPrimary),
current_orientation_(blink::WebScreenOrientationPortraitPrimary),
listener_(NULL) {
......@@ -30,6 +32,9 @@ void MockScreenOrientationController::SetListener(
}
void MockScreenOrientationController::ResetData() {
if (render_view_impl())
render_view_impl()->RemoveObserver(this);
current_lock_ = blink::WebScreenOrientationLockDefault;
device_orientation_ = blink::WebScreenOrientationPortraitPrimary;
current_orientation_ = blink::WebScreenOrientationPortraitPrimary;
......@@ -64,7 +69,15 @@ void MockScreenOrientationController::ResetLockSync() {
}
void MockScreenOrientationController::UpdateDeviceOrientation(
RenderView* render_view,
blink::WebScreenOrientationType orientation) {
if (this->render_view()) {
// Make sure that render_view_ did not change during test.
DCHECK_EQ(this->render_view(), render_view);
} else {
Observe(render_view);
}
if (device_orientation_ == orientation)
return;
device_orientation_ = orientation;
......@@ -73,11 +86,18 @@ void MockScreenOrientationController::UpdateDeviceOrientation(
UpdateScreenOrientation(orientation);
}
RenderViewImpl* MockScreenOrientationController::render_view_impl() const {
return static_cast<RenderViewImpl*>(render_view());
}
void MockScreenOrientationController::UpdateScreenOrientation(
blink::WebScreenOrientationType orientation) {
if (current_orientation_ == orientation)
return;
current_orientation_ = orientation;
if (render_view_impl())
render_view_impl()->SetScreenOrientationForTesting(orientation);
if (listener_)
listener_->didChangeScreenOrientation(current_orientation_);
}
......@@ -124,4 +144,7 @@ MockScreenOrientationController::SuitableOrientationForCurrentLock() {
}
}
void MockScreenOrientationController::OnDestruct() {
}
} // namespace content
......@@ -8,6 +8,7 @@
#include "base/lazy_instance.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h"
#include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
......@@ -16,9 +17,12 @@ class WebScreenOrientationListener;
}
namespace content {
class RenderView;
class RenderViewImpl;
class MockScreenOrientationController
: public base::RefCountedThreadSafe<MockScreenOrientationController> {
: public base::RefCountedThreadSafe<MockScreenOrientationController>,
public RenderViewObserver {
public:
MockScreenOrientationController();
......@@ -26,7 +30,9 @@ class MockScreenOrientationController
void ResetData();
void UpdateLock(blink::WebScreenOrientationLockType);
void ResetLock();
void UpdateDeviceOrientation(blink::WebScreenOrientationType);
void UpdateDeviceOrientation(
RenderView* render_view,
blink::WebScreenOrientationType);
private:
virtual ~MockScreenOrientationController();
......@@ -36,6 +42,10 @@ class MockScreenOrientationController
void UpdateScreenOrientation(blink::WebScreenOrientationType);
bool IsOrientationAllowedByCurrentLock(blink::WebScreenOrientationType);
blink::WebScreenOrientationType SuitableOrientationForCurrentLock();
RenderViewImpl* render_view_impl() const;
// RenderViewObserver
virtual void OnDestruct() OVERRIDE;
blink::WebScreenOrientationLockType current_lock_;
blink::WebScreenOrientationType device_orientation_;
......
......@@ -104,11 +104,8 @@ void SetMockDeviceOrientationData(const WebDeviceOrientationData& data) {
void SetMockScreenOrientation(
RenderView* render_view,
const blink::WebScreenOrientationType& orientation) {
static_cast<RenderViewImpl*>(render_view)
->SetScreenOrientationForTesting(orientation);
// FIXME(ostap): Remove this when blink side gets updated.
RendererWebKitPlatformSupportImpl::
SetMockScreenOrientationForTesting(orientation);
SetMockScreenOrientationForTesting(render_view, orientation);
}
void ResetMockScreenOrientation()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment