| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/web_notification/ash_popup_alignment_delegate.h" | 5 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 11 #include "ash/display/window_tree_host_manager.h" |
| 11 #include "ash/screen_util.h" | 12 #include "ash/screen_util.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 13 #include "ash/shelf/shelf_layout_manager.h" |
| 13 #include "ash/shelf/shelf_types.h" | 14 #include "ash/shelf/shelf_types.h" |
| 14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 15 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
| 16 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 17 #include "base/command_line.h" | 18 #include "base/command_line.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
| 20 #include "ui/keyboard/keyboard_switches.h" | 21 #include "ui/keyboard/keyboard_switches.h" |
| 21 #include "ui/keyboard/keyboard_util.h" | 22 #include "ui/keyboard/keyboard_util.h" |
| 22 #include "ui/message_center/message_center_style.h" | 23 #include "ui/message_center/message_center_style.h" |
| 23 | 24 |
| 24 namespace ash { | 25 namespace ash { |
| 25 | 26 |
| 26 class AshPopupAlignmentDelegateTest : public test::AshTestBase { | 27 class AshPopupAlignmentDelegateTest : public test::AshTestBase { |
| 27 public: | 28 public: |
| 28 AshPopupAlignmentDelegateTest() {} | 29 AshPopupAlignmentDelegateTest() {} |
| 29 ~AshPopupAlignmentDelegateTest() override {} | 30 ~AshPopupAlignmentDelegateTest() override {} |
| 30 | 31 |
| 31 void SetUp() override { | 32 void SetUp() override { |
| 32 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 33 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 33 keyboard::switches::kEnableVirtualKeyboard); | 34 keyboard::switches::kEnableVirtualKeyboard); |
| 34 test::AshTestBase::SetUp(); | 35 test::AshTestBase::SetUp(); |
| 35 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate())); | 36 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( |
| 37 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())))); |
| 36 } | 38 } |
| 37 | 39 |
| 38 void TearDown() override { | 40 void TearDown() override { |
| 39 alignment_delegate_.reset(); | 41 alignment_delegate_.reset(); |
| 40 test::AshTestBase::TearDown(); | 42 test::AshTestBase::TearDown(); |
| 41 } | 43 } |
| 42 | 44 |
| 43 void SetKeyboardBounds(const gfx::Rect& new_bounds) { | 45 void SetKeyboardBounds(const gfx::Rect& new_bounds) { |
| 44 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow()) | 46 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow()) |
| 45 ->OnKeyboardBoundsChanging(new_bounds); | 47 ->OnKeyboardBoundsChanging(new_bounds); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 259 | 261 |
| 260 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 262 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
| 261 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, | 263 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, |
| 262 alignment_delegate()->GetBaseLine()); | 264 alignment_delegate()->GetBaseLine()); |
| 263 } | 265 } |
| 264 | 266 |
| 265 TEST_F(AshPopupAlignmentDelegateTest, Extended) { | 267 TEST_F(AshPopupAlignmentDelegateTest, Extended) { |
| 266 if (!SupportsMultipleDisplays()) | 268 if (!SupportsMultipleDisplays()) |
| 267 return; | 269 return; |
| 268 UpdateDisplay("600x600,800x800"); | 270 UpdateDisplay("600x600,800x800"); |
| 269 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate())); | 271 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( |
| 272 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())))); |
| 270 | 273 |
| 271 AshPopupAlignmentDelegate for_2nd_display; | 274 gfx::Display second_display = ScreenUtil::GetSecondaryDisplay(); |
| 272 UpdateWorkArea(&for_2nd_display, ScreenUtil::GetSecondaryDisplay()); | 275 aura::Window* second_root = |
| 276 Shell::GetInstance() |
| 277 ->window_tree_host_manager() |
| 278 ->GetRootWindowForDisplayId(second_display.id()); |
| 279 AshPopupAlignmentDelegate for_2nd_display( |
| 280 ShelfLayoutManager::ForShelf(second_root)); |
| 281 UpdateWorkArea(&for_2nd_display, second_display); |
| 273 // Make sure that the toast position on the secondary display is | 282 // Make sure that the toast position on the secondary display is |
| 274 // positioned correctly. | 283 // positioned correctly. |
| 275 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 284 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
| 276 EXPECT_LT(700, for_2nd_display.GetBaseLine()); | 285 EXPECT_LT(700, for_2nd_display.GetBaseLine()); |
| 277 } | 286 } |
| 278 | 287 |
| 279 TEST_F(AshPopupAlignmentDelegateTest, Unified) { | 288 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
| 280 if (!SupportsMultipleDisplays()) | 289 if (!SupportsMultipleDisplays()) |
| 281 return; | 290 return; |
| 282 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 291 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 283 display_manager->SetUnifiedDesktopEnabled(true); | 292 display_manager->SetUnifiedDesktopEnabled(true); |
| 284 | 293 |
| 285 // Reset the delegate as the primary display's shelf will be destroyed during | 294 // Reset the delegate as the primary display's shelf will be destroyed during |
| 286 // transition. | 295 // transition. |
| 287 SetAlignmentDelegate(scoped_ptr<AshPopupAlignmentDelegate>()); | 296 SetAlignmentDelegate(nullptr); |
| 288 | 297 |
| 289 UpdateDisplay("600x600,800x800"); | 298 UpdateDisplay("600x600,800x800"); |
| 290 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate())); | 299 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( |
| 300 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())))); |
| 291 | 301 |
| 292 EXPECT_GT(600, | 302 EXPECT_GT(600, |
| 293 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 303 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
| 294 } | 304 } |
| 295 | 305 |
| 296 // Tests that when the keyboard is showing that notifications appear above it, | 306 // Tests that when the keyboard is showing that notifications appear above it, |
| 297 // and that they return to normal once the keyboard is gone. | 307 // and that they return to normal once the keyboard is gone. |
| 298 TEST_F(AshPopupAlignmentDelegateTest, KeyboardShowing) { | 308 TEST_F(AshPopupAlignmentDelegateTest, KeyboardShowing) { |
| 299 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 309 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
| 300 ASSERT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 310 ASSERT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
| 301 | 311 |
| 302 UpdateDisplay("600x600"); | 312 UpdateDisplay("600x600"); |
| 303 int baseline = alignment_delegate()->GetBaseLine(); | 313 int baseline = alignment_delegate()->GetBaseLine(); |
| 304 | 314 |
| 305 gfx::Rect keyboard_bounds(0, 300, 600, 300); | 315 gfx::Rect keyboard_bounds(0, 300, 600, 300); |
| 306 SetKeyboardBounds(keyboard_bounds); | 316 SetKeyboardBounds(keyboard_bounds); |
| 307 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 317 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
| 308 EXPECT_NE(baseline, keyboard_baseline); | 318 EXPECT_NE(baseline, keyboard_baseline); |
| 309 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 319 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
| 310 | 320 |
| 311 SetKeyboardBounds(gfx::Rect()); | 321 SetKeyboardBounds(gfx::Rect()); |
| 312 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 322 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
| 313 } | 323 } |
| 314 | 324 |
| 315 } // namespace ash | 325 } // namespace ash |
| OLD | NEW |