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

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

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

Powered by Google App Engine
This is Rietveld 408576698