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

Side by Side Diff: content/renderer/screen_orientation/mock_screen_orientation_controller.cc

Issue 302553007: Call RenderViewImpl::SetScreenOrientationForTesting to make sure that events are not sent when orie… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/screen_orientation/mock_screen_orientation_controller .h" 5 #include "content/renderer/screen_orientation/mock_screen_orientation_controller .h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/renderer/render_view_impl.h"
8 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h" 9 #include "third_party/WebKit/public/platform/WebScreenOrientationListener.h"
9 10
10 namespace content { 11 namespace content {
11 12
12 MockScreenOrientationController::MockScreenOrientationController() 13 MockScreenOrientationController::MockScreenOrientationController()
13 : current_lock_(blink::WebScreenOrientationLockDefault), 14 : current_lock_(blink::WebScreenOrientationLockDefault),
14 device_orientation_(blink::WebScreenOrientationPortraitPrimary), 15 device_orientation_(blink::WebScreenOrientationPortraitPrimary),
15 current_orientation_(blink::WebScreenOrientationPortraitPrimary), 16 current_orientation_(blink::WebScreenOrientationPortraitPrimary),
16 listener_(NULL) { 17 listener_(NULL),
18 render_view_(NULL) {
17 } 19 }
18 20
19 void MockScreenOrientationController::SetListener( 21 void MockScreenOrientationController::SetListener(
20 blink::WebScreenOrientationListener* listener) { 22 blink::WebScreenOrientationListener* listener) {
21 listener_ = listener; 23 listener_ = listener;
22 } 24 }
23 25
24 void MockScreenOrientationController::ResetData() { 26 void MockScreenOrientationController::ResetData() {
25 current_lock_ = blink::WebScreenOrientationLockDefault; 27 current_lock_ = blink::WebScreenOrientationLockDefault;
26 device_orientation_ = blink::WebScreenOrientationPortraitPrimary; 28 device_orientation_ = blink::WebScreenOrientationPortraitPrimary;
(...skipping 10 matching lines...) Expand all
37 39
38 void MockScreenOrientationController::ResetLock() { 40 void MockScreenOrientationController::ResetLock() {
39 bool will_screen_orientation_need_updating = 41 bool will_screen_orientation_need_updating =
40 !IsOrientationAllowedByCurrentLock(device_orientation_); 42 !IsOrientationAllowedByCurrentLock(device_orientation_);
41 current_lock_ = blink::WebScreenOrientationLockDefault; 43 current_lock_ = blink::WebScreenOrientationLockDefault;
42 if (will_screen_orientation_need_updating) 44 if (will_screen_orientation_need_updating)
43 UpdateScreenOrientation(device_orientation_); 45 UpdateScreenOrientation(device_orientation_);
44 } 46 }
45 47
46 void MockScreenOrientationController::UpdateDeviceOrientation( 48 void MockScreenOrientationController::UpdateDeviceOrientation(
49 RenderView* render_view,
47 blink::WebScreenOrientationType orientation) { 50 blink::WebScreenOrientationType orientation) {
51 if (render_view_) {
52 // Make sure that render_view_ did not change during test.
53 assert(render_view_ == render_view);
54 } else {
55 render_view_ = render_view;
56 }
mlamouri (slow - plz ping) 2014/05/28 13:45:20 I guess you can do: assert(!render_view_ || rend
ostap 2014/05/28 19:17:05 Done.
57
48 if (device_orientation_ == orientation) 58 if (device_orientation_ == orientation)
49 return; 59 return;
50 device_orientation_ = orientation; 60 device_orientation_ = orientation;
51 if (!IsOrientationAllowedByCurrentLock(orientation)) 61 if (!IsOrientationAllowedByCurrentLock(orientation))
52 return; 62 return;
53 UpdateScreenOrientation(orientation); 63 UpdateScreenOrientation(orientation);
54 } 64 }
55 65
56 void MockScreenOrientationController::UpdateScreenOrientation( 66 void MockScreenOrientationController::UpdateScreenOrientation(
57 blink::WebScreenOrientationType orientation) { 67 blink::WebScreenOrientationType orientation) {
58 if (current_orientation_ == orientation) 68 if (current_orientation_ == orientation)
59 return; 69 return;
60 current_orientation_ = orientation; 70 current_orientation_ = orientation;
71 if (render_view_)
72 static_cast<RenderViewImpl*>(render_view_)
73 ->SetScreenOrientationForTesting(orientation);
61 if (listener_) 74 if (listener_)
62 listener_->didChangeScreenOrientation(current_orientation_); 75 listener_->didChangeScreenOrientation(current_orientation_);
Inactive 2014/05/28 12:02:20 BTW, we should get rid of the old listener old in
63 } 76 }
64 77
65 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock( 78 bool MockScreenOrientationController::IsOrientationAllowedByCurrentLock(
66 blink::WebScreenOrientationType orientation) { 79 blink::WebScreenOrientationType orientation) {
67 if (current_lock_ == blink::WebScreenOrientationLockDefault || 80 if (current_lock_ == blink::WebScreenOrientationLockDefault ||
68 current_lock_ == blink::WebScreenOrientationLockAny) { 81 current_lock_ == blink::WebScreenOrientationLockAny) {
69 return true; 82 return true;
70 } 83 }
71 84
72 switch (orientation) { 85 switch (orientation) {
(...skipping 24 matching lines...) Expand all
97 case blink::WebScreenOrientationLockLandscapePrimary: 110 case blink::WebScreenOrientationLockLandscapePrimary:
98 case blink::WebScreenOrientationLockLandscape: 111 case blink::WebScreenOrientationLockLandscape:
99 return blink::WebScreenOrientationLandscapePrimary; 112 return blink::WebScreenOrientationLandscapePrimary;
100 case blink::WebScreenOrientationLockLandscapeSecondary: 113 case blink::WebScreenOrientationLockLandscapeSecondary:
101 return blink::WebScreenOrientationLandscapePrimary; 114 return blink::WebScreenOrientationLandscapePrimary;
102 default: 115 default:
103 return blink::WebScreenOrientationPortraitPrimary; 116 return blink::WebScreenOrientationPortraitPrimary;
104 } 117 }
105 } 118 }
106 119
120 void MockScreenOrientationController::ResetRenderView() {
121 render_view_ = 0;
122 }
123
107 } // namespace content 124 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698