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

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

Issue 347553002: Use WebLockOrientationError instead of WebLockOrientationCallbackErrorType. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup_web_screen_orientation_listener
Patch Set: Created 6 years, 6 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
« no previous file with comments | « content/renderer/screen_orientation/screen_orientation_dispatcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 16 matching lines...) Expand all
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_; 35 unsigned angle_;
36 blink::WebScreenOrientationType orientation_; 36 blink::WebScreenOrientationType orientation_;
37 blink::WebLockOrientationCallback::ErrorType error_; 37 blink::WebLockOrientationError error_;
38 }; 38 };
39 39
40 explicit MockLockOrientationCallback(LockOrientationResultHolder* results) 40 explicit MockLockOrientationCallback(LockOrientationResultHolder* results)
41 : results_(results) {} 41 : results_(results) {}
42 42
43 virtual void onSuccess(unsigned angle, 43 virtual void onSuccess(unsigned angle,
44 blink::WebScreenOrientationType orientation) { 44 blink::WebScreenOrientationType orientation) {
45 results_->succeeded_ = true; 45 results_->succeeded_ = true;
46 results_->angle_ = angle; 46 results_->angle_ = angle;
47 results_->orientation_ = orientation; 47 results_->orientation_ = orientation;
48 } 48 }
49 49
50 virtual void onError( 50 virtual void onError(blink::WebLockOrientationError error) {
51 blink::WebLockOrientationCallback::ErrorType error) {
52 results_->failed_ = true; 51 results_->failed_ = true;
53 results_->error_ = error; 52 results_->error_ = error;
54 } 53 }
55 54
56 private: 55 private:
57 virtual ~MockLockOrientationCallback() {} 56 virtual ~MockLockOrientationCallback() {}
58 57
59 LockOrientationResultHolder* results_; 58 LockOrientationResultHolder* results_;
60 }; 59 };
61 60
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // Test that calling lockOrientation() followed by unlockOrientation() cancel 116 // Test that calling lockOrientation() followed by unlockOrientation() cancel
118 // the lockOrientation(). 117 // the lockOrientation().
119 TEST_F(ScreenOrientationDispatcherTest, CancelPending_Unlocking) { 118 TEST_F(ScreenOrientationDispatcherTest, CancelPending_Unlocking) {
120 MockLockOrientationCallback::LockOrientationResultHolder callback_results; 119 MockLockOrientationCallback::LockOrientationResultHolder callback_results;
121 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, 120 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary,
122 new MockLockOrientationCallback(&callback_results)); 121 new MockLockOrientationCallback(&callback_results));
123 UnlockOrientation(); 122 UnlockOrientation();
124 123
125 EXPECT_FALSE(callback_results.succeeded_); 124 EXPECT_FALSE(callback_results.succeeded_);
126 EXPECT_TRUE(callback_results.failed_); 125 EXPECT_TRUE(callback_results.failed_);
127 EXPECT_EQ(blink::WebLockOrientationCallback::ErrorTypeCanceled, 126 EXPECT_EQ(blink::WebLockOrientationErrorCanceled, callback_results.error_);
128 callback_results.error_);
129 } 127 }
130 128
131 // Test that calling lockOrientation() twice cancel the first lockOrientation(). 129 // Test that calling lockOrientation() twice cancel the first lockOrientation().
132 TEST_F(ScreenOrientationDispatcherTest, CancelPending_DoubleLock) { 130 TEST_F(ScreenOrientationDispatcherTest, CancelPending_DoubleLock) {
133 MockLockOrientationCallback::LockOrientationResultHolder callback_results; 131 MockLockOrientationCallback::LockOrientationResultHolder callback_results;
134 // We create the object to prevent leaks but never actually use it. 132 // We create the object to prevent leaks but never actually use it.
135 MockLockOrientationCallback::LockOrientationResultHolder callback_results2; 133 MockLockOrientationCallback::LockOrientationResultHolder callback_results2;
136 134
137 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, 135 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary,
138 new MockLockOrientationCallback(&callback_results)); 136 new MockLockOrientationCallback(&callback_results));
139 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, 137 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary,
140 new MockLockOrientationCallback(&callback_results2)); 138 new MockLockOrientationCallback(&callback_results2));
141 139
142 EXPECT_FALSE(callback_results.succeeded_); 140 EXPECT_FALSE(callback_results.succeeded_);
143 EXPECT_TRUE(callback_results.failed_); 141 EXPECT_TRUE(callback_results.failed_);
144 EXPECT_EQ(blink::WebLockOrientationCallback::ErrorTypeCanceled, 142 EXPECT_EQ(blink::WebLockOrientationErrorCanceled, callback_results.error_);
145 callback_results.error_);
146 } 143 }
147 144
148 // Test that when a LockError message is received, the request is set as failed 145 // Test that when a LockError message is received, the request is set as failed
149 // with the correct values. 146 // with the correct values.
150 TEST_F(ScreenOrientationDispatcherTest, LockRequest_Error) { 147 TEST_F(ScreenOrientationDispatcherTest, LockRequest_Error) {
151 std::list<blink::WebLockOrientationCallback::ErrorType> errors; 148 std::list<blink::WebLockOrientationError> errors;
152 errors.push_back(blink::WebLockOrientationCallback::ErrorTypeNotAvailable); 149 errors.push_back(blink::WebLockOrientationErrorNotAvailable);
153 errors.push_back( 150 errors.push_back(
154 blink::WebLockOrientationCallback::ErrorTypeFullScreenRequired); 151 blink::WebLockOrientationErrorFullScreenRequired);
155 errors.push_back(blink::WebLockOrientationCallback::ErrorTypeCanceled); 152 errors.push_back(blink::WebLockOrientationErrorCanceled);
156 153
157 for (std::list<blink::WebLockOrientationCallback::ErrorType>::const_iterator 154 for (std::list<blink::WebLockOrientationError>::const_iterator
158 it = errors.begin(); it != errors.end(); ++it) { 155 it = errors.begin(); it != errors.end(); ++it) {
159 MockLockOrientationCallback::LockOrientationResultHolder callback_results; 156 MockLockOrientationCallback::LockOrientationResultHolder callback_results;
160 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, 157 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary,
161 new MockLockOrientationCallback(&callback_results)); 158 new MockLockOrientationCallback(&callback_results));
162 159
163 int request_id = GetFirstLockRequestIdFromSink(); 160 int request_id = GetFirstLockRequestIdFromSink();
164 OnMessageReceived( 161 OnMessageReceived(
165 ScreenOrientationMsg_LockError(routing_id(), request_id, *it)); 162 ScreenOrientationMsg_LockError(routing_id(), request_id, *it));
166 163
167 EXPECT_FALSE(callback_results.succeeded_); 164 EXPECT_FALSE(callback_results.succeeded_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 224
228 // Test an edge case: a LockError is received but it matches no pending 225 // Test an edge case: a LockError is received but it matches no pending
229 // callback. 226 // callback.
230 TEST_F(ScreenOrientationDispatcherTest, ErrorForUnknownRequest) { 227 TEST_F(ScreenOrientationDispatcherTest, ErrorForUnknownRequest) {
231 MockLockOrientationCallback::LockOrientationResultHolder callback_results; 228 MockLockOrientationCallback::LockOrientationResultHolder callback_results;
232 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary, 229 LockOrientation(blink::WebScreenOrientationLockPortraitPrimary,
233 new MockLockOrientationCallback(&callback_results)); 230 new MockLockOrientationCallback(&callback_results));
234 231
235 int request_id = GetFirstLockRequestIdFromSink(); 232 int request_id = GetFirstLockRequestIdFromSink();
236 OnMessageReceived(ScreenOrientationMsg_LockError( 233 OnMessageReceived(ScreenOrientationMsg_LockError(
237 routing_id(), 234 routing_id(), request_id + 1, blink::WebLockOrientationErrorCanceled));
238 request_id + 1,
239 blink::WebLockOrientationCallback::ErrorTypeCanceled));
240 235
241 EXPECT_FALSE(callback_results.succeeded_); 236 EXPECT_FALSE(callback_results.succeeded_);
242 EXPECT_FALSE(callback_results.failed_); 237 EXPECT_FALSE(callback_results.failed_);
243 } 238 }
244 239
245 // Test the following scenario: 240 // Test the following scenario:
246 // - request1 is received by the dispatcher; 241 // - request1 is received by the dispatcher;
247 // - request2 is received by the dispatcher; 242 // - request2 is received by the dispatcher;
248 // - request1 is rejected; 243 // - request1 is rejected;
249 // - request1 success response is received. 244 // - request1 success response is received.
(...skipping 13 matching lines...) Expand all
263 258
264 OnMessageReceived(ScreenOrientationMsg_LockSuccess( 259 OnMessageReceived(ScreenOrientationMsg_LockSuccess(
265 routing_id(), 260 routing_id(),
266 request_id1, 261 request_id1,
267 0, 262 0,
268 blink::WebScreenOrientationPortraitPrimary)); 263 blink::WebScreenOrientationPortraitPrimary));
269 264
270 // First request is still rejected. 265 // First request is still rejected.
271 EXPECT_FALSE(callback_results1.succeeded_); 266 EXPECT_FALSE(callback_results1.succeeded_);
272 EXPECT_TRUE(callback_results1.failed_); 267 EXPECT_TRUE(callback_results1.failed_);
273 EXPECT_EQ(blink::WebLockOrientationCallback::ErrorTypeCanceled, 268 EXPECT_EQ(blink::WebLockOrientationErrorCanceled, callback_results1.error_);
274 callback_results1.error_);
275 269
276 // Second request is still pending. 270 // Second request is still pending.
277 EXPECT_FALSE(callback_results2.succeeded_); 271 EXPECT_FALSE(callback_results2.succeeded_);
278 EXPECT_FALSE(callback_results2.failed_); 272 EXPECT_FALSE(callback_results2.failed_);
279 } 273 }
280 274
281 } // namespace content 275 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/screen_orientation/screen_orientation_dispatcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698