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

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

Issue 2860163005: chromeos: gets rid of wm_screen_util (Closed)
Patch Set: include Created 3 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
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/system/toast/toast_manager.h" 5 #include "ash/system/toast/toast_manager.h"
6 6
7 #include "ash/public/cpp/config.h" 7 #include "ash/public/cpp/config.h"
8 #include "ash/screen_util.h"
8 #include "ash/shelf/shelf_constants.h" 9 #include "ash/shelf/shelf_constants.h"
9 #include "ash/shelf/wm_shelf.h" 10 #include "ash/shelf/wm_shelf.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/wm_screen_util.h" 13 #include "ash/wm_window.h"
13 #include "base/run_loop.h" 14 #include "base/run_loop.h"
14 #include "base/strings/string16.h" 15 #include "base/strings/string16.h"
15 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 17 #include "base/strings/utf_string_conversions.h"
17 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 18 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
18 #include "ui/display/manager/display_manager.h" 19 #include "ui/display/manager/display_manager.h"
19 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
20 21
21 namespace ash { 22 namespace ash {
22 23
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 181
181 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) { 182 TEST_F(ToastManagerTest, PositionWithVisibleBottomShelf) {
182 WmShelf* shelf = GetPrimaryShelf(); 183 WmShelf* shelf = GetPrimaryShelf();
183 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 184 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
184 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 185 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
185 186
186 ShowToast("DUMMY", ToastData::kInfiniteDuration); 187 ShowToast("DUMMY", ToastData::kInfiniteDuration);
187 EXPECT_EQ(1, GetToastSerial()); 188 EXPECT_EQ(1, GetToastSerial());
188 189
189 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 190 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
190 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); 191 gfx::Rect root_bounds =
192 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());
191 193
192 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 194 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
193 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 195 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
194 196
195 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 197 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
196 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 198 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
197 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); 199 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom());
198 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, 200 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5,
199 toast_bounds.bottom()); 201 toast_bounds.bottom());
200 } 202 }
201 203
202 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { 204 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) {
203 std::unique_ptr<aura::Window> window( 205 std::unique_ptr<aura::Window> window(
204 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); 206 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4)));
205 207
206 WmShelf* shelf = GetPrimaryShelf(); 208 WmShelf* shelf = GetPrimaryShelf();
207 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 209 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
208 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 210 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
209 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); 211 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
210 212
211 ShowToast("DUMMY", ToastData::kInfiniteDuration); 213 ShowToast("DUMMY", ToastData::kInfiniteDuration);
212 EXPECT_EQ(1, GetToastSerial()); 214 EXPECT_EQ(1, GetToastSerial());
213 215
214 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 216 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
215 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); 217 gfx::Rect root_bounds =
218 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());
216 219
217 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 220 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
218 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 221 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
219 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, 222 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5,
220 toast_bounds.bottom()); 223 toast_bounds.bottom());
221 } 224 }
222 225
223 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { 226 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) {
224 WmShelf* shelf = GetPrimaryShelf(); 227 WmShelf* shelf = GetPrimaryShelf();
225 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 228 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
226 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); 229 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN);
227 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); 230 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState());
228 231
229 ShowToast("DUMMY", ToastData::kInfiniteDuration); 232 ShowToast("DUMMY", ToastData::kInfiniteDuration);
230 EXPECT_EQ(1, GetToastSerial()); 233 EXPECT_EQ(1, GetToastSerial());
231 234
232 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 235 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
233 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); 236 gfx::Rect root_bounds =
237 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());
234 238
235 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 239 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
236 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 240 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
237 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 241 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
238 } 242 }
239 243
240 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { 244 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) {
241 WmShelf* shelf = GetPrimaryShelf(); 245 WmShelf* shelf = GetPrimaryShelf();
242 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 246 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
243 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 247 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
244 248
245 ShowToast("DUMMY", ToastData::kInfiniteDuration); 249 ShowToast("DUMMY", ToastData::kInfiniteDuration);
246 EXPECT_EQ(1, GetToastSerial()); 250 EXPECT_EQ(1, GetToastSerial());
247 251
248 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 252 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
249 gfx::RectF precise_toast_bounds(toast_bounds); 253 gfx::RectF precise_toast_bounds(toast_bounds);
250 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); 254 gfx::Rect root_bounds =
255 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());
251 256
252 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 257 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
253 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); 258 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom());
254 259
255 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 260 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
256 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 261 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
257 EXPECT_NEAR( 262 EXPECT_NEAR(
258 shelf_bounds.right() + (root_bounds.width() - shelf_bounds.width()) / 2.0, 263 shelf_bounds.right() + (root_bounds.width() - shelf_bounds.width()) / 2.0,
259 precise_toast_bounds.CenterPoint().x(), 1.f /* accepted error */); 264 precise_toast_bounds.CenterPoint().x(), 1.f /* accepted error */);
260 } 265 }
261 266
262 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { 267 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) {
263 // TODO: needs unified mode. http://crbug.com/698024. 268 // TODO: needs unified mode. http://crbug.com/698024.
264 if (Shell::GetAshConfig() == Config::MASH) 269 if (Shell::GetAshConfig() == Config::MASH)
265 return; 270 return;
266 271
267 display_manager()->SetUnifiedDesktopEnabled(true); 272 display_manager()->SetUnifiedDesktopEnabled(true);
268 UpdateDisplay("1000x500,0+600-100x500"); 273 UpdateDisplay("1000x500,0+600-100x500");
269 274
270 WmShelf* shelf = GetPrimaryShelf(); 275 WmShelf* shelf = GetPrimaryShelf();
271 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); 276 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment());
272 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); 277 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
273 278
274 ShowToast("DUMMY", ToastData::kInfiniteDuration); 279 ShowToast("DUMMY", ToastData::kInfiniteDuration);
275 EXPECT_EQ(1, GetToastSerial()); 280 EXPECT_EQ(1, GetToastSerial());
276 281
277 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); 282 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen();
278 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); 283 gfx::Rect root_bounds =
284 ScreenUtil::GetDisplayBoundsWithShelf(shelf->GetWindow()->aura_window());
279 285
280 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); 286 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds()));
281 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); 287 EXPECT_TRUE(root_bounds.Contains(toast_bounds));
282 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); 288 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1);
283 289
284 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); 290 gfx::Rect shelf_bounds = shelf->GetIdealBounds();
285 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); 291 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds));
286 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); 292 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom());
287 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, 293 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5,
288 toast_bounds.bottom()); 294 toast_bounds.bottom());
(...skipping 16 matching lines...) Expand all
305 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText()); 311 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText());
306 // Cancel the shown toast. 312 // Cancel the shown toast.
307 CancelToast(id3); 313 CancelToast(id3);
308 // Confirm that the shown toast disappears. 314 // Confirm that the shown toast disappears.
309 EXPECT_FALSE(GetCurrentOverlay()); 315 EXPECT_FALSE(GetCurrentOverlay());
310 // Confirm that only 1 toast is shown. 316 // Confirm that only 1 toast is shown.
311 EXPECT_EQ(2, GetToastSerial()); 317 EXPECT_EQ(2, GetToastSerial());
312 } 318 }
313 319
314 } // namespace ash 320 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698