| OLD | NEW |
| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 | 155 |
| 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 = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
| 165 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | |
| 166 | 166 |
| 167 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 167 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 168 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 168 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 169 | 169 |
| 170 if (SupportsHostWindowResize()) { | 170 if (SupportsHostWindowResize()) { |
| 171 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() | 171 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() |
| 172 // doesn't return correct value. | 172 // doesn't return correct value. |
| 173 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 173 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 174 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 174 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 175 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 175 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
| 176 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 176 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
| 177 toast_bounds.bottom()); | 177 toast_bounds.bottom()); |
| 178 } | 178 } |
| 179 } | 179 } |
| 180 | 180 |
| 181 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { | 181 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { |
| 182 std::unique_ptr<aura::Window> window( | 182 std::unique_ptr<aura::Window> window( |
| 183 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 183 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
| 184 | 184 |
| 185 WmShelf* shelf = GetPrimaryShelf(); | 185 WmShelf* shelf = GetPrimaryShelf(); |
| 186 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 186 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 187 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 187 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
| 188 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 188 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
| 189 | 189 |
| 190 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 190 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 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 = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
| 195 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | |
| 196 | 195 |
| 197 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 196 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 198 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 197 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 199 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, | 198 EXPECT_EQ(root_bounds.bottom() - kShelfAutoHideSize - 5, |
| 200 toast_bounds.bottom()); | 199 toast_bounds.bottom()); |
| 201 } | 200 } |
| 202 | 201 |
| 203 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { | 202 TEST_F(ToastManagerTest, PositionWithHiddenBottomShelf) { |
| 204 WmShelf* shelf = GetPrimaryShelf(); | 203 WmShelf* shelf = GetPrimaryShelf(); |
| 205 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 204 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 206 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); | 205 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_ALWAYS_HIDDEN); |
| 207 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); | 206 EXPECT_EQ(SHELF_HIDDEN, shelf->GetVisibilityState()); |
| 208 | 207 |
| 209 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 208 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 210 EXPECT_EQ(1, GetToastSerial()); | 209 EXPECT_EQ(1, GetToastSerial()); |
| 211 | 210 |
| 212 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 211 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 213 gfx::Rect root_bounds = | 212 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
| 214 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | |
| 215 | 213 |
| 216 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 214 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 217 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 215 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 218 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 216 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 219 } | 217 } |
| 220 | 218 |
| 221 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { | 219 TEST_F(ToastManagerTest, PositionWithVisibleLeftShelf) { |
| 222 WmShelf* shelf = GetPrimaryShelf(); | 220 WmShelf* shelf = GetPrimaryShelf(); |
| 223 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 221 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 224 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 222 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 225 | 223 |
| 226 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 224 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 227 EXPECT_EQ(1, GetToastSerial()); | 225 EXPECT_EQ(1, GetToastSerial()); |
| 228 | 226 |
| 229 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 227 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 230 gfx::RectF precise_toast_bounds(toast_bounds); | 228 gfx::RectF precise_toast_bounds(toast_bounds); |
| 231 gfx::Rect root_bounds = | 229 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
| 232 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | |
| 233 | 230 |
| 234 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 231 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 235 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 232 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
| 236 | 233 |
| 237 if (SupportsHostWindowResize()) { | 234 if (SupportsHostWindowResize()) { |
| 238 // If host resize is not supported then calling WmShelf::GetIdealBounds() | 235 // If host resize is not supported then calling WmShelf::GetIdealBounds() |
| 239 // doesn't return correct value. | 236 // doesn't return correct value. |
| 240 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 237 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 241 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 238 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| 242 EXPECT_EQ(round(shelf_bounds.right() + | 239 EXPECT_EQ(round(shelf_bounds.right() + |
| (...skipping 11 matching lines...) Expand all Loading... |
| 254 UpdateDisplay("1000x500,0+600-100x500"); | 251 UpdateDisplay("1000x500,0+600-100x500"); |
| 255 | 252 |
| 256 WmShelf* shelf = GetPrimaryShelf(); | 253 WmShelf* shelf = GetPrimaryShelf(); |
| 257 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 254 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
| 258 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 255 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
| 259 | 256 |
| 260 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 257 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
| 261 EXPECT_EQ(1, GetToastSerial()); | 258 EXPECT_EQ(1, GetToastSerial()); |
| 262 | 259 |
| 263 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 260 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
| 264 gfx::Rect root_bounds = | 261 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
| 265 ScreenUtil::GetShelfDisplayBoundsInRoot(Shell::GetPrimaryRootWindow()); | |
| 266 | 262 |
| 267 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 263 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
| 268 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); | 264 EXPECT_TRUE(root_bounds.Contains(toast_bounds)); |
| 269 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 265 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
| 270 | 266 |
| 271 if (SupportsHostWindowResize()) { | 267 if (SupportsHostWindowResize()) { |
| 272 // If host resize is not supported then calling WmShelf::GetIdealBounds() | 268 // If host resize is not supported then calling WmShelf::GetIdealBounds() |
| 273 // doesn't return correct value. | 269 // doesn't return correct value. |
| 274 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 270 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
| 275 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 271 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 296 EXPECT_EQ("TEXT3", GetCurrentText()); | 292 EXPECT_EQ("TEXT3", GetCurrentText()); |
| 297 // Cancel the shown toast. | 293 // Cancel the shown toast. |
| 298 CancelToast(id3); | 294 CancelToast(id3); |
| 299 // Confirm that the shown toast disappears. | 295 // Confirm that the shown toast disappears. |
| 300 EXPECT_FALSE(GetCurrentOverlay()); | 296 EXPECT_FALSE(GetCurrentOverlay()); |
| 301 // Confirm that only 1 toast is shown. | 297 // Confirm that only 1 toast is shown. |
| 302 EXPECT_EQ(2, GetToastSerial()); | 298 EXPECT_EQ(2, GetToastSerial()); |
| 303 } | 299 } |
| 304 | 300 |
| 305 } // namespace ash | 301 } // namespace ash |
| OLD | NEW |