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

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

Issue 2215223004: mash: Migrate ShelfLayoutManager ScreenUtil usage to ash common types. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup. Created 4 years, 4 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
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/common/shelf/shelf_constants.h" 5 #include "ash/common/shelf/shelf_constants.h"
6 #include "ash/common/shelf/wm_shelf.h" 6 #include "ash/common/shelf/wm_shelf.h"
7 #include "ash/common/system/toast/toast_manager.h" 7 #include "ash/common/system/toast/toast_manager.h"
8 #include "ash/common/wm/wm_screen_util.h"
8 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
9 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
10 #include "ash/screen_util.h" 11 #include "ash/screen_util.h"
11 #include "ash/shell.h" 12 #include "ash/shell.h"
12 #include "ash/test/ash_test_base.h" 13 #include "ash/test/ash_test_base.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
15 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 16 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 18
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { 156 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) {
156 WmShelf* shelf = GetPrimaryShelf(); 157 WmShelf* shelf = GetPrimaryShelf();
157 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 158 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
158 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 159 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
159 160
160 ShowToast("DUMMY", ToastData::kInfiniteDuration); 161 ShowToast("DUMMY", ToastData::kInfiniteDuration);
161 EXPECT_EQ(1, GetToastSerial()); 162 EXPECT_EQ(1, GetToastSerial());
162 163
163 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 164 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
164 gfx::Rect root_bounds = 165 gfx::Rect root_bounds =
165 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 166 wm::GetShelfDisplayBoundsForWindow(shelf->GetWindow());
166 167
167 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 168 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
168 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 169 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
169 170
170 if (SupportsHostWindowResize()) { 171 if (SupportsHostWindowResize()) {
171 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() 172 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds()
172 // doesn't return correct value. 173 // doesn't return correct value.
173 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 174 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
174 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 175 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
175 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); 176 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom());
176 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, 177 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5,
177 toast_bounds.bottom()); 178 toast_bounds.bottom());
178 } 179 }
179 } 180 }
180 181
181 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { 182 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) {
182 std::unique_ptr<aura::Window> window( 183 std::unique_ptr<aura::Window> window(
183 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 184 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
184 185
185 WmShelf* shelf = GetPrimaryShelf(); 186 WmShelf* shelf = GetPrimaryShelf();
186 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 187 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
187 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 188 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
188 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 189 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
189 190
190 ShowToast("DUMMY", ToastData::kInfiniteDuration); 191 ShowToast("DUMMY", ToastData::kInfiniteDuration);
191 EXPECT_EQ(1, GetToastSerial()); 192 EXPECT_EQ(1, GetToastSerial());
192 193
193 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 194 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
194 gfx::Rect root_bounds = 195 gfx::Rect root_bounds =
195 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 196 wm::GetShelfDisplayBoundsForWindow(shelf->GetWindow());
196 197
197 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 198 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
198 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 199 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
199 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, 200 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5,
200 toast_bounds.bottom()); 201 toast_bounds.bottom());
201 } 202 }
202 203
203 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { 204 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) {
204 WmShelf* shelf = GetPrimaryShelf(); 205 WmShelf* shelf = GetPrimaryShelf();
205 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 206 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
206 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 207 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
207 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); 208 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
208 209
209 ShowToast("DUMMY", ToastData::kInfiniteDuration); 210 ShowToast("DUMMY", ToastData::kInfiniteDuration);
210 EXPECT_EQ(1, GetToastSerial()); 211 EXPECT_EQ(1, GetToastSerial());
211 212
212 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 213 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
213 gfx::Rect root_bounds = 214 gfx::Rect root_bounds =
214 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 215 wm::GetShelfDisplayBoundsForWindow(shelf->GetWindow());
215 216
216 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 217 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
217 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 218 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
218 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 219 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
219 } 220 }
220 221
221 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { 222 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) {
222 WmShelf* shelf = GetPrimaryShelf(); 223 WmShelf* shelf = GetPrimaryShelf();
223 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 224 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
224 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 225 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
225 226
226 ShowToast("DUMMY", ToastData::kInfiniteDuration); 227 ShowToast("DUMMY", ToastData::kInfiniteDuration);
227 EXPECT_EQ(1, GetToastSerial()); 228 EXPECT_EQ(1, GetToastSerial());
228 229
229 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 230 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
230 gfx::RectF precise_toast_bounds(toast_bounds); 231 gfx::RectF precise_toast_bounds(toast_bounds);
231 gfx::Rect root_bounds = 232 gfx::Rect root_bounds =
232 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 233 wm::GetShelfDisplayBoundsForWindow(shelf->GetWindow());
233 234
234 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 235 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
235 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 236 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
236 237
237 if (SupportsHostWindowResize()) { 238 if (SupportsHostWindowResize()) {
238 // If host resize is not supported then calling WmShelf::GetIdealBounds() 239 // If host resize is not supported then calling WmShelf::GetIdealBounds()
239 // doesn't return correct value. 240 // doesn't return correct value.
240 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 241 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
241 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 242 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
242 EXPECT_EQ(round(shelf_bounds.right() + 243 EXPECT_EQ(round(shelf_bounds.right() +
(...skipping 12 matching lines...) Expand all
255 256
256 WmShelf* shelf = GetPrimaryShelf(); 257 WmShelf* shelf = GetPrimaryShelf();
257 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 258 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
258 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 259 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
259 260
260 ShowToast("DUMMY", ToastData::kInfiniteDuration); 261 ShowToast("DUMMY", ToastData::kInfiniteDuration);
261 EXPECT_EQ(1, GetToastSerial()); 262 EXPECT_EQ(1, GetToastSerial());
262 263
263 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 264 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
264 gfx::Rect root_bounds = 265 gfx::Rect root_bounds =
265 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); 266 wm::GetShelfDisplayBoundsForWindow(shelf->GetWindow());
266 267
267 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 268 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
268 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); 269 EXPECT_TRUE(root_bounds.Contains(toast_bounds));
269 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 270 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
270 271
271 if (SupportsHostWindowResize()) { 272 if (SupportsHostWindowResize()) {
272 // If host resize is not supported then calling WmShelf::GetIdealBounds() 273 // If host resize is not supported then calling WmShelf::GetIdealBounds()
273 // doesn't return correct value. 274 // doesn't return correct value.
274 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 275 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
275 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 276 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
(...skipping 20 matching lines...) Expand all
296 EXPECT_EQ("TEXT3", GetCurrentText()); 297 EXPECT_EQ("TEXT3", GetCurrentText());
297 // Cancel the shown toast. 298 // Cancel the shown toast.
298 CancelToast(id3); 299 CancelToast(id3);
299 // Confirm that the shown toast disappears. 300 // Confirm that the shown toast disappears.
300 EXPECT_FALSE(GetCurrentOverlay()); 301 EXPECT_FALSE(GetCurrentOverlay());
301 // Confirm that only 1 toast is shown. 302 // Confirm that only 1 toast is shown.
302 EXPECT_EQ(2, GetToastSerial()); 303 EXPECT_EQ(2, GetToastSerial());
303 } 304 }
304 305
305 } // namespace ash 306 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698