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

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

Issue 2036353002: mash: Move ash/common/wm/shelf to ash/common/shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase again Created 4 years, 6 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 ToastOverlay* overlay = GetCurrentOverlay(); 57 ToastOverlay* overlay = GetCurrentOverlay();
58 return overlay ? overlay->text_ : std::string(); 58 return overlay ? overlay->text_ : std::string();
59 } 59 }
60 60
61 void ClickDismissButton() { 61 void ClickDismissButton() {
62 ToastOverlay* overlay = GetCurrentOverlay(); 62 ToastOverlay* overlay = GetCurrentOverlay();
63 if (overlay) 63 if (overlay)
64 overlay->ClickDismissButtonForTesting(DummyEvent()); 64 overlay->ClickDismissButtonForTesting(DummyEvent());
65 } 65 }
66 66
67 void SetShelfAlignment(wm::ShelfAlignment alignment) { 67 void SetShelfAlignment(ShelfAlignment alignment) {
68 Shelf::ForPrimaryDisplay()->SetAlignment(alignment); 68 Shelf::ForPrimaryDisplay()->SetAlignment(alignment);
69 } 69 }
70 70
71 void SetShelfState(ShelfVisibilityState state) { 71 void SetShelfState(ShelfVisibilityState state) {
72 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetState(state); 72 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->SetState(state);
73 } 73 }
74 74
75 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) { 75 void SetShelfAutoHideBehavior(ShelfAutoHideBehavior behavior) {
76 Shelf::ForPrimaryDisplay()->SetAutoHideBehavior(behavior); 76 Shelf::ForPrimaryDisplay()->SetAutoHideBehavior(behavior);
77 } 77 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 while (GetToastSerial() != 3) 146 while (GetToastSerial() != 3)
147 base::RunLoop().RunUntilIdle(); 147 base::RunLoop().RunUntilIdle();
148 148
149 EXPECT_EQ("DUMMY3", GetCurrentText()); 149 EXPECT_EQ("DUMMY3", GetCurrentText());
150 } 150 }
151 151
152 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { 152 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) {
153 ShelfLayoutManager* shelf = 153 ShelfLayoutManager* shelf =
154 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 154 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
155 SetShelfState(ash::SHELF_VISIBLE); 155 SetShelfState(ash::SHELF_VISIBLE);
156 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); 156 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM);
157 157
158 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); 158 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */);
159 EXPECT_EQ(1, GetToastSerial()); 159 EXPECT_EQ(1, GetToastSerial());
160 160
161 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 161 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
162 gfx::Rect root_bounds = 162 gfx::Rect root_bounds =
163 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 163 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
164 164
165 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 165 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
166 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 166 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
167 167
168 if (SupportsHostWindowResize()) { 168 if (SupportsHostWindowResize()) {
169 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() 169 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds()
170 // doesn't return correct value. 170 // doesn't return correct value.
171 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 171 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
172 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 172 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
173 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); 173 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom());
174 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, 174 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5,
175 toast_bounds.bottom()); 175 toast_bounds.bottom());
176 } 176 }
177 } 177 }
178 178
179 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { 179 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) {
180 std::unique_ptr<aura::Window> window( 180 std::unique_ptr<aura::Window> window(
181 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 181 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
182 182
183 ShelfLayoutManager* shelf = 183 ShelfLayoutManager* shelf =
184 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 184 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
185 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); 185 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM);
186 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 186 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
187 shelf->LayoutShelf(); 187 shelf->LayoutShelf();
188 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); 188 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->auto_hide_state());
189 189
190 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); 190 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */);
191 EXPECT_EQ(1, GetToastSerial()); 191 EXPECT_EQ(1, GetToastSerial());
192 192
193 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 193 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
194 gfx::Rect root_bounds = 194 gfx::Rect root_bounds =
195 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 195 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
196 196
197 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 197 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
198 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 198 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
199 EXPECT_EQ(root_bounds.bottom() - ShelfLayoutManager::kAutoHideSize - 5, 199 EXPECT_EQ(root_bounds.bottom() - ShelfLayoutManager::kAutoHideSize - 5,
200 toast_bounds.bottom()); 200 toast_bounds.bottom());
201 } 201 }
202 202
203 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { 203 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) {
204 ShelfLayoutManager* shelf = 204 ShelfLayoutManager* shelf =
205 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 205 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
206 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 206 SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
207 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); 207 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM);
208 SetShelfState(ash::SHELF_HIDDEN); 208 SetShelfState(ash::SHELF_HIDDEN);
209 209
210 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); 210 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */);
211 EXPECT_EQ(1, GetToastSerial()); 211 EXPECT_EQ(1, GetToastSerial());
212 212
213 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 213 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
214 gfx::Rect root_bounds = 214 gfx::Rect root_bounds =
215 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 215 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
216 216
217 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 217 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
218 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 218 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
219 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 219 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
220 } 220 }
221 221
222 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { 222 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) {
223 ShelfLayoutManager* shelf = 223 ShelfLayoutManager* shelf =
224 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 224 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
225 SetShelfState(ash::SHELF_VISIBLE); 225 SetShelfState(ash::SHELF_VISIBLE);
226 SetShelfAlignment(wm::SHELF_ALIGNMENT_LEFT); 226 SetShelfAlignment(SHELF_ALIGNMENT_LEFT);
227 227
228 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); 228 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */);
229 EXPECT_EQ(1, GetToastSerial()); 229 EXPECT_EQ(1, GetToastSerial());
230 230
231 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 231 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
232 gfx::Rect root_bounds = 232 gfx::Rect root_bounds =
233 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 233 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
234 234
235 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 235 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
236 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 236 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
(...skipping 13 matching lines...) Expand all
250 if (!SupportsMultipleDisplays()) 250 if (!SupportsMultipleDisplays())
251 return; 251 return;
252 252
253 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 253 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
254 display_manager->SetUnifiedDesktopEnabled(true); 254 display_manager->SetUnifiedDesktopEnabled(true);
255 UpdateDisplay("1000x500,0+600-100x500"); 255 UpdateDisplay("1000x500,0+600-100x500");
256 256
257 ShelfLayoutManager* shelf = 257 ShelfLayoutManager* shelf =
258 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); 258 Shelf::ForPrimaryDisplay()->shelf_layout_manager();
259 SetShelfState(ash::SHELF_VISIBLE); 259 SetShelfState(ash::SHELF_VISIBLE);
260 SetShelfAlignment(wm::SHELF_ALIGNMENT_BOTTOM); 260 SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM);
261 261
262 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */); 262 ShowToast("DUMMY", kLongLongDuration /* prevent timeout */);
263 EXPECT_EQ(1, GetToastSerial()); 263 EXPECT_EQ(1, GetToastSerial());
264 264
265 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 265 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
266 gfx::Rect root_bounds = 266 gfx::Rect root_bounds =
267 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 267 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow());
268 268
269 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds())); 269 EXPECT_TRUE(toast_bounds.Intersects(shelf->user_work_area_bounds()));
270 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); 270 EXPECT_TRUE(root_bounds.Contains(toast_bounds));
(...skipping 27 matching lines...) Expand all
298 EXPECT_EQ("TEXT3", GetCurrentText()); 298 EXPECT_EQ("TEXT3", GetCurrentText());
299 // Cancel the shown toast. 299 // Cancel the shown toast.
300 CancelToast(id3); 300 CancelToast(id3);
301 // Confirm that the shown toast disappears. 301 // Confirm that the shown toast disappears.
302 EXPECT_FALSE(GetCurrentOverlay()); 302 EXPECT_FALSE(GetCurrentOverlay());
303 // Confirm that only 1 toast is shown. 303 // Confirm that only 1 toast is shown.
304 EXPECT_EQ(2, GetToastSerial()); 304 EXPECT_EQ(2, GetToastSerial());
305 } 305 }
306 306
307 } // namespace ash 307 } // 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