| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/screen_ash.h" | 5 #include "ash/screen_util.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 12 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 17 #include "ui/views/widget/widget_delegate.h" | 17 #include "ui/views/widget/widget_delegate.h" |
| 18 | 18 |
| 19 namespace ash { | 19 namespace ash { |
| 20 namespace test { | 20 namespace test { |
| 21 | 21 |
| 22 typedef test::AshTestBase ScreenAshTest; | 22 typedef test::AshTestBase ScreenUtilTest; |
| 23 | 23 |
| 24 TEST_F(ScreenAshTest, Bounds) { | 24 TEST_F(ScreenUtilTest, Bounds) { |
| 25 if (!SupportsMultipleDisplays()) | 25 if (!SupportsMultipleDisplays()) |
| 26 return; | 26 return; |
| 27 | 27 |
| 28 UpdateDisplay("600x600,500x500"); | 28 UpdateDisplay("600x600,500x500"); |
| 29 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> | 29 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager()-> |
| 30 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 30 SetAutoHideBehavior(ash::SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 31 | 31 |
| 32 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 32 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 33 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 33 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
| 34 primary->Show(); | 34 primary->Show(); |
| 35 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 35 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 36 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 36 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 37 secondary->Show(); | 37 secondary->Show(); |
| 38 | 38 |
| 39 // Maximized bounds | 39 // Maximized bounds |
| 40 EXPECT_EQ("0,0 600x597", | 40 EXPECT_EQ("0,0 600x597", |
| 41 ScreenAsh::GetMaximizedWindowBoundsInParent( | 41 ScreenUtil::GetMaximizedWindowBoundsInParent( |
| 42 primary->GetNativeView()).ToString()); | 42 primary->GetNativeView()).ToString()); |
| 43 EXPECT_EQ("0,0 500x453", | 43 EXPECT_EQ("0,0 500x453", |
| 44 ScreenAsh::GetMaximizedWindowBoundsInParent( | 44 ScreenUtil::GetMaximizedWindowBoundsInParent( |
| 45 secondary->GetNativeView()).ToString()); | 45 secondary->GetNativeView()).ToString()); |
| 46 | 46 |
| 47 // Display bounds | 47 // Display bounds |
| 48 EXPECT_EQ("0,0 600x600", | 48 EXPECT_EQ("0,0 600x600", |
| 49 ScreenAsh::GetDisplayBoundsInParent( | 49 ScreenUtil::GetDisplayBoundsInParent( |
| 50 primary->GetNativeView()).ToString()); | 50 primary->GetNativeView()).ToString()); |
| 51 EXPECT_EQ("0,0 500x500", | 51 EXPECT_EQ("0,0 500x500", |
| 52 ScreenAsh::GetDisplayBoundsInParent( | 52 ScreenUtil::GetDisplayBoundsInParent( |
| 53 secondary->GetNativeView()).ToString()); | 53 secondary->GetNativeView()).ToString()); |
| 54 | 54 |
| 55 // Work area bounds | 55 // Work area bounds |
| 56 EXPECT_EQ("0,0 600x597", | 56 EXPECT_EQ("0,0 600x597", |
| 57 ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 57 ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 58 primary->GetNativeView()).ToString()); | 58 primary->GetNativeView()).ToString()); |
| 59 EXPECT_EQ("0,0 500x453", | 59 EXPECT_EQ("0,0 500x453", |
| 60 ScreenAsh::GetDisplayWorkAreaBoundsInParent( | 60 ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 61 secondary->GetNativeView()).ToString()); | 61 secondary->GetNativeView()).ToString()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 // Test verifies a stable handling of secondary screen widget changes | 64 // Test verifies a stable handling of secondary screen widget changes |
| 65 // (crbug.com/226132). | 65 // (crbug.com/226132). |
| 66 TEST_F(ScreenAshTest, StabilityTest) { | 66 TEST_F(ScreenUtilTest, StabilityTest) { |
| 67 if (!SupportsMultipleDisplays()) | 67 if (!SupportsMultipleDisplays()) |
| 68 return; | 68 return; |
| 69 | 69 |
| 70 UpdateDisplay("600x600,500x500"); | 70 UpdateDisplay("600x600,500x500"); |
| 71 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 71 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 72 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 72 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 73 EXPECT_EQ(Shell::GetAllRootWindows()[1], | 73 EXPECT_EQ(Shell::GetAllRootWindows()[1], |
| 74 secondary->GetNativeView()->GetRootWindow()); | 74 secondary->GetNativeView()->GetRootWindow()); |
| 75 secondary->Show(); | 75 secondary->Show(); |
| 76 secondary->Maximize(); | 76 secondary->Maximize(); |
| 77 secondary->Show(); | 77 secondary->Show(); |
| 78 secondary->SetFullscreen(true); | 78 secondary->SetFullscreen(true); |
| 79 secondary->Hide(); | 79 secondary->Hide(); |
| 80 secondary->Close(); | 80 secondary->Close(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(ScreenAshTest, ConvertRect) { | 83 TEST_F(ScreenUtilTest, ConvertRect) { |
| 84 if (!SupportsMultipleDisplays()) | 84 if (!SupportsMultipleDisplays()) |
| 85 return; | 85 return; |
| 86 | 86 |
| 87 UpdateDisplay("600x600,500x500"); | 87 UpdateDisplay("600x600,500x500"); |
| 88 | 88 |
| 89 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( | 89 views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 90 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); | 90 NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
| 91 primary->Show(); | 91 primary->Show(); |
| 92 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( | 92 views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 93 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); | 93 NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 94 secondary->Show(); | 94 secondary->Show(); |
| 95 | 95 |
| 96 EXPECT_EQ( | 96 EXPECT_EQ( |
| 97 "0,0 100x100", | 97 "0,0 100x100", |
| 98 ScreenAsh::ConvertRectFromScreen( | 98 ScreenUtil::ConvertRectFromScreen( |
| 99 primary->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString()); | 99 primary->GetNativeView(), gfx::Rect(10, 10, 100, 100)).ToString()); |
| 100 EXPECT_EQ( | 100 EXPECT_EQ( |
| 101 "10,10 100x100", | 101 "10,10 100x100", |
| 102 ScreenAsh::ConvertRectFromScreen( | 102 ScreenUtil::ConvertRectFromScreen( |
| 103 secondary->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString()); | 103 secondary->GetNativeView(), gfx::Rect(620, 20, 100, 100)).ToString()); |
| 104 | 104 |
| 105 EXPECT_EQ( | 105 EXPECT_EQ( |
| 106 "40,40 100x100", | 106 "40,40 100x100", |
| 107 ScreenAsh::ConvertRectToScreen( | 107 ScreenUtil::ConvertRectToScreen( |
| 108 primary->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString()); | 108 primary->GetNativeView(), gfx::Rect(30, 30, 100, 100)).ToString()); |
| 109 EXPECT_EQ( | 109 EXPECT_EQ( |
| 110 "650,50 100x100", | 110 "650,50 100x100", |
| 111 ScreenAsh::ConvertRectToScreen( | 111 ScreenUtil::ConvertRectToScreen( |
| 112 secondary->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString()); | 112 secondary->GetNativeView(), gfx::Rect(40, 40, 100, 100)).ToString()); |
| 113 } | 113 } |
| 114 | 114 |
| 115 } // namespace test | 115 } // namespace test |
| 116 } // namespace ash | 116 } // namespace ash |
| OLD | NEW |