| 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 <vector> |
| 6 |
| 5 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 6 #include "ash/content/display/screen_orientation_controller_chromeos.h" | 8 #include "ash/content/display/screen_orientation_controller_chromeos.h" |
| 7 #include "ash/display/display_info.h" | 9 #include "ash/display/display_info.h" |
| 8 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/test/ash_test_helper.h" | 13 #include "ash/test/ash_test_helper.h" |
| 14 #include "ash/test/display_manager_test_api.h" |
| 12 #include "ash/test/test_shell_delegate.h" | 15 #include "ash/test/test_shell_delegate.h" |
| 13 #include "ash/test/test_system_tray_delegate.h" | 16 #include "ash/test/test_system_tray_delegate.h" |
| 14 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 17 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 15 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 16 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 17 #include "chromeos/accelerometer/accelerometer_reader.h" | 20 #include "chromeos/accelerometer/accelerometer_reader.h" |
| 18 #include "chromeos/accelerometer/accelerometer_types.h" | 21 #include "chromeos/accelerometer/accelerometer_types.h" |
| 19 #include "content/public/browser/browser_context.h" | 22 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/test/test_browser_context.h" | 24 #include "content/public/test/test_browser_context.h" |
| 22 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" | 25 #include "third_party/WebKit/public/platform/WebScreenOrientationLockType.h" |
| 23 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 24 #include "ui/gfx/display.h" | 27 #include "ui/gfx/display.h" |
| 25 #include "ui/message_center/message_center.h" | 28 #include "ui/message_center/message_center.h" |
| 26 #include "ui/views/test/webview_test_helper.h" | 29 #include "ui/views/test/webview_test_helper.h" |
| 27 #include "ui/views/view.h" | 30 #include "ui/views/view.h" |
| 28 #include "ui/views/views_delegate.h" | 31 #include "ui/views/views_delegate.h" |
| 29 #include "ui/wm/public/activation_client.h" | 32 #include "ui/wm/public/activation_client.h" |
| 30 | 33 |
| 31 namespace ash { | 34 namespace ash { |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 const float kDegreesToRadians = 3.1415926f / 180.0f; | 38 const float kDegreesToRadians = 3.1415926f / 180.0f; |
| 36 const float kMeanGravity = 9.8066f; | 39 const float kMeanGravity = 9.8066f; |
| 37 | 40 |
| 41 DisplayInfo CreateDisplayInfo(int64 id, const gfx::Rect& bounds) { |
| 42 DisplayInfo info(id, "dummy", false); |
| 43 info.SetBounds(bounds); |
| 44 return info; |
| 45 } |
| 46 |
| 38 void EnableMaximizeMode(bool enable) { | 47 void EnableMaximizeMode(bool enable) { |
| 39 Shell::GetInstance() | 48 Shell::GetInstance() |
| 40 ->maximize_mode_controller() | 49 ->maximize_mode_controller() |
| 41 ->EnableMaximizeModeWindowManager(enable); | 50 ->EnableMaximizeModeWindowManager(enable); |
| 42 } | 51 } |
| 43 | 52 |
| 44 bool RotationLocked() { | 53 bool RotationLocked() { |
| 45 return Shell::GetInstance() | 54 return Shell::GetInstance() |
| 46 ->screen_orientation_controller() | 55 ->screen_orientation_controller() |
| 47 ->rotation_locked(); | 56 ->rotation_locked(); |
| (...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 // Should not crash, even thought there is no internal display. | 597 // Should not crash, even thought there is no internal display. |
| 589 SetInternalDisplayRotation(gfx::Display::ROTATE_180); | 598 SetInternalDisplayRotation(gfx::Display::ROTATE_180); |
| 590 EXPECT_FALSE(RotationLocked()); | 599 EXPECT_FALSE(RotationLocked()); |
| 591 | 600 |
| 592 // With an internal display now available, functionality should resume. | 601 // With an internal display now available, functionality should resume. |
| 593 gfx::Display::SetInternalDisplayId(internal_display_id); | 602 gfx::Display::SetInternalDisplayId(internal_display_id); |
| 594 SetInternalDisplayRotation(gfx::Display::ROTATE_90); | 603 SetInternalDisplayRotation(gfx::Display::ROTATE_90); |
| 595 EXPECT_TRUE(RotationLocked()); | 604 EXPECT_TRUE(RotationLocked()); |
| 596 } | 605 } |
| 597 | 606 |
| 607 // Verifies rotating an inactive Display is sucessful. |
| 608 TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplay) { |
| 609 const int64 kInternalDisplayId = 9; |
| 610 const int64 kExternalDisplayId = 10; |
| 611 const gfx::Display::Rotation kNewRotation = gfx::Display::ROTATE_180; |
| 612 |
| 613 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 614 |
| 615 const DisplayInfo internal_display_info = |
| 616 CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500)); |
| 617 const DisplayInfo external_display_info = |
| 618 CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500)); |
| 619 |
| 620 std::vector<DisplayInfo> display_info_list_two_active; |
| 621 display_info_list_two_active.push_back(internal_display_info); |
| 622 display_info_list_two_active.push_back(external_display_info); |
| 623 |
| 624 std::vector<DisplayInfo> display_info_list_one_active; |
| 625 display_info_list_one_active.push_back(external_display_info); |
| 626 |
| 627 // The DisplayInfo list with two active displays needs to be added first so |
| 628 // that the DisplayManager can track the |internal_display_info| as inactive |
| 629 // instead of non-existent. |
| 630 ash::Shell::GetInstance()->display_manager()->UpdateDisplays( |
| 631 display_info_list_two_active); |
| 632 ash::Shell::GetInstance()->display_manager()->UpdateDisplays( |
| 633 display_info_list_one_active); |
| 634 |
| 635 test::DisplayManagerTestApi(display_manager) |
| 636 .SetInternalDisplayId(kInternalDisplayId); |
| 637 |
| 638 ASSERT_NE(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId) |
| 639 .GetActiveRotation()); |
| 640 |
| 641 delegate()->SetDisplayRotation(kNewRotation, |
| 642 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 643 |
| 644 // TODO(bruthig): Uncomment when www.crbug.com/480703 is fixed. This test |
| 645 // still adds value by ensuring a crash does not occur. See |
| 646 // www.crbug.com/479503. |
| 647 // ASSERT_EQ(kNewRotation, display_manager->GetDisplayInfo(kInternalDisplayId) |
| 648 // .GetActiveRotation()); |
| 649 } |
| 650 |
| 598 } // namespace ash | 651 } // namespace ash |
| OLD | NEW |