OLD | NEW |
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 "screen_orientation_dispatcher.h" | 5 #include "screen_orientation_dispatcher.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 // any time. | 25 // any time. |
26 class MockLockOrientationCallback : | 26 class MockLockOrientationCallback : |
27 public blink::WebLockOrientationCallback { | 27 public blink::WebLockOrientationCallback { |
28 public: | 28 public: |
29 struct LockOrientationResultHolder { | 29 struct LockOrientationResultHolder { |
30 LockOrientationResultHolder() | 30 LockOrientationResultHolder() |
31 : succeeded_(false), failed_(false) {} | 31 : succeeded_(false), failed_(false) {} |
32 | 32 |
33 bool succeeded_; | 33 bool succeeded_; |
34 bool failed_; | 34 bool failed_; |
35 unsigned angle_; | |
36 blink::WebScreenOrientationType orientation_; | |
37 blink::WebLockOrientationError error_; | 35 blink::WebLockOrientationError error_; |
38 }; | 36 }; |
39 | 37 |
40 explicit MockLockOrientationCallback(LockOrientationResultHolder* results) | 38 explicit MockLockOrientationCallback(LockOrientationResultHolder* results) |
41 : results_(results) {} | 39 : results_(results) {} |
42 | 40 |
43 virtual void onSuccess(unsigned angle, | 41 virtual void onSuccess() { |
44 blink::WebScreenOrientationType orientation) { | |
45 results_->succeeded_ = true; | 42 results_->succeeded_ = true; |
46 results_->angle_ = angle; | |
47 results_->orientation_ = orientation; | |
48 } | 43 } |
49 | 44 |
50 virtual void onError(blink::WebLockOrientationError error) { | 45 virtual void onError(blink::WebLockOrientationError error) { |
51 results_->failed_ = true; | 46 results_->failed_ = true; |
52 results_->error_ = error; | 47 results_->error_ = error; |
53 } | 48 } |
54 | 49 |
55 private: | 50 private: |
56 virtual ~MockLockOrientationCallback() {} | 51 virtual ~MockLockOrientationCallback() {} |
57 | 52 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 158 |
164 EXPECT_FALSE(callback_results.succeeded_); | 159 EXPECT_FALSE(callback_results.succeeded_); |
165 EXPECT_TRUE(callback_results.failed_); | 160 EXPECT_TRUE(callback_results.failed_); |
166 EXPECT_EQ(*it, callback_results.error_); | 161 EXPECT_EQ(*it, callback_results.error_); |
167 | 162 |
168 sink().ClearMessages(); | 163 sink().ClearMessages(); |
169 } | 164 } |
170 } | 165 } |
171 | 166 |
172 // Test that when a LockSuccess message is received, the request is set as | 167 // Test that when a LockSuccess message is received, the request is set as |
173 // succeeded with the correct values. | 168 // succeeded. |
174 TEST_F(ScreenOrientationDispatcherTest, LockRequest_Success) { | 169 TEST_F(ScreenOrientationDispatcherTest, LockRequest_Success) { |
175 struct ScreenOrientationInformation { | 170 MockLockOrientationCallback::LockOrientationResultHolder callback_results; |
176 unsigned angle; | 171 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, |
177 blink::WebScreenOrientationType type; | 172 new MockLockOrientationCallback(&callback_results)); |
178 } orientations[] = { | |
179 { 0, blink::WebScreenOrientationPortraitPrimary }, | |
180 { 0, blink::WebScreenOrientationLandscapePrimary }, | |
181 { 90, blink::WebScreenOrientationPortraitSecondary }, | |
182 { 90, blink::WebScreenOrientationLandscapePrimary } | |
183 }; | |
184 | 173 |
185 int orientationsCount = 4; | 174 int request_id = GetFirstLockRequestIdFromSink(); |
| 175 OnMessageReceived(ScreenOrientationMsg_LockSuccess(routing_id(), |
| 176 request_id)); |
186 | 177 |
187 for (int i = 0; i < orientationsCount; ++i) { | 178 EXPECT_TRUE(callback_results.succeeded_); |
188 MockLockOrientationCallback::LockOrientationResultHolder callback_results; | 179 EXPECT_FALSE(callback_results.failed_); |
189 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, | |
190 new MockLockOrientationCallback(&callback_results)); | |
191 | 180 |
192 int request_id = GetFirstLockRequestIdFromSink(); | 181 sink().ClearMessages(); |
193 OnMessageReceived(ScreenOrientationMsg_LockSuccess(routing_id(), | |
194 request_id, | |
195 orientations[i].angle, | |
196 orientations[i].type)); | |
197 | |
198 EXPECT_TRUE(callback_results.succeeded_); | |
199 EXPECT_FALSE(callback_results.failed_); | |
200 EXPECT_EQ(orientations[i].angle, callback_results.angle_); | |
201 EXPECT_EQ(orientations[i].type, callback_results.orientation_); | |
202 | |
203 sink().ClearMessages(); | |
204 } | |
205 } | 182 } |
206 | 183 |
207 // Test an edge case: a LockSuccess is received but it matches no pending | 184 // Test an edge case: a LockSuccess is received but it matches no pending |
208 // callback. | 185 // callback. |
209 TEST_F(ScreenOrientationDispatcherTest, SuccessForUnknownRequest) { | 186 TEST_F(ScreenOrientationDispatcherTest, SuccessForUnknownRequest) { |
210 MockLockOrientationCallback::LockOrientationResultHolder callback_results; | 187 MockLockOrientationCallback::LockOrientationResultHolder callback_results; |
211 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, | 188 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, |
212 new MockLockOrientationCallback(&callback_results)); | 189 new MockLockOrientationCallback(&callback_results)); |
213 | 190 |
214 int request_id = GetFirstLockRequestIdFromSink(); | 191 int request_id = GetFirstLockRequestIdFromSink(); |
215 OnMessageReceived(ScreenOrientationMsg_LockSuccess( | 192 OnMessageReceived(ScreenOrientationMsg_LockSuccess(routing_id(), |
216 routing_id(), | 193 request_id + 1)); |
217 request_id + 1, | |
218 90, | |
219 blink::WebScreenOrientationLandscapePrimary)); | |
220 | 194 |
221 EXPECT_FALSE(callback_results.succeeded_); | 195 EXPECT_FALSE(callback_results.succeeded_); |
222 EXPECT_FALSE(callback_results.failed_); | 196 EXPECT_FALSE(callback_results.failed_); |
223 } | 197 } |
224 | 198 |
225 // Test an edge case: a LockError is received but it matches no pending | 199 // Test an edge case: a LockError is received but it matches no pending |
226 // callback. | 200 // callback. |
227 TEST_F(ScreenOrientationDispatcherTest, ErrorForUnknownRequest) { | 201 TEST_F(ScreenOrientationDispatcherTest, ErrorForUnknownRequest) { |
228 MockLockOrientationCallback::LockOrientationResultHolder callback_results; | 202 MockLockOrientationCallback::LockOrientationResultHolder callback_results; |
229 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, | 203 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, |
(...skipping 19 matching lines...) Expand all Loading... |
249 | 223 |
250 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, | 224 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, |
251 new MockLockOrientationCallback(&callback_results1)); | 225 new MockLockOrientationCallback(&callback_results1)); |
252 int request_id1 = GetFirstLockRequestIdFromSink(); | 226 int request_id1 = GetFirstLockRequestIdFromSink(); |
253 | 227 |
254 LockOrientation(blink::WebScreenOrientationLockLandscapePrimary, | 228 LockOrientation(blink::WebScreenOrientationLockLandscapePrimary, |
255 new MockLockOrientationCallback(&callback_results2)); | 229 new MockLockOrientationCallback(&callback_results2)); |
256 | 230 |
257 // callback_results1 must be rejected, tested in CancelPending_DoubleLock. | 231 // callback_results1 must be rejected, tested in CancelPending_DoubleLock. |
258 | 232 |
259 OnMessageReceived(ScreenOrientationMsg_LockSuccess( | 233 OnMessageReceived(ScreenOrientationMsg_LockSuccess(routing_id(), |
260 routing_id(), | 234 request_id1)); |
261 request_id1, | |
262 0, | |
263 blink::WebScreenOrientationPortraitPrimary)); | |
264 | 235 |
265 // First request is still rejected. | 236 // First request is still rejected. |
266 EXPECT_FALSE(callback_results1.succeeded_); | 237 EXPECT_FALSE(callback_results1.succeeded_); |
267 EXPECT_TRUE(callback_results1.failed_); | 238 EXPECT_TRUE(callback_results1.failed_); |
268 EXPECT_EQ(blink::WebLockOrientationErrorCanceled, callback_results1.error_); | 239 EXPECT_EQ(blink::WebLockOrientationErrorCanceled, callback_results1.error_); |
269 | 240 |
270 // Second request is still pending. | 241 // Second request is still pending. |
271 EXPECT_FALSE(callback_results2.succeeded_); | 242 EXPECT_FALSE(callback_results2.succeeded_); |
272 EXPECT_FALSE(callback_results2.failed_); | 243 EXPECT_FALSE(callback_results2.failed_); |
273 } | 244 } |
274 | 245 |
275 } // namespace content | 246 } // namespace content |
OLD | NEW |