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/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
11 #include "ash/wm/shadow.h" | 11 #include "ash/wm/shadow.h" |
12 #include "ash/wm/shadow_controller.h" | 12 #include "ash/wm/shadow_controller.h" |
13 #include "ash/wm/shadow_types.h" | 13 #include "ash/wm/shadow_types.h" |
14 #include "ash/wm/window_properties.h" | 14 #include "ash/wm/window_properties.h" |
15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "ui/aura/client/activation_client.h" | 17 #include "ui/aura/client/activation_client.h" |
18 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/gfx/compositor/dip_util.h" |
20 #include "ui/gfx/compositor/layer.h" | 21 #include "ui/gfx/compositor/layer.h" |
21 #include "ui/gfx/insets.h" | 22 #include "ui/gfx/insets.h" |
22 #include "ui/gfx/monitor.h" | 23 #include "ui/gfx/monitor.h" |
23 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
25 | 26 |
26 #if defined(ENABLE_DIP) | |
27 #define MAYBE_Shadow FAILS_Shadow | |
28 #define MAYBE_WorkArea FAILS_WorkArea | |
29 #else | |
30 #define MAYBE_Shadow DISABLED_Shadow | |
31 #define MAYBE_WorkArea DISABLED_WorkArea | |
32 #endif | |
33 | |
34 namespace ash { | 27 namespace ash { |
35 | 28 |
36 typedef ash::test::AshTestBase DIPTest; | 29 typedef ash::test::AshTestBase DIPTest; |
37 | 30 |
38 // Test if the shadow works correctly under different density | |
39 TEST_F(DIPTest, MAYBE_Shadow) { | |
40 const gfx::Rect kBoundsInDIP(20, 30, 400, 300); | |
41 | |
42 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | |
43 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
44 window->Init(ui::LAYER_TEXTURED); | |
45 window->SetParent(NULL); | |
46 window->SetBounds(kBoundsInDIP); | |
47 | |
48 internal::ShadowController::TestApi api( | |
49 Shell::GetInstance()->shadow_controller()); | |
50 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | |
51 window->Show(); | |
52 | |
53 const gfx::Rect layer_bounds_copy = shadow->layer()->bounds(); | |
54 window.reset(); | |
55 | |
56 ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 1000, 1000)); | |
57 | |
58 window.reset(new aura::Window(NULL)); | |
59 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
60 window->Init(ui::LAYER_TEXTURED); | |
61 window->SetParent(NULL); | |
62 window->SetBounds(kBoundsInDIP); | |
63 shadow = api.GetShadowForWindow(window.get()); | |
64 window->Show(); | |
65 EXPECT_EQ("40,60 800x600", window->GetBoundsInPixel().ToString()); | |
66 EXPECT_EQ(layer_bounds_copy.Scale(2.0f).ToString(), | |
67 shadow->layer()->bounds().ToString()); | |
68 } | |
69 | |
70 // Test if the WM sets correct work area under different density. | 31 // Test if the WM sets correct work area under different density. |
71 TEST_F(DIPTest, MAYBE_WorkArea) { | 32 TEST_F(DIPTest, WorkArea) { |
| 33 ui::test::ScopedDIPEnablerForTest enable; |
72 ChangeMonitorConfig(1.0f, gfx::Rect(0, 0, 1000, 900)); | 34 ChangeMonitorConfig(1.0f, gfx::Rect(0, 0, 1000, 900)); |
73 | 35 |
74 aura::RootWindow* root = Shell::GetRootWindow(); | 36 aura::RootWindow* root = Shell::GetRootWindow(); |
75 const gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(root); | 37 const gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(root); |
76 | 38 |
77 EXPECT_EQ("0,0 1000x900", monitor.bounds().ToString()); | 39 EXPECT_EQ("0,0 1000x900", monitor.bounds().ToString()); |
78 const gfx::Rect work_area = monitor.work_area(); | 40 gfx::Rect work_area = monitor.work_area(); |
79 const gfx::Insets insets = monitor.bounds().InsetsFrom(work_area); | 41 EXPECT_EQ("0,0 1000x852", work_area.ToString()); |
80 EXPECT_EQ("0,0,48,0", insets.ToString()); | 42 EXPECT_EQ("0,0,48,0", monitor.bounds().InsetsFrom(work_area).ToString()); |
81 | 43 |
82 ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 2000, 1800)); | 44 ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 2000, 1800)); |
83 | 45 |
84 const gfx::Monitor monitor_2x = gfx::Screen::GetMonitorNearestWindow(root); | 46 const gfx::Monitor monitor_2x = gfx::Screen::GetMonitorNearestWindow(root); |
85 | 47 |
| 48 // The |bounds_in_pixel()| should report bounds in pixel coordinate. |
86 EXPECT_EQ("0,0 2000x1800", monitor_2x.bounds_in_pixel().ToString()); | 49 EXPECT_EQ("0,0 2000x1800", monitor_2x.bounds_in_pixel().ToString()); |
| 50 |
| 51 // Aura and views coordinates are in DIP, so they their bounds do not change. |
87 EXPECT_EQ("0,0 1000x900", monitor_2x.bounds().ToString()); | 52 EXPECT_EQ("0,0 1000x900", monitor_2x.bounds().ToString()); |
| 53 work_area = monitor_2x.work_area(); |
| 54 EXPECT_EQ("0,0 1000x852", work_area.ToString()); |
| 55 EXPECT_EQ("0,0,48,0", monitor_2x.bounds().InsetsFrom(work_area).ToString()); |
88 | 56 |
89 EXPECT_EQ(work_area.ToString(), monitor_2x.work_area().ToString()); | 57 // Sanity check if the workarea's inset hight is same as |
90 | 58 // the launcher's height. |
91 Launcher* launcher = Shell::GetInstance()->launcher(); | 59 Launcher* launcher = Shell::GetInstance()->launcher(); |
92 EXPECT_EQ( | 60 EXPECT_EQ( |
93 monitor_2x.bounds().InsetsFrom(work_area).height() * 2, | 61 monitor_2x.bounds().InsetsFrom(work_area).height(), |
94 launcher->widget()->GetNativeView()->layer()->bounds().height()); | 62 launcher->widget()->GetNativeView()->layer()->bounds().height()); |
95 } | 63 } |
96 | 64 |
97 } // namespace ash | 65 } // namespace ash |
OLD | NEW |