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

Side by Side Diff: ash/content/display/screen_orientation_controller_chromeos_unittest.cc

Issue 2906803002: Rename MaximizeMode to TabletMode (Closed)
Patch Set: updated filter Created 3 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 "ash/display/screen_orientation_controller_chromeos.h" 5 #include "ash/display/screen_orientation_controller_chromeos.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/content/shell_content_state.h" 11 #include "ash/content/shell_content_state.h"
12 #include "ash/display/screen_orientation_controller_chromeos.h" 12 #include "ash/display/screen_orientation_controller_chromeos.h"
13 #include "ash/shared/app_types.h" 13 #include "ash/shared/app_types.h"
14 #include "ash/shell.h" 14 #include "ash/shell.h"
15 #include "ash/system/screen_layout_observer.h" 15 #include "ash/system/screen_layout_observer.h"
16 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
17 #include "ash/test/ash_test_environment_content.h" 17 #include "ash/test/ash_test_environment_content.h"
18 #include "ash/test/ash_test_helper.h" 18 #include "ash/test/ash_test_helper.h"
19 #include "ash/test/content/test_shell_content_state.h" 19 #include "ash/test/content/test_shell_content_state.h"
20 #include "ash/test/screen_orientation_controller_test_api.h" 20 #include "ash/test/screen_orientation_controller_test_api.h"
21 #include "ash/test/test_shell_delegate.h" 21 #include "ash/test/test_shell_delegate.h"
22 #include "ash/test/test_system_tray_delegate.h" 22 #include "ash/test/test_system_tray_delegate.h"
23 #include "ash/wm/maximize_mode/maximize_mode_controller.h" 23 #include "ash/wm/tablet_mode/tablet_mode_controller.h"
24 #include "ash/wm/window_state.h" 24 #include "ash/wm/window_state.h"
25 #include "ash/wm_window.h" 25 #include "ash/wm_window.h"
26 #include "base/command_line.h" 26 #include "base/command_line.h"
27 #include "chromeos/accelerometer/accelerometer_reader.h" 27 #include "chromeos/accelerometer/accelerometer_reader.h"
28 #include "chromeos/accelerometer/accelerometer_types.h" 28 #include "chromeos/accelerometer/accelerometer_types.h"
29 #include "content/public/browser/browser_context.h" 29 #include "content/public/browser/browser_context.h"
30 #include "content/public/browser/web_contents.h" 30 #include "content/public/browser/web_contents.h"
31 #include "content/public/test/test_browser_context.h" 31 #include "content/public/test/test_browser_context.h"
32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h" 32 #include "third_party/WebKit/public/platform/modules/screen_orientation/WebScree nOrientationLockType.h"
33 #include "ui/aura/window.h" 33 #include "ui/aura/window.h"
(...skipping 15 matching lines...) Expand all
49 const float kDegreesToRadians = 3.1415926f / 180.0f; 49 const float kDegreesToRadians = 3.1415926f / 180.0f;
50 const float kMeanGravity = -9.8066f; 50 const float kMeanGravity = -9.8066f;
51 51
52 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id, 52 display::ManagedDisplayInfo CreateDisplayInfo(int64_t id,
53 const gfx::Rect& bounds) { 53 const gfx::Rect& bounds) {
54 display::ManagedDisplayInfo info(id, "dummy", false); 54 display::ManagedDisplayInfo info(id, "dummy", false);
55 info.SetBounds(bounds); 55 info.SetBounds(bounds);
56 return info; 56 return info;
57 } 57 }
58 58
59 void EnableMaximizeMode(bool enable) { 59 void EnableTabletMode(bool enable) {
60 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 60 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(enable);
61 enable);
62 } 61 }
63 62
64 bool RotationLocked() { 63 bool RotationLocked() {
65 return Shell::Get()->screen_orientation_controller()->rotation_locked(); 64 return Shell::Get()->screen_orientation_controller()->rotation_locked();
66 } 65 }
67 66
68 bool UserRotationLocked() { 67 bool UserRotationLocked() {
69 return Shell::Get()->screen_orientation_controller()->user_rotation_locked(); 68 return Shell::Get()->screen_orientation_controller()->user_rotation_locked();
70 } 69 }
71 70
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 activation_client->ActivateWindow(focus_window2.get()); 352 activation_client->ActivateWindow(focus_window2.get());
354 EXPECT_FALSE(RotationLocked()); 353 EXPECT_FALSE(RotationLocked());
355 354
356 activation_client->ActivateWindow(focus_window1.get()); 355 activation_client->ActivateWindow(focus_window1.get());
357 EXPECT_FALSE(RotationLocked()); 356 EXPECT_FALSE(RotationLocked());
358 } 357 }
359 358
360 // Tests that accelerometer readings in each of the screen angles will trigger a 359 // Tests that accelerometer readings in each of the screen angles will trigger a
361 // rotation of the internal display. 360 // rotation of the internal display.
362 TEST_F(ScreenOrientationControllerTest, DisplayRotation) { 361 TEST_F(ScreenOrientationControllerTest, DisplayRotation) {
363 EnableMaximizeMode(true); 362 EnableTabletMode(true);
364 // Now test rotating in all directions. 363 // Now test rotating in all directions.
365 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 364 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
366 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 365 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
367 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 366 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
368 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 367 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
369 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 368 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
370 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 369 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
371 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 370 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
372 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 371 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
373 } 372 }
374 373
375 // Tests that low angles are ignored by the accelerometer (i.e. when the device 374 // Tests that low angles are ignored by the accelerometer (i.e. when the device
376 // is almost laying flat). 375 // is almost laying flat).
377 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) { 376 TEST_F(ScreenOrientationControllerTest, RotationIgnoresLowAngles) {
378 EnableMaximizeMode(true); 377 EnableTabletMode(true);
379 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity)); 378 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, -kMeanGravity));
380 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 379 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
381 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity)); 380 TriggerLidUpdate(gfx::Vector3dF(-2.0f, 0.0f, -kMeanGravity));
382 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 381 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
383 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity)); 382 TriggerLidUpdate(gfx::Vector3dF(0.0f, 2.0f, -kMeanGravity));
384 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 383 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
385 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity)); 384 TriggerLidUpdate(gfx::Vector3dF(2.0f, 0.0f, -kMeanGravity));
386 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 385 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
387 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity)); 386 TriggerLidUpdate(gfx::Vector3dF(0.0f, -2.0f, -kMeanGravity));
388 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 387 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
389 } 388 }
390 389
391 // Tests that the display will stick to the current orientation beyond the 390 // Tests that the display will stick to the current orientation beyond the
392 // halfway point, preventing frequent updates back and forth. 391 // halfway point, preventing frequent updates back and forth.
393 TEST_F(ScreenOrientationControllerTest, RotationSticky) { 392 TEST_F(ScreenOrientationControllerTest, RotationSticky) {
394 EnableMaximizeMode(true); 393 EnableTabletMode(true);
395 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f); 394 gfx::Vector3dF gravity(0.0f, -kMeanGravity, 0.0f);
396 TriggerLidUpdate(gravity); 395 TriggerLidUpdate(gravity);
397 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 396 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
398 397
399 // Turn past half-way point to next direction and rotation should remain 398 // Turn past half-way point to next direction and rotation should remain
400 // the same. 399 // the same.
401 float degrees = 50.0; 400 float degrees = 50.0;
402 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 401 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
403 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 402 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
404 TriggerLidUpdate(gravity); 403 TriggerLidUpdate(gravity);
(...skipping 11 matching lines...) Expand all
416 degrees = 40.0; 415 degrees = 40.0;
417 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity); 416 gravity.set_x(-sin(degrees * kDegreesToRadians) * kMeanGravity);
418 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity); 417 gravity.set_y(-cos(degrees * kDegreesToRadians) * kMeanGravity);
419 TriggerLidUpdate(gravity); 418 TriggerLidUpdate(gravity);
420 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 419 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
421 } 420 }
422 421
423 // Tests that the display will stick to its current orientation when the 422 // Tests that the display will stick to its current orientation when the
424 // rotation lock has been set. 423 // rotation lock has been set.
425 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) { 424 TEST_F(ScreenOrientationControllerTest, RotationLockPreventsRotation) {
426 EnableMaximizeMode(true); 425 EnableTabletMode(true);
427 SetUserRotationLocked(true); 426 SetUserRotationLocked(true);
428 427
429 // Turn past the threshold for rotation. 428 // Turn past the threshold for rotation.
430 float degrees = 90.0; 429 float degrees = 90.0;
431 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity, 430 gfx::Vector3dF gravity(-sin(degrees * kDegreesToRadians) * kMeanGravity,
432 -cos(degrees * kDegreesToRadians) * kMeanGravity, 431 -cos(degrees * kDegreesToRadians) * kMeanGravity,
433 0.0f); 432 0.0f);
434 TriggerLidUpdate(gravity); 433 TriggerLidUpdate(gravity);
435 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 434 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
436 435
437 SetUserRotationLocked(false); 436 SetUserRotationLocked(false);
438 TriggerLidUpdate(gravity); 437 TriggerLidUpdate(gravity);
439 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 438 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
440 } 439 }
441 440
442 // The ScreenLayoutObserver class that is responsible for adding/updating 441 // The ScreenLayoutObserver class that is responsible for adding/updating
443 // MessageCenter notifications is only added to the SystemTray on ChromeOS. 442 // MessageCenter notifications is only added to the SystemTray on ChromeOS.
444 // Tests that the screen rotation notifications are suppressed when 443 // Tests that the screen rotation notifications are suppressed when
445 // triggered by the accelerometer. 444 // triggered by the accelerometer.
446 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) { 445 TEST_F(ScreenOrientationControllerTest, BlockRotationNotifications) {
447 EnableMaximizeMode(true); 446 EnableTabletMode(true);
448 Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing( 447 Shell::Get()->screen_layout_observer()->set_show_notifications_for_testing(
449 true); 448 true);
450 display::test::DisplayManagerTestApi(display_manager()) 449 display::test::DisplayManagerTestApi(display_manager())
451 .SetFirstDisplayAsInternalDisplay(); 450 .SetFirstDisplayAsInternalDisplay();
452 451
453 message_center::MessageCenter* message_center = 452 message_center::MessageCenter* message_center =
454 message_center::MessageCenter::Get(); 453 message_center::MessageCenter::Get();
455 454
456 EXPECT_EQ(0u, message_center->NotificationCount()); 455 EXPECT_EQ(0u, message_center->NotificationCount());
457 EXPECT_FALSE(message_center->HasPopupNotifications()); 456 EXPECT_FALSE(message_center->HasPopupNotifications());
458 457
459 // Make sure notifications are still displayed when 458 // Make sure notifications are still displayed when
460 // adjusting the screen rotation directly when in maximize mode 459 // adjusting the screen rotation directly when in tablet mode
461 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 460 ASSERT_NE(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
462 SetInternalDisplayRotation(display::Display::ROTATE_270); 461 SetInternalDisplayRotation(display::Display::ROTATE_270);
463 SetSystemRotationLocked(false); 462 SetSystemRotationLocked(false);
464 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 463 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
465 EXPECT_EQ(1u, message_center->NotificationCount()); 464 EXPECT_EQ(1u, message_center->NotificationCount());
466 EXPECT_TRUE(message_center->HasPopupNotifications()); 465 EXPECT_TRUE(message_center->HasPopupNotifications());
467 466
468 // Clear all notifications 467 // Clear all notifications
469 message_center->RemoveAllNotifications( 468 message_center->RemoveAllNotifications(
470 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); 469 false /* by_user */, message_center::MessageCenter::RemoveType::ALL);
471 EXPECT_EQ(0u, message_center->NotificationCount()); 470 EXPECT_EQ(0u, message_center->NotificationCount());
472 EXPECT_FALSE(message_center->HasPopupNotifications()); 471 EXPECT_FALSE(message_center->HasPopupNotifications());
473 472
474 // Make sure notifications are blocked when adjusting the screen rotation 473 // Make sure notifications are blocked when adjusting the screen rotation
475 // via the accelerometer while in maximize mode 474 // via the accelerometer while in tablet mode
476 // Rotate the screen 90 degrees 475 // Rotate the screen 90 degrees
477 ASSERT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 476 ASSERT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
478 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 477 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
479 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 478 ASSERT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
480 EXPECT_EQ(0u, message_center->NotificationCount()); 479 EXPECT_EQ(0u, message_center->NotificationCount());
481 EXPECT_FALSE(message_center->HasPopupNotifications()); 480 EXPECT_FALSE(message_center->HasPopupNotifications());
482 481
483 // Make sure notifications are still displayed when 482 // Make sure notifications are still displayed when
484 // adjusting the screen rotation directly when not in maximize mode 483 // adjusting the screen rotation directly when not in tablet mode
485 EnableMaximizeMode(false); 484 EnableTabletMode(false);
486 // Reset the screen rotation. 485 // Reset the screen rotation.
487 SetInternalDisplayRotation(display::Display::ROTATE_0); 486 SetInternalDisplayRotation(display::Display::ROTATE_0);
488 // Clear all notifications 487 // Clear all notifications
489 message_center->RemoveAllNotifications( 488 message_center->RemoveAllNotifications(
490 false /* by_user */, message_center::MessageCenter::RemoveType::ALL); 489 false /* by_user */, message_center::MessageCenter::RemoveType::ALL);
491 ASSERT_NE(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 490 ASSERT_NE(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
492 ASSERT_EQ(0u, message_center->NotificationCount()); 491 ASSERT_EQ(0u, message_center->NotificationCount());
493 ASSERT_FALSE(message_center->HasPopupNotifications()); 492 ASSERT_FALSE(message_center->HasPopupNotifications());
494 SetInternalDisplayRotation(display::Display::ROTATE_180); 493 SetInternalDisplayRotation(display::Display::ROTATE_180);
495 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 494 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
496 EXPECT_EQ(1u, message_center->NotificationCount()); 495 EXPECT_EQ(1u, message_center->NotificationCount());
497 EXPECT_TRUE(message_center->HasPopupNotifications()); 496 EXPECT_TRUE(message_center->HasPopupNotifications());
498 } 497 }
499 498
500 // Tests that if a user has set a display rotation that it is restored upon 499 // Tests that if a user has set a display rotation that it is restored upon
501 // exiting maximize mode. 500 // exiting tablet mode.
502 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) { 501 TEST_F(ScreenOrientationControllerTest, ResetUserRotationUponExit) {
503 display::test::DisplayManagerTestApi(display_manager()) 502 display::test::DisplayManagerTestApi(display_manager())
504 .SetFirstDisplayAsInternalDisplay(); 503 .SetFirstDisplayAsInternalDisplay();
505 504
506 SetInternalDisplayRotation(display::Display::ROTATE_90); 505 SetInternalDisplayRotation(display::Display::ROTATE_90);
507 EnableMaximizeMode(true); 506 EnableTabletMode(true);
508 507
509 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 508 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
510 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 509 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
511 510
512 EnableMaximizeMode(false); 511 EnableTabletMode(false);
513 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 512 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
514 } 513 }
515 514
516 // Tests that if a user sets a display rotation that accelerometer rotation 515 // Tests that if a user sets a display rotation that accelerometer rotation
517 // becomes locked. 516 // becomes locked.
518 TEST_F(ScreenOrientationControllerTest, 517 TEST_F(ScreenOrientationControllerTest,
519 NonAccelerometerRotationChangesLockRotation) { 518 NonAccelerometerRotationChangesLockRotation) {
520 EnableMaximizeMode(true); 519 EnableTabletMode(true);
521 ASSERT_FALSE(RotationLocked()); 520 ASSERT_FALSE(RotationLocked());
522 SetInternalDisplayRotation(display::Display::ROTATE_270); 521 SetInternalDisplayRotation(display::Display::ROTATE_270);
523 EXPECT_TRUE(RotationLocked()); 522 EXPECT_TRUE(RotationLocked());
524 } 523 }
525 524
526 // Tests that if a user changes the display rotation, while rotation is locked, 525 // Tests that if a user changes the display rotation, while rotation is locked,
527 // that the updates are recorded. Upon exiting maximize mode the latest user 526 // that the updates are recorded. Upon exiting tablet mode the latest user
528 // rotation should be applied. 527 // rotation should be applied.
529 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) { 528 TEST_F(ScreenOrientationControllerTest, UpdateUserRotationWhileRotationLocked) {
530 EnableMaximizeMode(true); 529 EnableTabletMode(true);
531 SetInternalDisplayRotation(display::Display::ROTATE_270); 530 SetInternalDisplayRotation(display::Display::ROTATE_270);
532 // User sets rotation to the same rotation that the display was at when 531 // User sets rotation to the same rotation that the display was at when
533 // maximize mode was activated. 532 // tablet mode was activated.
534 SetInternalDisplayRotation(display::Display::ROTATE_0); 533 SetInternalDisplayRotation(display::Display::ROTATE_0);
535 EnableMaximizeMode(false); 534 EnableTabletMode(false);
536 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 535 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
537 } 536 }
538 537
539 // Tests that when the orientation lock is set to Landscape, that rotation can 538 // Tests that when the orientation lock is set to Landscape, that rotation can
540 // be done between the two angles of the orientation. 539 // be done between the two angles of the orientation.
541 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) { 540 TEST_F(ScreenOrientationControllerTest, LandscapeOrientationAllowsRotation) {
542 std::unique_ptr<content::WebContents> content(CreateWebContents()); 541 std::unique_ptr<content::WebContents> content(CreateWebContents());
543 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); 542 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
544 EnableMaximizeMode(true); 543 EnableTabletMode(true);
545 544
546 AttachAndActivateWebContents(content.get(), focus_window.get()); 545 AttachAndActivateWebContents(content.get(), focus_window.get());
547 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); 546 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
548 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 547 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
549 EXPECT_TRUE(RotationLocked()); 548 EXPECT_TRUE(RotationLocked());
550 549
551 // Inverse of orientation is allowed 550 // Inverse of orientation is allowed
552 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 551 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
553 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 552 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
554 553
555 // Display rotations between are not allowed 554 // Display rotations between are not allowed
556 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 555 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
557 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 556 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
558 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f)); 557 TriggerLidUpdate(gfx::Vector3dF(-kMeanGravity, 0.0f, 0.0f));
559 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation()); 558 EXPECT_EQ(display::Display::ROTATE_180, GetCurrentInternalDisplayRotation());
560 } 559 }
561 560
562 // Tests that when the orientation lock is set to Portrait, that rotaiton can be 561 // Tests that when the orientation lock is set to Portrait, that rotaiton can be
563 // done between the two angles of the orientation. 562 // done between the two angles of the orientation.
564 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) { 563 TEST_F(ScreenOrientationControllerTest, PortraitOrientationAllowsRotation) {
565 std::unique_ptr<content::WebContents> content(CreateWebContents()); 564 std::unique_ptr<content::WebContents> content(CreateWebContents());
566 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); 565 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
567 EnableMaximizeMode(true); 566 EnableTabletMode(true);
568 567
569 AttachAndActivateWebContents(content.get(), focus_window.get()); 568 AttachAndActivateWebContents(content.get(), focus_window.get());
570 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockPortrait); 569 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockPortrait);
571 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 570 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
572 EXPECT_TRUE(RotationLocked()); 571 EXPECT_TRUE(RotationLocked());
573 572
574 // Inverse of orientation is allowed 573 // Inverse of orientation is allowed
575 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 574 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
576 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 575 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
577 576
578 // Display rotations between are not allowed 577 // Display rotations between are not allowed
579 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 578 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
580 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 579 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
581 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 580 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
582 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation()); 581 EXPECT_EQ(display::Display::ROTATE_270, GetCurrentInternalDisplayRotation());
583 } 582 }
584 583
585 // Tests that for an orientation lock which does not allow rotation, that the 584 // Tests that for an orientation lock which does not allow rotation, that the
586 // display rotation remains constant. 585 // display rotation remains constant.
587 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) { 586 TEST_F(ScreenOrientationControllerTest, OrientationLockDisallowsRotation) {
588 std::unique_ptr<content::WebContents> content(CreateWebContents()); 587 std::unique_ptr<content::WebContents> content(CreateWebContents());
589 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); 588 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
590 EnableMaximizeMode(true); 589 EnableTabletMode(true);
591 590
592 AttachAndActivateWebContents(content.get(), focus_window.get()); 591 AttachAndActivateWebContents(content.get(), focus_window.get());
593 delegate()->Lock(content.get(), 592 delegate()->Lock(content.get(),
594 blink::kWebScreenOrientationLockPortraitPrimary); 593 blink::kWebScreenOrientationLockPortraitPrimary);
595 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 594 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
596 EXPECT_TRUE(RotationLocked()); 595 EXPECT_TRUE(RotationLocked());
597 596
598 // Rotation does not change. 597 // Rotation does not change.
599 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f)); 598 TriggerLidUpdate(gfx::Vector3dF(kMeanGravity, 0.0f, 0.0f));
600 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 599 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
601 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 600 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
602 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 601 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
603 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f)); 602 TriggerLidUpdate(gfx::Vector3dF(0.0f, -kMeanGravity, 0.0f));
604 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 603 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
605 } 604 }
606 605
607 // Tests that after a content::WebContents has applied an orientation lock which 606 // Tests that after a content::WebContents has applied an orientation lock which
608 // supports rotation, that a user rotation lock does not allow rotation. 607 // supports rotation, that a user rotation lock does not allow rotation.
609 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) { 608 TEST_F(ScreenOrientationControllerTest, UserRotationLockDisallowsRotation) {
610 std::unique_ptr<content::WebContents> content(CreateWebContents()); 609 std::unique_ptr<content::WebContents> content(CreateWebContents());
611 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0)); 610 std::unique_ptr<aura::Window> focus_window(CreateAppWindowInShellWithId(0));
612 EnableMaximizeMode(true); 611 EnableTabletMode(true);
613 612
614 AttachAndActivateWebContents(content.get(), focus_window.get()); 613 AttachAndActivateWebContents(content.get(), focus_window.get());
615 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape); 614 delegate()->Lock(content.get(), blink::kWebScreenOrientationLockLandscape);
616 delegate()->Unlock(content.get()); 615 delegate()->Unlock(content.get());
617 616
618 SetUserRotationLocked(true); 617 SetUserRotationLocked(true);
619 EXPECT_TRUE(RotationLocked()); 618 EXPECT_TRUE(RotationLocked());
620 EXPECT_TRUE(UserRotationLocked()); 619 EXPECT_TRUE(UserRotationLocked());
621 620
622 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 621 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
623 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f)); 622 TriggerLidUpdate(gfx::Vector3dF(0.0f, kMeanGravity, 0.0f));
624 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 623 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
625 } 624 }
626 625
627 // Tests that when MaximizeMode is triggered before the internal display is 626 // Tests that when TabletMode is triggered before the internal display is
628 // ready, that ScreenOrientationController still begins listening to events, 627 // ready, that ScreenOrientationController still begins listening to events,
629 // which require an internal display to be acted upon. 628 // which require an internal display to be acted upon.
630 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) { 629 TEST_F(ScreenOrientationControllerTest, InternalDisplayNotAvailableAtStartup) {
631 display::test::DisplayManagerTestApi(display_manager()) 630 display::test::DisplayManagerTestApi(display_manager())
632 .SetFirstDisplayAsInternalDisplay(); 631 .SetFirstDisplayAsInternalDisplay();
633 632
634 int64_t internal_display_id = display::Display::InternalDisplayId(); 633 int64_t internal_display_id = display::Display::InternalDisplayId();
635 display::Display::SetInternalDisplayId(display::kInvalidDisplayId); 634 display::Display::SetInternalDisplayId(display::kInvalidDisplayId);
636 635
637 EnableMaximizeMode(true); 636 EnableTabletMode(true);
638 637
639 // Should not crash, even though there is no internal display. 638 // Should not crash, even though there is no internal display.
640 SetDisplayRotationById(internal_display_id, display::Display::ROTATE_180); 639 SetDisplayRotationById(internal_display_id, display::Display::ROTATE_180);
641 EXPECT_FALSE(RotationLocked()); 640 EXPECT_FALSE(RotationLocked());
642 641
643 // Should not crash, even though the invalid display id is requested. 642 // Should not crash, even though the invalid display id is requested.
644 SetDisplayRotationById(display::kInvalidDisplayId, 643 SetDisplayRotationById(display::kInvalidDisplayId,
645 display::Display::ROTATE_180); 644 display::Display::ROTATE_180);
646 EXPECT_FALSE(RotationLocked()); 645 EXPECT_FALSE(RotationLocked());
647 646
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape); 791 delegate()->Lock(content2.get(), blink::kWebScreenOrientationLockLandscape);
793 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation()); 792 EXPECT_EQ(display::Display::ROTATE_0, GetCurrentInternalDisplayRotation());
794 793
795 delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny); 794 delegate()->Lock(content1.get(), blink::kWebScreenOrientationLockAny);
796 activation_client->ActivateWindow(focus_window1.get()); 795 activation_client->ActivateWindow(focus_window1.get());
797 // Switching back to any will rotate to user rotation. 796 // Switching back to any will rotate to user rotation.
798 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation()); 797 EXPECT_EQ(display::Display::ROTATE_90, GetCurrentInternalDisplayRotation());
799 } 798 }
800 799
801 } // namespace ash 800 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698