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 <algorithm> | 5 #include <algorithm> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
| 8 #include "ash/ash_switches.h" |
8 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
9 #include "ash/launcher/launcher.h" | 10 #include "ash/launcher/launcher.h" |
10 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
13 #include "ash/wm/window_properties.h" | 14 #include "ash/wm/window_properties.h" |
14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "base/command_line.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
16 #include "ui/aura/client/activation_client.h" | 18 #include "ui/aura/client/activation_client.h" |
17 #include "ui/aura/root_window.h" | 19 #include "ui/aura/root_window.h" |
18 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
19 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
20 #include "ui/gfx/display.h" | 22 #include "ui/gfx/display.h" |
21 #include "ui/gfx/insets.h" | 23 #include "ui/gfx/insets.h" |
22 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
23 #include "ui/views/corewm/shadow.h" | 25 #include "ui/views/corewm/shadow.h" |
24 #include "ui/views/corewm/shadow_controller.h" | 26 #include "ui/views/corewm/shadow_controller.h" |
25 #include "ui/views/corewm/shadow_types.h" | 27 #include "ui/views/corewm/shadow_types.h" |
26 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
27 | 29 |
28 namespace ash { | 30 namespace ash { |
29 | 31 |
30 typedef ash::test::AshTestBase DIPTest; | 32 typedef ash::test::AshTestBase DIPTest; |
31 | 33 |
32 // Test if the WM sets correct work area under different density. | 34 // Test if the WM sets correct work area under different density. |
33 TEST_F(DIPTest, WorkArea) { | 35 TEST_F(DIPTest, WorkArea) { |
34 UpdateDisplay("1000x900*1.0f"); | 36 UpdateDisplay("1000x900*1.0f"); |
35 | 37 |
36 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); | 38 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
37 const gfx::Display display = | 39 const gfx::Display display = |
38 Shell::GetScreen()->GetDisplayNearestWindow(root); | 40 Shell::GetScreen()->GetDisplayNearestWindow(root); |
39 | 41 |
40 EXPECT_EQ("0,0 1000x900", display.bounds().ToString()); | 42 EXPECT_EQ("0,0 1000x900", display.bounds().ToString()); |
41 gfx::Rect work_area = display.work_area(); | 43 gfx::Rect work_area = display.work_area(); |
| 44 EXPECT_EQ("0,0 1000x853", work_area.ToString()); |
| 45 EXPECT_EQ("0,0,47,0", display.bounds().InsetsFrom(work_area).ToString()); |
| 46 |
| 47 UpdateDisplay("2000x1800*2.0f"); |
| 48 gfx::Screen* screen = Shell::GetScreen(); |
| 49 |
| 50 const gfx::Display display_2x = screen->GetDisplayNearestWindow(root); |
| 51 const internal::DisplayInfo display_info_2x = |
| 52 Shell::GetInstance()->display_manager()->GetDisplayInfo(display_2x.id()); |
| 53 |
| 54 // The |bounds_in_pixel()| should report bounds in pixel coordinate. |
| 55 EXPECT_EQ("1,1 2000x1800", |
| 56 display_info_2x.bounds_in_pixel().ToString()); |
| 57 |
| 58 // Aura and views coordinates are in DIP, so they their bounds do not change. |
| 59 EXPECT_EQ("0,0 1000x900", display_2x.bounds().ToString()); |
| 60 work_area = display_2x.work_area(); |
| 61 EXPECT_EQ("0,0 1000x853", work_area.ToString()); |
| 62 EXPECT_EQ("0,0,47,0", display_2x.bounds().InsetsFrom(work_area).ToString()); |
| 63 |
| 64 // Sanity check if the workarea's inset hight is same as |
| 65 // the launcher's height. |
| 66 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
| 67 EXPECT_EQ( |
| 68 display_2x.bounds().InsetsFrom(work_area).height(), |
| 69 launcher->shelf_widget()->GetNativeView()->layer()->bounds().height()); |
| 70 } |
| 71 |
| 72 TEST_F(DIPTest, WorkAreaForLegacyShelfLayout) { |
| 73 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 74 ash::switches::kAshDisableAlternateShelfLayout); |
| 75 UpdateDisplay("1000x900*1.0f"); |
| 76 |
| 77 aura::RootWindow* root = Shell::GetPrimaryRootWindow(); |
| 78 const gfx::Display display = |
| 79 Shell::GetScreen()->GetDisplayNearestWindow(root); |
| 80 |
| 81 EXPECT_EQ("0,0 1000x900", display.bounds().ToString()); |
| 82 gfx::Rect work_area = display.work_area(); |
42 EXPECT_EQ("0,0 1000x852", work_area.ToString()); | 83 EXPECT_EQ("0,0 1000x852", work_area.ToString()); |
43 EXPECT_EQ("0,0,48,0", display.bounds().InsetsFrom(work_area).ToString()); | 84 EXPECT_EQ("0,0,48,0", display.bounds().InsetsFrom(work_area).ToString()); |
44 | 85 |
45 UpdateDisplay("2000x1800*2.0f"); | 86 UpdateDisplay("2000x1800*2.0f"); |
46 gfx::Screen* screen = Shell::GetScreen(); | 87 gfx::Screen* screen = Shell::GetScreen(); |
47 | 88 |
48 const gfx::Display display_2x = screen->GetDisplayNearestWindow(root); | 89 const gfx::Display display_2x = screen->GetDisplayNearestWindow(root); |
49 const internal::DisplayInfo display_info_2x = | 90 const internal::DisplayInfo display_info_2x = |
50 Shell::GetInstance()->display_manager()->GetDisplayInfo(display_2x.id()); | 91 Shell::GetInstance()->display_manager()->GetDisplayInfo(display_2x.id()); |
51 | 92 |
52 // The |bounds_in_pixel()| should report bounds in pixel coordinate. | 93 // The |bounds_in_pixel()| should report bounds in pixel coordinate. |
53 EXPECT_EQ("1,1 2000x1800", | 94 EXPECT_EQ("1,1 2000x1800", |
54 display_info_2x.bounds_in_pixel().ToString()); | 95 display_info_2x.bounds_in_pixel().ToString()); |
55 | 96 |
56 // Aura and views coordinates are in DIP, so they their bounds do not change. | 97 // Aura and views coordinates are in DIP, so they their bounds do not change. |
57 EXPECT_EQ("0,0 1000x900", display_2x.bounds().ToString()); | 98 EXPECT_EQ("0,0 1000x900", display_2x.bounds().ToString()); |
58 work_area = display_2x.work_area(); | 99 work_area = display_2x.work_area(); |
59 EXPECT_EQ("0,0 1000x852", work_area.ToString()); | 100 EXPECT_EQ("0,0 1000x852", work_area.ToString()); |
60 EXPECT_EQ("0,0,48,0", display_2x.bounds().InsetsFrom(work_area).ToString()); | 101 EXPECT_EQ("0,0,48,0", display_2x.bounds().InsetsFrom(work_area).ToString()); |
61 | 102 |
62 // Sanity check if the workarea's inset hight is same as | 103 // Sanity check if the workarea's inset hight is same as |
63 // the launcher's height. | 104 // the launcher's height. |
64 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 105 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
65 EXPECT_EQ( | 106 EXPECT_EQ( |
66 display_2x.bounds().InsetsFrom(work_area).height(), | 107 display_2x.bounds().InsetsFrom(work_area).height(), |
67 launcher->shelf_widget()->GetNativeView()->layer()->bounds().height()); | 108 launcher->shelf_widget()->GetNativeView()->layer()->bounds().height()); |
68 } | 109 } |
69 | 110 |
70 } // namespace ash | 111 } // namespace ash |
OLD | NEW |