Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: ash/wm/base_layout_manager_unittest.cc

Issue 9960042: Refactor screen/monitor so that gfx::Screen returns monitor object. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/base_layout_manager.cc ('k') | ash/wm/root_window_event_filter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/wm/base_layout_manager.h" 5 #include "ash/wm/base_layout_manager.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 9 #include "ash/shell_window_ids.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "ui/aura/client/aura_constants.h" 13 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/root_window.h" 14 #include "ui/aura/root_window.h"
15 #include "ui/aura/test/test_windows.h" 15 #include "ui/aura/test/test_windows.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/base/ui_base_types.h" 17 #include "ui/base/ui_base_types.h"
18 #include "ui/gfx/insets.h" 18 #include "ui/gfx/insets.h"
19 #include "ui/gfx/screen.h"
19 20
20 namespace ash { 21 namespace ash {
21 22
22 namespace { 23 namespace {
23 24
24 class BaseLayoutManagerTest : public test::AshTestBase { 25 class BaseLayoutManagerTest : public test::AshTestBase {
25 public: 26 public:
26 BaseLayoutManagerTest() {} 27 BaseLayoutManagerTest() {}
27 virtual ~BaseLayoutManagerTest() {} 28 virtual ~BaseLayoutManagerTest() {}
28 29
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 EXPECT_NE(initial_work_area_bounds.ToString(), 86 EXPECT_NE(initial_work_area_bounds.ToString(),
86 ScreenAsh::GetMaximizedWindowBounds(window.get()).ToString()); 87 ScreenAsh::GetMaximizedWindowBounds(window.get()).ToString());
87 } 88 }
88 89
89 // Tests normal->fullscreen->normal. 90 // Tests normal->fullscreen->normal.
90 TEST_F(BaseLayoutManagerTest, Fullscreen) { 91 TEST_F(BaseLayoutManagerTest, Fullscreen) {
91 gfx::Rect bounds(100, 100, 200, 200); 92 gfx::Rect bounds(100, 100, 200, 200);
92 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 93 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
93 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 94 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
94 // Fullscreen window fills the whole monitor. 95 // Fullscreen window fills the whole monitor.
95 EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()).ToString(), 96 EXPECT_EQ(
96 window->bounds().ToString()); 97 gfx::Screen::GetMonitorNearestWindow(window.get()).bounds().ToString(),
98 window->bounds().ToString());
97 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 99 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
98 EXPECT_EQ(bounds.ToString(), window->bounds().ToString()); 100 EXPECT_EQ(bounds.ToString(), window->bounds().ToString());
99 } 101 }
100 102
101 // Tests fullscreen window size during root window resize. 103 // Tests fullscreen window size during root window resize.
102 TEST_F(BaseLayoutManagerTest, FullscreenRootWindowResize) { 104 TEST_F(BaseLayoutManagerTest, FullscreenRootWindowResize) {
103 gfx::Rect bounds(100, 100, 200, 200); 105 gfx::Rect bounds(100, 100, 200, 200);
104 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 106 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
105 // Fullscreen window fills the whole monitor. 107 // Fullscreen window fills the whole monitor.
106 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 108 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
107 EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()).ToString(), 109 EXPECT_EQ(
108 window->bounds().ToString()); 110 gfx::Screen::GetMonitorNearestWindow(window.get()).bounds().ToString(),
111 window->bounds().ToString());
109 // Enlarge the root window. We should still match the monitor size. 112 // Enlarge the root window. We should still match the monitor size.
110 Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600)); 113 Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
111 EXPECT_EQ(gfx::Screen::GetMonitorAreaNearestWindow(window.get()).ToString(), 114 EXPECT_EQ(
112 window->bounds().ToString()); 115 gfx::Screen::GetMonitorNearestWindow(window.get()).bounds().ToString(),
116 window->bounds().ToString());
113 } 117 }
114 118
115 // Fails on Mac only. Need to be implemented. http://crbug.com/111279. 119 // Fails on Mac only. Need to be implemented. http://crbug.com/111279.
116 #if defined(OS_MACOSX) 120 #if defined(OS_MACOSX)
117 #define MAYBE_RootWindowResizeShrinksWindows \ 121 #define MAYBE_RootWindowResizeShrinksWindows \
118 FAILS_RootWindowResizeShrinksWindows 122 FAILS_RootWindowResizeShrinksWindows
119 #else 123 #else
120 #define MAYBE_RootWindowResizeShrinksWindows RootWindowResizeShrinksWindows 124 #define MAYBE_RootWindowResizeShrinksWindows RootWindowResizeShrinksWindows
121 #endif 125 #endif
122 // Tests that when the screen gets smaller the windows aren't bigger than 126 // Tests that when the screen gets smaller the windows aren't bigger than
123 // the screen. 127 // the screen.
124 TEST_F(BaseLayoutManagerTest, MAYBE_RootWindowResizeShrinksWindows) { 128 TEST_F(BaseLayoutManagerTest, MAYBE_RootWindowResizeShrinksWindows) {
125 scoped_ptr<aura::Window> window( 129 scoped_ptr<aura::Window> window(
126 CreateTestWindow(gfx::Rect(10, 20, 500, 400))); 130 CreateTestWindow(gfx::Rect(10, 20, 500, 400)));
127 gfx::Rect work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get()); 131 gfx::Rect work_area =
132 gfx::Screen::GetMonitorNearestWindow(window.get()).work_area();
128 // Invariant: Window is smaller than work area. 133 // Invariant: Window is smaller than work area.
129 EXPECT_LE(window->bounds().width(), work_area.width()); 134 EXPECT_LE(window->bounds().width(), work_area.width());
130 EXPECT_LE(window->bounds().height(), work_area.height()); 135 EXPECT_LE(window->bounds().height(), work_area.height());
131 136
132 // Make the root window narrower than our window. 137 // Make the root window narrower than our window.
133 Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 400)); 138 Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 400));
134 work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get()); 139 work_area = gfx::Screen::GetMonitorNearestWindow(window.get()).work_area();
135 EXPECT_LE(window->bounds().width(), work_area.width()); 140 EXPECT_LE(window->bounds().width(), work_area.width());
136 EXPECT_LE(window->bounds().height(), work_area.height()); 141 EXPECT_LE(window->bounds().height(), work_area.height());
137 142
138 // Make the root window shorter than our window. 143 // Make the root window shorter than our window.
139 Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 200)); 144 Shell::GetRootWindow()->SetHostSize(gfx::Size(300, 200));
140 work_area = gfx::Screen::GetMonitorAreaNearestWindow(window.get()); 145 work_area = gfx::Screen::GetMonitorNearestWindow(window.get()).work_area();
141 EXPECT_LE(window->bounds().width(), work_area.width()); 146 EXPECT_LE(window->bounds().width(), work_area.width());
142 EXPECT_LE(window->bounds().height(), work_area.height()); 147 EXPECT_LE(window->bounds().height(), work_area.height());
143 148
144 // Enlarging the root window does not change the window bounds. 149 // Enlarging the root window does not change the window bounds.
145 gfx::Rect old_bounds = window->bounds(); 150 gfx::Rect old_bounds = window->bounds();
146 Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600)); 151 Shell::GetRootWindow()->SetHostSize(gfx::Size(800, 600));
147 EXPECT_EQ(old_bounds.width(), window->bounds().width()); 152 EXPECT_EQ(old_bounds.width(), window->bounds().width());
148 EXPECT_EQ(old_bounds.height(), window->bounds().height()); 153 EXPECT_EQ(old_bounds.height(), window->bounds().height());
149 } 154 }
150 155
151 // Tests that a maximized window with too-large restore bounds will be restored 156 // Tests that a maximized window with too-large restore bounds will be restored
152 // to smaller than the full work area. 157 // to smaller than the full work area.
153 TEST_F(BaseLayoutManagerTest, BoundsWithScreenEdgeVisible) { 158 TEST_F(BaseLayoutManagerTest, BoundsWithScreenEdgeVisible) {
154 // Create a window with bounds that fill the screen. 159 // Create a window with bounds that fill the screen.
155 gfx::Rect bounds = gfx::Screen::GetPrimaryMonitorBounds(); 160 gfx::Rect bounds = gfx::Screen::GetPrimaryMonitor().bounds();
156 scoped_ptr<aura::Window> window(CreateTestWindow(bounds)); 161 scoped_ptr<aura::Window> window(CreateTestWindow(bounds));
157 // Maximize it, which writes the old bounds to restore bounds. 162 // Maximize it, which writes the old bounds to restore bounds.
158 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 163 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED);
159 // Restore it. 164 // Restore it.
160 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 165 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL);
161 // It should have the default maximized window bounds, inset by the grid size. 166 // It should have the default maximized window bounds, inset by the grid size.
162 int grid_size = ash::Shell::GetInstance()->GetGridSize(); 167 int grid_size = ash::Shell::GetInstance()->GetGridSize();
163 gfx::Rect max_bounds = ash::ScreenAsh::GetMaximizedWindowBounds(window.get()); 168 gfx::Rect max_bounds = ash::ScreenAsh::GetMaximizedWindowBounds(window.get());
164 max_bounds.Inset(grid_size, grid_size); 169 max_bounds.Inset(grid_size, grid_size);
165 EXPECT_EQ(max_bounds.ToString(), window->bounds().ToString()); 170 EXPECT_EQ(max_bounds.ToString(), window->bounds().ToString());
166 } 171 }
167 172
168 } // namespace 173 } // namespace
169 174
170 } // namespace ash 175 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/base_layout_manager.cc ('k') | ash/wm/root_window_event_filter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698