| 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/display/window_tree_host_manager.h" |
| 12 #include "ash/screen_util.h" | 12 #include "ash/screen_util.h" |
| 13 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_layout_manager.h" | 14 #include "ash/shelf/shelf_layout_manager.h" |
| 14 #include "ash/shelf/shelf_types.h" | 15 #include "ash/shelf/shelf_types.h" |
| 15 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 16 #include "ash/shell_window_ids.h" | 17 #include "ash/shell_window_ids.h" |
| 17 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 18 #include "base/command_line.h" | 19 #include "base/command_line.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 20 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 21 #include "ui/keyboard/keyboard_switches.h" | 22 #include "ui/keyboard/keyboard_switches.h" |
| 22 #include "ui/keyboard/keyboard_util.h" | 23 #include "ui/keyboard/keyboard_util.h" |
| 23 #include "ui/message_center/message_center_style.h" | 24 #include "ui/message_center/message_center_style.h" |
| 24 | 25 |
| 25 namespace ash { | 26 namespace ash { |
| 26 | 27 |
| 27 class AshPopupAlignmentDelegateTest : public test::AshTestBase { | 28 class AshPopupAlignmentDelegateTest : public test::AshTestBase { |
| 28 public: | 29 public: |
| 29 AshPopupAlignmentDelegateTest() {} | 30 AshPopupAlignmentDelegateTest() {} |
| 30 ~AshPopupAlignmentDelegateTest() override {} | 31 ~AshPopupAlignmentDelegateTest() override {} |
| 31 | 32 |
| 32 void SetUp() override { | 33 void SetUp() override { |
| 33 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 34 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 34 keyboard::switches::kEnableVirtualKeyboard); | 35 keyboard::switches::kEnableVirtualKeyboard); |
| 35 test::AshTestBase::SetUp(); | 36 test::AshTestBase::SetUp(); |
| 36 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( | 37 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( |
| 37 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())))); | 38 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void TearDown() override { | 41 void TearDown() override { |
| 41 alignment_delegate_.reset(); | 42 alignment_delegate_.reset(); |
| 42 test::AshTestBase::TearDown(); | 43 test::AshTestBase::TearDown(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void SetKeyboardBounds(const gfx::Rect& new_bounds) { | 46 void SetKeyboardBounds(const gfx::Rect& new_bounds) { |
| 46 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow()) | 47 Shelf::ForPrimaryDisplay() |
| 48 ->shelf_layout_manager() |
| 47 ->OnKeyboardBoundsChanging(new_bounds); | 49 ->OnKeyboardBoundsChanging(new_bounds); |
| 48 } | 50 } |
| 49 | 51 |
| 50 protected: | 52 protected: |
| 51 enum Position { | 53 enum Position { |
| 52 TOP_LEFT, | 54 TOP_LEFT, |
| 53 TOP_RIGHT, | 55 TOP_RIGHT, |
| 54 BOTTOM_LEFT, | 56 BOTTOM_LEFT, |
| 55 BOTTOM_RIGHT, | 57 BOTTOM_RIGHT, |
| 56 OUTSIDE | 58 OUTSIDE |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 const gfx::Rect toast_size(0, 0, 10, 10); | 174 const gfx::Rect toast_size(0, 0, 10, 10); |
| 173 UpdateDisplay("600x600"); | 175 UpdateDisplay("600x600"); |
| 174 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 176 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
| 175 int baseline = alignment_delegate()->GetBaseLine(); | 177 int baseline = alignment_delegate()->GetBaseLine(); |
| 176 | 178 |
| 177 // Create a window, otherwise autohide doesn't work. | 179 // Create a window, otherwise autohide doesn't work. |
| 178 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); | 180 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(0)); |
| 179 Shell::GetInstance()->SetShelfAutoHideBehavior( | 181 Shell::GetInstance()->SetShelfAutoHideBehavior( |
| 180 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, | 182 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS, |
| 181 Shell::GetPrimaryRootWindow()); | 183 Shell::GetPrimaryRootWindow()); |
| 182 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())-> | 184 Shelf::ForPrimaryDisplay()->shelf_layout_manager()->UpdateAutoHideStateNow(); |
| 183 UpdateAutoHideStateNow(); | |
| 184 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 185 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
| 185 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); | 186 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); |
| 186 } | 187 } |
| 187 | 188 |
| 188 // Verify that docked window doesn't affect the popup alignment. | 189 // Verify that docked window doesn't affect the popup alignment. |
| 189 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { | 190 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { |
| 190 const gfx::Rect toast_size(0, 0, 10, 10); | 191 const gfx::Rect toast_size(0, 0, 10, 10); |
| 191 UpdateDisplay("600x600"); | 192 UpdateDisplay("600x600"); |
| 192 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 193 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
| 193 int baseline = alignment_delegate()->GetBaseLine(); | 194 int baseline = alignment_delegate()->GetBaseLine(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 275 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
| 275 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, | 276 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, |
| 276 alignment_delegate()->GetBaseLine()); | 277 alignment_delegate()->GetBaseLine()); |
| 277 } | 278 } |
| 278 | 279 |
| 279 TEST_F(AshPopupAlignmentDelegateTest, Extended) { | 280 TEST_F(AshPopupAlignmentDelegateTest, Extended) { |
| 280 if (!SupportsMultipleDisplays()) | 281 if (!SupportsMultipleDisplays()) |
| 281 return; | 282 return; |
| 282 UpdateDisplay("600x600,800x800"); | 283 UpdateDisplay("600x600,800x800"); |
| 283 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( | 284 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( |
| 284 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())))); | 285 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
| 285 | 286 |
| 286 gfx::Display second_display = ScreenUtil::GetSecondaryDisplay(); | 287 gfx::Display second_display = ScreenUtil::GetSecondaryDisplay(); |
| 287 aura::Window* second_root = | 288 aura::Window* second_root = |
| 288 Shell::GetInstance() | 289 Shell::GetInstance() |
| 289 ->window_tree_host_manager() | 290 ->window_tree_host_manager() |
| 290 ->GetRootWindowForDisplayId(second_display.id()); | 291 ->GetRootWindowForDisplayId(second_display.id()); |
| 291 AshPopupAlignmentDelegate for_2nd_display( | 292 AshPopupAlignmentDelegate for_2nd_display( |
| 292 ShelfLayoutManager::ForShelf(second_root)); | 293 Shelf::ForWindow(second_root)->shelf_layout_manager()); |
| 293 UpdateWorkArea(&for_2nd_display, second_display); | 294 UpdateWorkArea(&for_2nd_display, second_display); |
| 294 // Make sure that the toast position on the secondary display is | 295 // Make sure that the toast position on the secondary display is |
| 295 // positioned correctly. | 296 // positioned correctly. |
| 296 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 297 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
| 297 EXPECT_LT(700, for_2nd_display.GetBaseLine()); | 298 EXPECT_LT(700, for_2nd_display.GetBaseLine()); |
| 298 } | 299 } |
| 299 | 300 |
| 300 TEST_F(AshPopupAlignmentDelegateTest, Unified) { | 301 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
| 301 if (!SupportsMultipleDisplays()) | 302 if (!SupportsMultipleDisplays()) |
| 302 return; | 303 return; |
| 303 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 304 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 304 display_manager->SetUnifiedDesktopEnabled(true); | 305 display_manager->SetUnifiedDesktopEnabled(true); |
| 305 | 306 |
| 306 // Reset the delegate as the primary display's shelf will be destroyed during | 307 // Reset the delegate as the primary display's shelf will be destroyed during |
| 307 // transition. | 308 // transition. |
| 308 SetAlignmentDelegate(nullptr); | 309 SetAlignmentDelegate(nullptr); |
| 309 | 310 |
| 310 UpdateDisplay("600x600,800x800"); | 311 UpdateDisplay("600x600,800x800"); |
| 311 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( | 312 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate( |
| 312 ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow())))); | 313 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); |
| 313 | 314 |
| 314 EXPECT_GT(600, | 315 EXPECT_GT(600, |
| 315 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 316 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
| 316 } | 317 } |
| 317 | 318 |
| 318 // Tests that when the keyboard is showing that notifications appear above it, | 319 // Tests that when the keyboard is showing that notifications appear above it, |
| 319 // and that they return to normal once the keyboard is gone. | 320 // and that they return to normal once the keyboard is gone. |
| 320 #if defined(OS_WIN) && !defined(USE_ASH) | 321 #if defined(OS_WIN) && !defined(USE_ASH) |
| 321 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 322 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
| 322 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing | 323 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing |
| (...skipping 11 matching lines...) Expand all Loading... |
| 334 SetKeyboardBounds(keyboard_bounds); | 335 SetKeyboardBounds(keyboard_bounds); |
| 335 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 336 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
| 336 EXPECT_NE(baseline, keyboard_baseline); | 337 EXPECT_NE(baseline, keyboard_baseline); |
| 337 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 338 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
| 338 | 339 |
| 339 SetKeyboardBounds(gfx::Rect()); | 340 SetKeyboardBounds(gfx::Rect()); |
| 340 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 341 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
| 341 } | 342 } |
| 342 | 343 |
| 343 } // namespace ash | 344 } // namespace ash |
| OLD | NEW |