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

Side by Side Diff: ash/system/toast/toast_manager_unittest.cc

Issue 1914093002: Refactors DockedWindowLayoutManager in terms of ash/wm/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@nuke_aura_window
Patch Set: comment Created 4 years, 7 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
« no previous file with comments | « ash/system/status_area_widget_delegate.cc ('k') | ash/system/tray/system_tray.h » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/display/display_manager.h" 5 #include "ash/display/display_manager.h"
6 #include "ash/screen_util.h" 6 #include "ash/screen_util.h"
7 #include "ash/shelf/shelf.h" 7 #include "ash/shelf/shelf.h"
8 #include "ash/shelf/shelf_layout_manager.h" 8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/toast/toast_manager.h" 10 #include "ash/system/toast/toast_manager.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ToastOverlay* overlay = GetCurrentOverlay(); 56 ToastOverlay* overlay = GetCurrentOverlay();
57 return overlay ? overlay->text_ : std::string(); 57 return overlay ? overlay->text_ : std::string();
58 } 58 }
59 59
60 void ClickDismissButton() { 60 void ClickDismissButton() {
61 ToastOverlay* overlay = GetCurrentOverlay(); 61 ToastOverlay* overlay = GetCurrentOverlay();
62 if (overlay) 62 if (overlay)
63 overlay->ClickDismissButtonForTesting(DummyEvent()); 63 overlay->ClickDismissButtonForTesting(DummyEvent());
64 } 64 }
65 65
66 void SetShelfAlignment(ShelfAlignment alignment) { 66 void SetShelfAlignment(wm::ShelfAlignment alignment) {
67 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetAlignment(alignment); 67 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetAlignment(alignment);
68 } 68 }
69 69
70 void SetShelfState(ShelfVisibilityState state) { 70 void SetShelfState(ShelfVisibilityState state) {
71 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetState(state); 71 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetState(state);
72 } 72 }
73 73
74 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) { 74 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) {
75 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetAutoHideBehavior( 75 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetAutoHideBehavior(
76 behavior); 76 behavior);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 while (GetToastId() != 3) 137 while (GetToastId() != 3)
138 base::RunLoop().RunUntilIdle(); 138 base::RunLoop().RunUntilIdle();
139 139
140 EXPECT_EQ("DUMMY3", GetCurrentText()); 140 EXPECT_EQ("DUMMY3", GetCurrentText());
141 } 141 }
142 142
143 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { 143 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) {
144 ShelfLayoutManager* shelf = 144 ShelfLayoutManager* shelf =
145 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 145 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
146 SetShelfState(ash::SHELF_VISIBLE); 146 SetShelfState(ash::SHELF_VISIBLE);
147 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); 147 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM);
148 148
149 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); 149 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */);
150 EXPECT_EQ(1, GetToastId()); 150 EXPECT_EQ(1, GetToastId());
151 151
152 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 152 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
153 gfx::Rect root_bounds = 153 gfx::Rect root_bounds =
154 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 154 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
155 155
156 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 156 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
157 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 157 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
158 158
159 if (SupportsHostWindowResize()) { 159 if (SupportsHostWindowResize()) {
160 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() 160 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds()
161 // doesn't return correct value. 161 // doesn't return correct value.
162 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 162 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
163 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 163 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
164 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); 164 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom());
165 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, 165 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5,
166 toast_bounds.bottom()); 166 toast_bounds.bottom());
167 } 167 }
168 } 168 }
169 169
170 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { 170 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) {
171 std::unique_ptr<aura::Window> window( 171 std::unique_ptr<aura::Window> window(
172 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 172 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
173 173
174 ShelfLayoutManager* shelf = 174 ShelfLayoutManager* shelf =
175 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 175 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
176 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); 176 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM);
177 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 177 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
178 shelf->LayoutShelf(); 178 shelf->LayoutShelf();
179 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 179 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
180 180
181 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); 181 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */);
182 EXPECT_EQ(1, GetToastId()); 182 EXPECT_EQ(1, GetToastId());
183 183
184 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 184 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
185 gfx::Rect root_bounds = 185 gfx::Rect root_bounds =
186 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 186 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
187 187
188 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 188 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
189 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 189 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
190 EXPECT_EQ(root_bounds.bottom() - ShelfLayoutManager::kAutoHideSize - 5, 190 EXPECT_EQ(root_bounds.bottom() - ShelfLayoutManager::kAutoHideSize - 5,
191 toast_bounds.bottom()); 191 toast_bounds.bottom());
192 } 192 }
193 193
194 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { 194 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) {
195 ShelfLayoutManager* shelf = 195 ShelfLayoutManager* shelf =
196 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 196 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
197 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 197 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
198 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); 198 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM);
199 SetShelfState(ash::SHELF_HIDDEN); 199 SetShelfState(ash::SHELF_HIDDEN);
200 200
201 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); 201 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */);
202 EXPECT_EQ(1, GetToastId()); 202 EXPECT_EQ(1, GetToastId());
203 203
204 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 204 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
205 gfx::Rect root_bounds = 205 gfx::Rect root_bounds =
206 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 206 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
207 207
208 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 208 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
209 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 209 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
210 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 210 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
211 } 211 }
212 212
213 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { 213 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) {
214 ShelfLayoutManager* shelf = 214 ShelfLayoutManager* shelf =
215 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 215 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
216 SetShelfState(ash::SHELF_VISIBLE); 216 SetShelfState(ash::SHELF_VISIBLE);
217 SetShelfAlignment(ash::SHELF_ALIGNMENT_LEFT); 217 SetShelfAlignment(wm::SHELF_ALIGNMENT_LEFT);
218 218
219 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); 219 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */);
220 EXPECT_EQ(1, GetToastId()); 220 EXPECT_EQ(1, GetToastId());
221 221
222 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 222 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
223 gfx::Rect root_bounds = 223 gfx::Rect root_bounds =
224 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 224 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
225 225
226 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 226 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
227 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 227 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
(...skipping 13 matching lines...) Expand all
241 if (!SupportsMultipleDisplays()) 241 if (!SupportsMultipleDisplays())
242 return; 242 return;
243 243
244 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 244 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
245 display_manager->SetUnifiedDesktopEnabled(true); 245 display_manager->SetUnifiedDesktopEnabled(true);
246 UpdateDisplay("1000x500,0+600-100x500"); 246 UpdateDisplay("1000x500,0+600-100x500");
247 247
248 ShelfLayoutManager* shelf = 248 ShelfLayoutManager* shelf =
249 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 249 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
250 SetShelfState(ash::SHELF_VISIBLE); 250 SetShelfState(ash::SHELF_VISIBLE);
251 SetShelfAlignment(ash::SHELF_ALIGNMENT_BOTTOM); 251 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM);
252 252
253 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */); 253 manager()->Show("DUMMY", kLongLongDuration /* prevent timeout */);
254 EXPECT_EQ(1, GetToastId()); 254 EXPECT_EQ(1, GetToastId());
255 255
256 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 256 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
257 gfx::Rect root_bounds = 257 gfx::Rect root_bounds =
258 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 258 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
259 259
260 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 260 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
261 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); 261 EXPECT_TRUE(root_bounds.Contains(toast_bounds));
262 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 262 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
263 263
264 if (SupportsHostWindowResize()) { 264 if (SupportsHostWindowResize()) {
265 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() 265 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds()
266 // doesn't return correct value. 266 // doesn't return correct value.
267 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 267 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
268 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 268 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
269 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); 269 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom());
270 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, 270 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5,
271 toast_bounds.bottom()); 271 toast_bounds.bottom());
272 } 272 }
273 } 273 }
274 274
275 } // namespace ash 275 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/status_area_widget_delegate.cc ('k') | ash/system/tray/system_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698