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/compositor/dip_util.h" |
20 #include "ui/compositor/layer.h" | 21 #include "ui/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 | 31 #if defined(OS_WIN) |
39 TEST_F(DIPTest, MAYBE_Shadow) { | 32 // Windows/Aura doesn't have DIP support in monitor yet. |
40 const gfx::Rect kBoundsInDIP(20, 30, 400, 300); | 33 #define MAYBE_WorkArea DISABLED_WorkArea |
41 | 34 #else |
42 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 35 #define MAYBE_WorkArea WorkArea |
43 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | 36 #endif |
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 | 37 |
70 // Test if the WM sets correct work area under different density. | 38 // Test if the WM sets correct work area under different density. |
71 TEST_F(DIPTest, MAYBE_WorkArea) { | 39 TEST_F(DIPTest, MAYBE_WorkArea) { |
| 40 ui::test::ScopedDIPEnablerForTest enable; |
72 ChangeMonitorConfig(1.0f, gfx::Rect(0, 0, 1000, 900)); | 41 ChangeMonitorConfig(1.0f, gfx::Rect(0, 0, 1000, 900)); |
73 | 42 |
74 aura::RootWindow* root = Shell::GetRootWindow(); | 43 aura::RootWindow* root = Shell::GetRootWindow(); |
75 const gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(root); | 44 const gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(root); |
76 | 45 |
77 EXPECT_EQ("0,0 1000x900", monitor.bounds().ToString()); | 46 EXPECT_EQ("0,0 1000x900", monitor.bounds().ToString()); |
78 const gfx::Rect work_area = monitor.work_area(); | 47 gfx::Rect work_area = monitor.work_area(); |
79 const gfx::Insets insets = monitor.bounds().InsetsFrom(work_area); | 48 EXPECT_EQ("0,0 1000x852", work_area.ToString()); |
80 EXPECT_EQ("0,0,48,0", insets.ToString()); | 49 EXPECT_EQ("0,0,48,0", monitor.bounds().InsetsFrom(work_area).ToString()); |
81 | 50 |
82 ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 2000, 1800)); | 51 ChangeMonitorConfig(2.0f, gfx::Rect(0, 0, 2000, 1800)); |
83 | 52 |
84 const gfx::Monitor monitor_2x = gfx::Screen::GetMonitorNearestWindow(root); | 53 const gfx::Monitor monitor_2x = gfx::Screen::GetMonitorNearestWindow(root); |
85 | 54 |
| 55 // The |bounds_in_pixel()| should report bounds in pixel coordinate. |
86 EXPECT_EQ("0,0 2000x1800", monitor_2x.bounds_in_pixel().ToString()); | 56 EXPECT_EQ("0,0 2000x1800", monitor_2x.bounds_in_pixel().ToString()); |
| 57 |
| 58 // Aura and views coordinates are in DIP, so they their bounds do not change. |
87 EXPECT_EQ("0,0 1000x900", monitor_2x.bounds().ToString()); | 59 EXPECT_EQ("0,0 1000x900", monitor_2x.bounds().ToString()); |
| 60 work_area = monitor_2x.work_area(); |
| 61 EXPECT_EQ("0,0 1000x852", work_area.ToString()); |
| 62 EXPECT_EQ("0,0,48,0", monitor_2x.bounds().InsetsFrom(work_area).ToString()); |
88 | 63 |
89 EXPECT_EQ(work_area.ToString(), monitor_2x.work_area().ToString()); | 64 // Sanity check if the workarea's inset hight is same as |
90 | 65 // the launcher's height. |
91 Launcher* launcher = Shell::GetInstance()->launcher(); | 66 Launcher* launcher = Shell::GetInstance()->launcher(); |
92 EXPECT_EQ( | 67 EXPECT_EQ( |
93 monitor_2x.bounds().InsetsFrom(work_area).height() * 2, | 68 monitor_2x.bounds().InsetsFrom(work_area).height(), |
94 launcher->widget()->GetNativeView()->layer()->bounds().height()); | 69 launcher->widget()->GetNativeView()->layer()->bounds().height()); |
95 } | 70 } |
96 | 71 |
97 } // namespace ash | 72 } // namespace ash |
OLD | NEW |