WiFiServiceImpl (Windows): Fixed wrong authentication type with WEP-PSK.
[chromium-blink-merge.git] / components / test_runner / mock_screen_orientation_client.cc
blob80a1dbf013128a1debadc8945f768fdf50cd2318
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
3 // found in the LICENSE file.
5 #include "components/test_runner/mock_screen_orientation_client.h"
7 #include "base/bind.h"
8 #include "base/logging.h"
9 #include "base/message_loop/message_loop.h"
10 #include "third_party/WebKit/public/web/WebLocalFrame.h"
12 namespace test_runner {
14 MockScreenOrientationClient::MockScreenOrientationClient()
15 : main_frame_(NULL),
16 current_lock_(blink::WebScreenOrientationLockDefault),
17 device_orientation_(blink::WebScreenOrientationPortraitPrimary),
18 current_orientation_(blink::WebScreenOrientationPortraitPrimary) {
21 MockScreenOrientationClient::~MockScreenOrientationClient() {
24 void MockScreenOrientationClient::ResetData() {
25 current_lock_ = blink::WebScreenOrientationLockDefault;
26 device_orientation_ = blink::WebScreenOrientationPortraitPrimary;
27 current_orientation_ = blink::WebScreenOrientationPortraitPrimary;
30 void MockScreenOrientationClient::UpdateDeviceOrientation(
31 blink::WebLocalFrame* main_frame,
32 blink::WebScreenOrientationType orientation) {
33 main_frame_ = main_frame;
34 if (device_orientation_ == orientation)
35 return;
36 device_orientation_ = orientation;
37 if (!IsOrientationAllowedByCurrentLock(orientation))
38 return;
39 UpdateScreenOrientation(orientation);
42 void MockScreenOrientationClient::UpdateScreenOrientation(
43 blink::WebScreenOrientationType orientation) {
44 if (current_orientation_ == orientation)
45 return;
46 current_orientation_ = orientation;
47 if (main_frame_)
48 main_frame_->sendOrientationChangeEvent();
51 blink::WebScreenOrientationType
52 MockScreenOrientationClient::CurrentOrientationType() const {
53 return current_orientation_;
56 unsigned MockScreenOrientationClient::CurrentOrientationAngle() const {
57 return OrientationTypeToAngle(current_orientation_);
60 unsigned MockScreenOrientationClient::OrientationTypeToAngle(
61 blink::WebScreenOrientationType type) {
62 unsigned angle;
63 // FIXME(ostap): This relationship between orientationType and
64 // orientationAngle is temporary. The test should be able to specify
65 // the angle in addition to the orientation type.
66 switch (type) {
67 case blink::WebScreenOrientationLandscapePrimary:
68 angle = 90;
69 break;
70 case blink::WebScreenOrientationLandscapeSecondary:
71 angle = 270;
72 break;
73 case blink::WebScreenOrientationPortraitSecondary:
74 angle = 180;
75 break;
76 default:
77 angle = 0;
79 return angle;
82 bool MockScreenOrientationClient::IsOrientationAllowedByCurrentLock(
83 blink::WebScreenOrientationType orientation) {
84 if (current_lock_ == blink::WebScreenOrientationLockDefault ||
85 current_lock_ == blink::WebScreenOrientationLockAny) {
86 return true;
89 switch (orientation) {
90 case blink::WebScreenOrientationPortraitPrimary:
91 return current_lock_ == blink::WebScreenOrientationLockPortraitPrimary ||
92 current_lock_ == blink::WebScreenOrientationLockPortrait;
93 case blink::WebScreenOrientationPortraitSecondary:
94 return current_lock_ ==
95 blink::WebScreenOrientationLockPortraitSecondary ||
96 current_lock_ == blink::WebScreenOrientationLockPortrait;
97 case blink::WebScreenOrientationLandscapePrimary:
98 return current_lock_ == blink::WebScreenOrientationLockLandscapePrimary ||
99 current_lock_ == blink::WebScreenOrientationLockLandscape;
100 case blink::WebScreenOrientationLandscapeSecondary:
101 return current_lock_ ==
102 blink::WebScreenOrientationLockLandscapeSecondary ||
103 current_lock_ == blink::WebScreenOrientationLockLandscape;
104 default:
105 return false;
109 void MockScreenOrientationClient::lockOrientation(
110 blink::WebScreenOrientationLockType orientation,
111 blink::WebLockOrientationCallback* callback) {
112 base::MessageLoop::current()->PostTask(
113 FROM_HERE,
114 base::Bind(&MockScreenOrientationClient::UpdateLockSync,
115 base::Unretained(this),
116 orientation,
117 callback));
120 void MockScreenOrientationClient::unlockOrientation() {
121 base::MessageLoop::current()->PostTask(
122 FROM_HERE,
123 base::Bind(&MockScreenOrientationClient::ResetLockSync,
124 base::Unretained(this)));
127 void MockScreenOrientationClient::UpdateLockSync(
128 blink::WebScreenOrientationLockType lock,
129 blink::WebLockOrientationCallback* callback) {
130 DCHECK(lock != blink::WebScreenOrientationLockDefault);
131 current_lock_ = lock;
132 if (!IsOrientationAllowedByCurrentLock(current_orientation_))
133 UpdateScreenOrientation(SuitableOrientationForCurrentLock());
134 callback->onSuccess();
135 delete callback;
138 void MockScreenOrientationClient::ResetLockSync() {
139 bool will_screen_orientation_need_updating =
140 !IsOrientationAllowedByCurrentLock(device_orientation_);
141 current_lock_ = blink::WebScreenOrientationLockDefault;
142 if (will_screen_orientation_need_updating)
143 UpdateScreenOrientation(device_orientation_);
146 blink::WebScreenOrientationType
147 MockScreenOrientationClient::SuitableOrientationForCurrentLock() {
148 switch (current_lock_) {
149 case blink::WebScreenOrientationLockPortraitSecondary:
150 return blink::WebScreenOrientationPortraitSecondary;
151 case blink::WebScreenOrientationLockLandscapePrimary:
152 case blink::WebScreenOrientationLockLandscape:
153 return blink::WebScreenOrientationLandscapePrimary;
154 case blink::WebScreenOrientationLockLandscapeSecondary:
155 return blink::WebScreenOrientationLandscapePrimary;
156 default:
157 return blink::WebScreenOrientationPortraitPrimary;
161 } // namespace test_runner