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/wm_screen_util.h" |
9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 | 164 |
165 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 165 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
166 EXPECT_EQ(1, GetToastSerial()); | 166 EXPECT_EQ(1, GetToastSerial()); |
167 | 167 |
168 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 168 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
169 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); | 169 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
170 | 170 |
171 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 171 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
172 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); | 172 EXPECT_NEAR(root_bounds.CenterPoint().x(), toast_bounds.CenterPoint().x(), 1); |
173 | 173 |
174 if (SupportsHostWindowResize()) { | 174 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() |
James Cook
2016/09/26 19:21:11
nit: delete this comment
sky
2016/09/26 19:26:36
Done.
| |
175 // If host resize is not supported, ShelfLayoutManager::GetIdealBounds() | 175 // doesn't return correct value. |
176 // doesn't return correct value. | 176 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
177 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 177 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
178 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 178 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
179 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 179 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
180 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 180 toast_bounds.bottom()); |
181 toast_bounds.bottom()); | |
182 } | |
183 } | 181 } |
184 | 182 |
185 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { | 183 TEST_F(ToastManagerTest, PositionWithAutoHiddenBottomShelf) { |
186 std::unique_ptr<aura::Window> window( | 184 std::unique_ptr<aura::Window> window( |
187 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); | 185 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 3, 4))); |
188 | 186 |
189 WmShelf* shelf = GetPrimaryShelf(); | 187 WmShelf* shelf = GetPrimaryShelf(); |
190 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 188 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
191 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 189 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
192 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); | 190 EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 226 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
229 EXPECT_EQ(1, GetToastSerial()); | 227 EXPECT_EQ(1, GetToastSerial()); |
230 | 228 |
231 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 229 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
232 gfx::RectF precise_toast_bounds(toast_bounds); | 230 gfx::RectF precise_toast_bounds(toast_bounds); |
233 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); | 231 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
234 | 232 |
235 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); | 233 EXPECT_TRUE(toast_bounds.Intersects(shelf->GetUserWorkAreaBounds())); |
236 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); | 234 EXPECT_EQ(root_bounds.bottom() - 5, toast_bounds.bottom()); |
237 | 235 |
238 if (SupportsHostWindowResize()) { | 236 // If host resize is not supported then calling WmShelf::GetIdealBounds() |
239 // If host resize is not supported then calling WmShelf::GetIdealBounds() | 237 // doesn't return correct value. |
240 // doesn't return correct value. | 238 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
241 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 239 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
242 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 240 EXPECT_EQ(round(shelf_bounds.right() + |
243 EXPECT_EQ(round(shelf_bounds.right() + | 241 (root_bounds.width() - shelf_bounds.width()) / 2.0), |
244 (root_bounds.width() - shelf_bounds.width()) / 2.0), | 242 round(precise_toast_bounds.CenterPoint().x())); |
245 round(precise_toast_bounds.CenterPoint().x())); | |
246 } | |
247 } | 243 } |
248 | 244 |
249 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { | 245 TEST_F(ToastManagerTest, PositionWithUnifiedDesktop) { |
250 if (!SupportsMultipleDisplays()) | 246 if (!SupportsMultipleDisplays()) |
251 return; | 247 return; |
252 | 248 |
253 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 249 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
254 display_manager->SetUnifiedDesktopEnabled(true); | 250 display_manager->SetUnifiedDesktopEnabled(true); |
255 UpdateDisplay("1000x500,0+600-100x500"); | 251 UpdateDisplay("1000x500,0+600-100x500"); |
256 | 252 |
257 WmShelf* shelf = GetPrimaryShelf(); | 253 WmShelf* shelf = GetPrimaryShelf(); |
258 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); | 254 EXPECT_EQ(SHELF_ALIGNMENT_BOTTOM, shelf->GetAlignment()); |
259 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); | 255 EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState()); |
260 | 256 |
261 ShowToast("DUMMY", ToastData::kInfiniteDuration); | 257 ShowToast("DUMMY", ToastData::kInfiniteDuration); |
262 EXPECT_EQ(1, GetToastSerial()); | 258 EXPECT_EQ(1, GetToastSerial()); |
263 | 259 |
264 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); | 260 gfx::Rect toast_bounds = GetCurrentWidget()->GetWindowBoundsInScreen(); |
265 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); | 261 gfx::Rect root_bounds = wm::GetDisplayBoundsWithShelf(shelf->GetWindow()); |
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 host resize is not supported then calling WmShelf::GetIdealBounds() |
272 // If host resize is not supported then calling WmShelf::GetIdealBounds() | 268 // doesn't return correct value. |
273 // doesn't return correct value. | 269 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); |
274 gfx::Rect shelf_bounds = shelf->GetIdealBounds(); | 270 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); |
275 EXPECT_FALSE(toast_bounds.Intersects(shelf_bounds)); | 271 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); |
276 EXPECT_EQ(shelf_bounds.y() - 5, toast_bounds.bottom()); | 272 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, |
277 EXPECT_EQ(root_bounds.bottom() - shelf_bounds.height() - 5, | 273 toast_bounds.bottom()); |
278 toast_bounds.bottom()); | |
279 } | |
280 } | 274 } |
281 | 275 |
282 TEST_F(ToastManagerTest, CancelToast) { | 276 TEST_F(ToastManagerTest, CancelToast) { |
283 std::string id1 = ShowToast("TEXT1", ToastData::kInfiniteDuration); | 277 std::string id1 = ShowToast("TEXT1", ToastData::kInfiniteDuration); |
284 std::string id2 = ShowToast("TEXT2", ToastData::kInfiniteDuration); | 278 std::string id2 = ShowToast("TEXT2", ToastData::kInfiniteDuration); |
285 std::string id3 = ShowToast("TEXT3", ToastData::kInfiniteDuration); | 279 std::string id3 = ShowToast("TEXT3", ToastData::kInfiniteDuration); |
286 | 280 |
287 // Confirm that the first toast is shown. | 281 // Confirm that the first toast is shown. |
288 EXPECT_EQ(base::ASCIIToUTF16("TEXT1"), GetCurrentText()); | 282 EXPECT_EQ(base::ASCIIToUTF16("TEXT1"), GetCurrentText()); |
289 // Cancel the queued toast. | 283 // Cancel the queued toast. |
290 CancelToast(id2); | 284 CancelToast(id2); |
291 // Confirm that the shown toast is still visible. | 285 // Confirm that the shown toast is still visible. |
292 EXPECT_EQ(base::ASCIIToUTF16("TEXT1"), GetCurrentText()); | 286 EXPECT_EQ(base::ASCIIToUTF16("TEXT1"), GetCurrentText()); |
293 // Cancel the shown toast. | 287 // Cancel the shown toast. |
294 CancelToast(id1); | 288 CancelToast(id1); |
295 // Confirm that the next toast is visible. | 289 // Confirm that the next toast is visible. |
296 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText()); | 290 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText()); |
297 // Cancel the shown toast. | 291 // Cancel the shown toast. |
298 CancelToast(id3); | 292 CancelToast(id3); |
299 // Confirm that the shown toast disappears. | 293 // Confirm that the shown toast disappears. |
300 EXPECT_FALSE(GetCurrentOverlay()); | 294 EXPECT_FALSE(GetCurrentOverlay()); |
301 // Confirm that only 1 toast is shown. | 295 // Confirm that only 1 toast is shown. |
302 EXPECT_EQ(2, GetToastSerial()); | 296 EXPECT_EQ(2, GetToastSerial()); |
303 } | 297 } |
304 | 298 |
305 } // namespace ash | 299 } // namespace ash |
OLD | NEW |