Chromium Code Reviews| 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" |
| 12 #include "ash/test/test_shell_delegate.h" | 14 #include "ash/test/test_shell_delegate.h" |
| 13 #include "ash/test/test_system_tray_delegate.h" | 15 #include "ash/test/test_system_tray_delegate.h" |
| 14 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | 16 #include "ash/wm/maximize_mode/maximize_mode_controller.h" |
| 15 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/strings/stringprintf.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 gfx::Display::Rotation GetInternalDisplayRotation() { | 53 gfx::Display::Rotation GetInternalDisplayRotation() { |
| 45 return Shell::GetInstance() | 54 return Shell::GetInstance() |
| 46 ->display_manager() | 55 ->display_manager() |
| 47 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 56 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 601 // Should not crash, even thought there is no internal display. | 610 // Should not crash, even thought there is no internal display. |
| 602 SetInternalDisplayRotation(gfx::Display::ROTATE_180); | 611 SetInternalDisplayRotation(gfx::Display::ROTATE_180); |
| 603 EXPECT_FALSE(RotationLocked()); | 612 EXPECT_FALSE(RotationLocked()); |
| 604 | 613 |
| 605 // With an internal display now available, functionality should resume. | 614 // With an internal display now available, functionality should resume. |
| 606 gfx::Display::SetInternalDisplayId(internal_display_id); | 615 gfx::Display::SetInternalDisplayId(internal_display_id); |
| 607 SetInternalDisplayRotation(gfx::Display::ROTATE_90); | 616 SetInternalDisplayRotation(gfx::Display::ROTATE_90); |
| 608 EXPECT_TRUE(RotationLocked()); | 617 EXPECT_TRUE(RotationLocked()); |
| 609 } | 618 } |
| 610 | 619 |
| 620 // Verifies that rotating an inactive Display does not crash. See | |
| 621 // www.crbug.com/479503. | |
| 622 TEST_F(ScreenOrientationControllerTest, RotateInactiveDisplayShouldNotCrash) { | |
| 623 const int64 kInternalDisplayId = gfx::Display::InternalDisplayId(); | |
| 624 const int64 kExternalDisplayId = 10; | |
|
jonross
2015/04/24 14:18:08
Can this ever be the id of the internal display? I
bruthig
2015/04/24 16:17:13
Originally I had the assert to verify that kIntern
| |
| 625 const gfx::Display::Rotation kNewRotation = gfx::Display::ROTATE_180; | |
| 626 | |
| 627 ASSERT_NE(kInternalDisplayId, gfx::Display::kInvalidDisplayID); | |
| 628 ASSERT_NE(Shell::GetInstance() | |
| 629 ->display_manager() | |
| 630 ->GetDisplayInfo(kInternalDisplayId) | |
| 631 .rotation(), | |
| 632 kNewRotation); | |
| 633 | |
| 634 const DisplayInfo internal_display_info = | |
| 635 CreateDisplayInfo(kInternalDisplayId, gfx::Rect(0, 0, 500, 500)); | |
| 636 const DisplayInfo external_display_info = | |
| 637 CreateDisplayInfo(kExternalDisplayId, gfx::Rect(1, 1, 500, 500)); | |
| 638 | |
| 639 std::vector<DisplayInfo> display_info_list_two_active; | |
| 640 display_info_list_two_active.push_back(internal_display_info); | |
| 641 display_info_list_two_active.push_back(external_display_info); | |
| 642 | |
| 643 std::vector<DisplayInfo> display_info_list_one_active; | |
| 644 display_info_list_one_active.push_back(external_display_info); | |
| 645 | |
| 646 // The DisplayInfo list with two active displays needs to be added first so | |
| 647 // that the DisplayManager can track the |internal_display_info| as inactive | |
| 648 // instead of non-existent. | |
| 649 ash::Shell::GetInstance()->display_manager()->UpdateDisplays( | |
| 650 display_info_list_two_active); | |
| 651 ash::Shell::GetInstance()->display_manager()->UpdateDisplays( | |
| 652 display_info_list_one_active); | |
| 653 | |
| 654 delegate()->SetDisplayRotation(kNewRotation); | |
| 655 } | |
| 656 | |
| 611 } // namespace ash | 657 } // namespace ash |
| OLD | NEW |