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

Side by Side Diff: content/browser/screen_orientation/screen_orientation_provider_unittest.cc

Issue 2702033002: [ScreenOrientation] Fire pending lock request when we found it has failed.
Patch Set: Created 3 years, 10 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/browser/screen_orientation/screen_orientation_provider.h" 5 #include "content/browser/screen_orientation/screen_orientation_provider.h"
6 6
7 #include "base/optional.h" 7 #include "base/optional.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/common/frame_messages.h" 9 #include "content/common/frame_messages.h"
10 #include "content/public/browser/screen_orientation_delegate.h" 10 #include "content/public/browser/screen_orientation_delegate.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 // Navigate to a site. 144 // Navigate to a site.
145 const GURL url("http://www.google.com"); 145 const GURL url("http://www.google.com");
146 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED, 146 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED,
147 std::string()); 147 std::string());
148 148
149 base::Optional<ScreenOrientationLockResult> result_1; 149 base::Optional<ScreenOrientationLockResult> result_1;
150 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 150 CallLockAndGetResult(blink::WebScreenOrientationLockType::
151 WebScreenOrientationLockLandscapeSecondary, 151 WebScreenOrientationLockLandscapeSecondary,
152 &result_1); 152 &result_1);
153 // Lock request is pending. 153 #if defined(OS_ANDROID)
154 // On Android the screen orientation is expected to be changed asynchronously,
155 // the lock request is pending.
154 EXPECT_FALSE(result_1.has_value()); 156 EXPECT_FALSE(result_1.has_value());
157 #else
158 // On other platforms the screen orientation is expected to be changed
159 // synchronously, but FakeScreenOrientationDelegate did not change screen
160 // orientation actually, so the lock request will be fired immediately.
161 EXPECT_EQ(ScreenOrientationLockResult::
162 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
163 result_1);
164 #endif
155 // Delegate did apply lock once. 165 // Delegate did apply lock once.
156 EXPECT_EQ(1, delegate.lock_count()); 166 EXPECT_EQ(1, delegate.lock_count());
157 } 167 }
158 168
159 // Full screen is required by delegate. 169 // Full screen is required by delegate.
160 TEST_F(ScreenOrientationProviderTest, DelegateRequireFullScreenLockOnce) { 170 TEST_F(ScreenOrientationProviderTest, DelegateRequireFullScreenLockOnce) {
161 // ScreenOrientationDelegate requires full screen. 171 // ScreenOrientationDelegate requires full screen.
162 FakeScreenOrientationDelegate delegate(true, true); 172 FakeScreenOrientationDelegate delegate(true, true);
163 173
164 // Navigate to a site. 174 // Navigate to a site.
(...skipping 15 matching lines...) Expand all
180 190
181 // Simulates entering full screen. 191 // Simulates entering full screen.
182 main_test_rfh()->OnMessageReceived( 192 main_test_rfh()->OnMessageReceived(
183 FrameHostMsg_ToggleFullscreen(main_test_rfh()->GetRoutingID(), true)); 193 FrameHostMsg_ToggleFullscreen(main_test_rfh()->GetRoutingID(), true));
184 ASSERT_TRUE(contents()->IsFullscreenForCurrentTab()); 194 ASSERT_TRUE(contents()->IsFullscreenForCurrentTab());
185 195
186 base::Optional<ScreenOrientationLockResult> result_2; 196 base::Optional<ScreenOrientationLockResult> result_2;
187 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 197 CallLockAndGetResult(blink::WebScreenOrientationLockType::
188 WebScreenOrientationLockLandscapeSecondary, 198 WebScreenOrientationLockLandscapeSecondary,
189 &result_2); 199 &result_2);
200 #if defined(OS_ANDROID)
190 // Lock request is pending. 201 // Lock request is pending.
191 EXPECT_FALSE(result_2.has_value()); 202 EXPECT_FALSE(result_2.has_value());
203 #else
204 EXPECT_EQ(ScreenOrientationLockResult::
205 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
206 result_2);
207 #endif
192 // Delegate did apply lock once. 208 // Delegate did apply lock once.
193 EXPECT_EQ(1, delegate.lock_count()); 209 EXPECT_EQ(1, delegate.lock_count());
194 } 210 }
195 211
196 // Lock once, then unlock once, the pending lock request will be cancelled. 212 // Lock once, then unlock once, the pending lock request will be cancelled.
197 TEST_F(ScreenOrientationProviderTest, DelegateLockThenUnlock) { 213 TEST_F(ScreenOrientationProviderTest, DelegateLockThenUnlock) {
198 FakeScreenOrientationDelegate delegate(true, false); 214 FakeScreenOrientationDelegate delegate(true, false);
199 215
200 // Navigate to a site. 216 // Navigate to a site.
201 const GURL url("http://www.google.com"); 217 const GURL url("http://www.google.com");
202 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED, 218 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED,
203 std::string()); 219 std::string());
204 220
205 base::Optional<ScreenOrientationLockResult> result_1; 221 base::Optional<ScreenOrientationLockResult> result_1;
206 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 222 CallLockAndGetResult(blink::WebScreenOrientationLockType::
207 WebScreenOrientationLockLandscapeSecondary, 223 WebScreenOrientationLockLandscapeSecondary,
208 &result_1); 224 &result_1);
225 #if defined(OS_ANDROID)
209 // The lock request will be pending. 226 // The lock request will be pending.
210 EXPECT_FALSE(result_1.has_value()); 227 EXPECT_FALSE(result_1.has_value());
228 #else
229 EXPECT_EQ(ScreenOrientationLockResult::
230 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
231 result_1);
232 #endif
211 // Delegate did apply lock once. 233 // Delegate did apply lock once.
212 EXPECT_EQ(1, delegate.lock_count()); 234 EXPECT_EQ(1, delegate.lock_count());
213 EXPECT_EQ(0, delegate.unlock_count()); 235 EXPECT_EQ(0, delegate.unlock_count());
214 236
215 CallUnlock(); 237 CallUnlock();
216 // The pending lock request is cancelled. 238 // The pending lock request is cancelled.
217 EXPECT_EQ(ScreenOrientationLockResult:: 239 EXPECT_EQ(ScreenOrientationLockResult::
218 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED, 240 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
219 result_1); 241 result_1);
220 // Delegate did apply unlock once. 242 // Delegate did apply unlock once.
221 EXPECT_EQ(1, delegate.unlock_count()); 243 EXPECT_EQ(1, delegate.unlock_count());
222 } 244 }
223 245
224 // Lock twice, the first lock request will be cancelled by the second one. 246 // Lock twice, the first lock request will be cancelled by the second one.
225 TEST_F(ScreenOrientationProviderTest, DelegateLockThenLock) { 247 TEST_F(ScreenOrientationProviderTest, DelegateLockThenLock) {
226 FakeScreenOrientationDelegate delegate(true, false); 248 FakeScreenOrientationDelegate delegate(true, false);
227 249
228 // Navigate to a site. 250 // Navigate to a site.
229 const GURL url("http://www.google.com"); 251 const GURL url("http://www.google.com");
230 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED, 252 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED,
231 std::string()); 253 std::string());
232 254
233 base::Optional<ScreenOrientationLockResult> result_1; 255 base::Optional<ScreenOrientationLockResult> result_1;
234 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 256 CallLockAndGetResult(blink::WebScreenOrientationLockType::
235 WebScreenOrientationLockLandscapeSecondary, 257 WebScreenOrientationLockLandscapeSecondary,
236 &result_1); 258 &result_1);
259 #if defined(OS_ANDROID)
237 // The lock request will be pending. 260 // The lock request will be pending.
238 EXPECT_FALSE(result_1.has_value()); 261 EXPECT_FALSE(result_1.has_value());
262 #else
263 EXPECT_EQ(ScreenOrientationLockResult::
264 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
265 result_1);
266 #endif
239 // Delegate did apply lock once. 267 // Delegate did apply lock once.
240 EXPECT_EQ(1, delegate.lock_count()); 268 EXPECT_EQ(1, delegate.lock_count());
241 EXPECT_EQ(0, delegate.unlock_count()); 269 EXPECT_EQ(0, delegate.unlock_count());
242 270
243 base::Optional<ScreenOrientationLockResult> result_2; 271 base::Optional<ScreenOrientationLockResult> result_2;
244 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 272 CallLockAndGetResult(blink::WebScreenOrientationLockType::
245 WebScreenOrientationLockLandscapeSecondary, 273 WebScreenOrientationLockLandscapeSecondary,
246 &result_2); 274 &result_2);
247 // The pending lock request is cancelled. 275 // The pending lock request is cancelled.
248 EXPECT_EQ(ScreenOrientationLockResult:: 276 EXPECT_EQ(ScreenOrientationLockResult::
249 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED, 277 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
250 result_1); 278 result_1);
279 #if defined(OS_ANDROID)
251 // The second one became pending. 280 // The second one became pending.
252 EXPECT_FALSE(result_2.has_value()); 281 EXPECT_FALSE(result_2.has_value());
282 #else
283 EXPECT_EQ(ScreenOrientationLockResult::
284 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
285 result_2);
286 #endif
253 // Delegate did apply lock once more. 287 // Delegate did apply lock once more.
254 EXPECT_EQ(2, delegate.lock_count()); 288 EXPECT_EQ(2, delegate.lock_count());
255 EXPECT_EQ(0, delegate.unlock_count()); 289 EXPECT_EQ(0, delegate.unlock_count());
256 } 290 }
257 291
258 // Unlock won't be applied if no lock has been applied previously. 292 // Unlock won't be applied if no lock has been applied previously.
259 TEST_F(ScreenOrientationProviderTest, NoUnlockWithoutLock) { 293 TEST_F(ScreenOrientationProviderTest, NoUnlockWithoutLock) {
260 FakeScreenOrientationDelegate delegate(true, false); 294 FakeScreenOrientationDelegate delegate(true, false);
261 295
262 // Navigate to a site. 296 // Navigate to a site.
(...skipping 20 matching lines...) Expand all
283 317
284 // Simulates entering full screen. 318 // Simulates entering full screen.
285 main_test_rfh()->OnMessageReceived( 319 main_test_rfh()->OnMessageReceived(
286 FrameHostMsg_ToggleFullscreen(main_test_rfh()->GetRoutingID(), true)); 320 FrameHostMsg_ToggleFullscreen(main_test_rfh()->GetRoutingID(), true));
287 ASSERT_TRUE(contents()->IsFullscreenForCurrentTab()); 321 ASSERT_TRUE(contents()->IsFullscreenForCurrentTab());
288 322
289 base::Optional<ScreenOrientationLockResult> result; 323 base::Optional<ScreenOrientationLockResult> result;
290 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 324 CallLockAndGetResult(blink::WebScreenOrientationLockType::
291 WebScreenOrientationLockLandscapeSecondary, 325 WebScreenOrientationLockLandscapeSecondary,
292 &result); 326 &result);
327 #if defined(OS_ANDROID)
293 // The lock request will be pending. 328 // The lock request will be pending.
294 EXPECT_FALSE(result.has_value()); 329 EXPECT_FALSE(result.has_value());
330 #else
331 EXPECT_EQ(ScreenOrientationLockResult::
332 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
333 result);
334 #endif
295 // Delegate did apply lock once. 335 // Delegate did apply lock once.
296 EXPECT_EQ(1, delegate.lock_count()); 336 EXPECT_EQ(1, delegate.lock_count());
297 EXPECT_EQ(0, delegate.unlock_count()); 337 EXPECT_EQ(0, delegate.unlock_count());
298 338
299 // Simulates exiting full screen. 339 // Simulates exiting full screen.
300 main_test_rfh()->OnMessageReceived( 340 main_test_rfh()->OnMessageReceived(
301 FrameHostMsg_ToggleFullscreen(main_test_rfh()->GetRoutingID(), false)); 341 FrameHostMsg_ToggleFullscreen(main_test_rfh()->GetRoutingID(), false));
302 ASSERT_FALSE(contents()->IsFullscreenForCurrentTab()); 342 ASSERT_FALSE(contents()->IsFullscreenForCurrentTab());
303 // The pending lock request is cancelled. 343 // The pending lock request is cancelled.
304 EXPECT_EQ(ScreenOrientationLockResult:: 344 EXPECT_EQ(ScreenOrientationLockResult::
(...skipping 11 matching lines...) Expand all
316 356
317 // Navigate to a site. 357 // Navigate to a site.
318 const GURL url("http://www.google.com"); 358 const GURL url("http://www.google.com");
319 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED, 359 controller().LoadURL(url, Referrer(), ui::PAGE_TRANSITION_TYPED,
320 std::string()); 360 std::string());
321 361
322 base::Optional<ScreenOrientationLockResult> result; 362 base::Optional<ScreenOrientationLockResult> result;
323 CallLockAndGetResult(blink::WebScreenOrientationLockType:: 363 CallLockAndGetResult(blink::WebScreenOrientationLockType::
324 WebScreenOrientationLockLandscapeSecondary, 364 WebScreenOrientationLockLandscapeSecondary,
325 &result); 365 &result);
366 #if defined(OS_ANDROID)
326 // The lock request will be pending. 367 // The lock request will be pending.
327 EXPECT_FALSE(result.has_value()); 368 EXPECT_FALSE(result.has_value());
369 #else
370 EXPECT_EQ(ScreenOrientationLockResult::
371 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
372 result);
373 #endif
328 // Delegate did apply lock once. 374 // Delegate did apply lock once.
329 EXPECT_EQ(1, delegate.lock_count()); 375 EXPECT_EQ(1, delegate.lock_count());
330 EXPECT_EQ(0, delegate.unlock_count()); 376 EXPECT_EQ(0, delegate.unlock_count());
331 377
332 // Navigate to another site. 378 // Navigate to another site.
333 const GURL another_url("http://www.google.com/abc.html"); 379 const GURL another_url("http://www.google.com/abc.html");
334 contents()->NavigateAndCommit(another_url); 380 contents()->NavigateAndCommit(another_url);
335 // The pending lock request is cancelled. 381 // The pending lock request is cancelled.
336 EXPECT_EQ(ScreenOrientationLockResult:: 382 EXPECT_EQ(ScreenOrientationLockResult::
337 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED, 383 SCREEN_ORIENTATION_LOCK_RESULT_ERROR_CANCELED,
338 result); 384 result);
339 // Delegate did apply unlock once. 385 // Delegate did apply unlock once.
340 EXPECT_EQ(1, delegate.unlock_count()); 386 EXPECT_EQ(1, delegate.unlock_count());
341 } 387 }
342 388
343 } // namespace content 389 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/screen_orientation/screen_orientation_provider.cc ('k') | content/browser/web_contents/web_contents_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698