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/common/shelf/shelf_types.h" | 10 #include "ash/common/shelf/shelf_types.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" |
11 #include "ash/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
| 13 #include "ash/common/wm_lookup.h" |
12 #include "ash/common/wm_root_window_controller.h" | 14 #include "ash/common/wm_root_window_controller.h" |
13 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
14 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
15 #include "ash/display/display_manager.h" | 17 #include "ash/display/display_manager.h" |
16 #include "ash/screen_util.h" | 18 #include "ash/screen_util.h" |
17 #include "ash/shelf/shelf.h" | 19 #include "ash/shelf/shelf.h" |
18 #include "ash/shelf/shelf_layout_manager.h" | 20 #include "ash/shelf/shelf_layout_manager.h" |
19 #include "ash/shell.h" | 21 #include "ash/shell.h" |
20 #include "ash/test/ash_test_base.h" | 22 #include "ash/test/ash_test_base.h" |
21 #include "base/command_line.h" | 23 #include "base/command_line.h" |
22 #include "base/memory/ptr_util.h" | 24 #include "base/memory/ptr_util.h" |
23 #include "ui/display/screen.h" | 25 #include "ui/display/screen.h" |
24 #include "ui/gfx/geometry/rect.h" | 26 #include "ui/gfx/geometry/rect.h" |
25 #include "ui/keyboard/keyboard_switches.h" | 27 #include "ui/keyboard/keyboard_switches.h" |
26 #include "ui/keyboard/keyboard_util.h" | 28 #include "ui/keyboard/keyboard_util.h" |
27 #include "ui/message_center/message_center_style.h" | 29 #include "ui/message_center/message_center_style.h" |
28 | 30 |
29 namespace ash { | 31 namespace ash { |
30 | 32 |
31 class AshPopupAlignmentDelegateTest : public test::AshTestBase { | 33 class AshPopupAlignmentDelegateTest : public test::AshTestBase { |
32 public: | 34 public: |
33 AshPopupAlignmentDelegateTest() {} | 35 AshPopupAlignmentDelegateTest() {} |
34 ~AshPopupAlignmentDelegateTest() override {} | 36 ~AshPopupAlignmentDelegateTest() override {} |
35 | 37 |
36 void SetUp() override { | 38 void SetUp() override { |
37 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 39 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
38 keyboard::switches::kEnableVirtualKeyboard); | 40 keyboard::switches::kEnableVirtualKeyboard); |
39 test::AshTestBase::SetUp(); | 41 test::AshTestBase::SetUp(); |
40 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( | 42 SetAlignmentDelegate( |
41 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 43 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); |
42 } | 44 } |
43 | 45 |
44 void TearDown() override { | 46 void TearDown() override { |
45 alignment_delegate_.reset(); | 47 alignment_delegate_.reset(); |
46 test::AshTestBase::TearDown(); | 48 test::AshTestBase::TearDown(); |
47 } | 49 } |
48 | 50 |
49 void SetKeyboardBounds(const gfx::Rect& new_bounds) { | 51 void SetKeyboardBounds(const gfx::Rect& new_bounds) { |
50 Shelf::ForPrimaryDisplay() | 52 Shelf::ForPrimaryDisplay() |
51 ->shelf_layout_manager() | 53 ->shelf_layout_manager() |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ->GetRootWindowController() | 114 ->GetRootWindowController() |
113 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id, | 115 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id, |
114 ¶ms); | 116 ¶ms); |
115 widget->Init(params); | 117 widget->Init(params); |
116 widget->Show(); | 118 widget->Show(); |
117 return widget; | 119 return widget; |
118 } | 120 } |
119 | 121 |
120 private: | 122 private: |
121 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; | 123 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; |
| 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(AshPopupAlignmentDelegateTest); |
122 }; | 126 }; |
123 | 127 |
124 #if defined(OS_WIN) && !defined(USE_ASH) | 128 #if defined(OS_WIN) && !defined(USE_ASH) |
125 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 129 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
126 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment | 130 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment |
127 #else | 131 #else |
128 #define MAYBE_ShelfAlignment ShelfAlignment | 132 #define MAYBE_ShelfAlignment ShelfAlignment |
129 #endif | 133 #endif |
130 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) { | 134 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) { |
131 const gfx::Rect toast_size(0, 0, 10, 10); | 135 const gfx::Rect toast_size(0, 0, 10, 10); |
132 UpdateDisplay("600x600"); | 136 UpdateDisplay("600x600"); |
133 gfx::Point toast_point; | 137 gfx::Point toast_point; |
134 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); | 138 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); |
135 toast_point.set_y(alignment_delegate()->GetBaseLine()); | 139 toast_point.set_y(alignment_delegate()->GetBaseLine()); |
136 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); | 140 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); |
137 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 141 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
138 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 142 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
139 | 143 |
140 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_RIGHT); | 144 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
141 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); | 145 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); |
142 toast_point.set_y(alignment_delegate()->GetBaseLine()); | 146 toast_point.set_y(alignment_delegate()->GetBaseLine()); |
143 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); | 147 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); |
144 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 148 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
145 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 149 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
146 | 150 |
147 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT); | 151 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); |
148 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); | 152 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); |
149 toast_point.set_y(alignment_delegate()->GetBaseLine()); | 153 toast_point.set_y(alignment_delegate()->GetBaseLine()); |
150 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point)); | 154 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point)); |
151 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 155 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
152 EXPECT_TRUE(alignment_delegate()->IsFromLeft()); | 156 EXPECT_TRUE(alignment_delegate()->IsFromLeft()); |
153 } | 157 } |
154 | 158 |
155 TEST_F(AshPopupAlignmentDelegateTest, LockScreen) { | 159 TEST_F(AshPopupAlignmentDelegateTest, LockScreen) { |
156 if (!SupportsHostWindowResize()) | 160 if (!SupportsHostWindowResize()) |
157 return; | 161 return; |
158 | 162 |
159 const gfx::Rect toast_size(0, 0, 10, 10); | 163 const gfx::Rect toast_size(0, 0, 10, 10); |
160 | 164 |
161 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT); | 165 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); |
162 gfx::Point toast_point; | 166 gfx::Point toast_point; |
163 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); | 167 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); |
164 toast_point.set_y(alignment_delegate()->GetBaseLine()); | 168 toast_point.set_y(alignment_delegate()->GetBaseLine()); |
165 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point)); | 169 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point)); |
166 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 170 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
167 EXPECT_TRUE(alignment_delegate()->IsFromLeft()); | 171 EXPECT_TRUE(alignment_delegate()->IsFromLeft()); |
168 | 172 |
169 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); | 173 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); |
170 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); | 174 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); |
171 toast_point.set_y(alignment_delegate()->GetBaseLine()); | 175 toast_point.set_y(alignment_delegate()->GetBaseLine()); |
(...skipping 28 matching lines...) Expand all Loading... |
200 std::unique_ptr<views::Widget> widget = | 204 std::unique_ptr<views::Widget> widget = |
201 CreateTestWidget(kShellWindowId_DockedContainer); | 205 CreateTestWidget(kShellWindowId_DockedContainer); |
202 | 206 |
203 // Left-side dock should not affect popup alignment | 207 // Left-side dock should not affect popup alignment |
204 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 208 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
205 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 209 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
206 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 210 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
207 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 211 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
208 | 212 |
209 // Force dock to right-side | 213 // Force dock to right-side |
210 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT); | 214 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); |
211 Shelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 215 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
212 | 216 |
213 // Right-side dock should not affect popup alignment | 217 // Right-side dock should not affect popup alignment |
214 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 218 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
215 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 219 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
216 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 220 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
217 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 221 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
218 } | 222 } |
219 | 223 |
220 #if defined(OS_WIN) && !defined(USE_ASH) | 224 #if defined(OS_WIN) && !defined(USE_ASH) |
221 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 225 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 276 |
273 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 277 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
274 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, | 278 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, |
275 alignment_delegate()->GetBaseLine()); | 279 alignment_delegate()->GetBaseLine()); |
276 } | 280 } |
277 | 281 |
278 TEST_F(AshPopupAlignmentDelegateTest, Extended) { | 282 TEST_F(AshPopupAlignmentDelegateTest, Extended) { |
279 if (!SupportsMultipleDisplays()) | 283 if (!SupportsMultipleDisplays()) |
280 return; | 284 return; |
281 UpdateDisplay("600x600,800x800"); | 285 UpdateDisplay("600x600,800x800"); |
282 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( | 286 SetAlignmentDelegate( |
283 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 287 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); |
284 | 288 |
285 display::Display second_display = ScreenUtil::GetSecondaryDisplay(); | 289 display::Display second_display = ScreenUtil::GetSecondaryDisplay(); |
286 AshPopupAlignmentDelegate for_2nd_display( | 290 WmShelf* second_shelf = |
287 Shelf::ForDisplayId(second_display.id())->shelf_layout_manager()); | 291 WmLookup::Get() |
| 292 ->GetRootWindowControllerWithDisplayId(second_display.id()) |
| 293 ->GetShelf(); |
| 294 AshPopupAlignmentDelegate for_2nd_display(second_shelf); |
288 UpdateWorkArea(&for_2nd_display, second_display); | 295 UpdateWorkArea(&for_2nd_display, second_display); |
289 // Make sure that the toast position on the secondary display is | 296 // Make sure that the toast position on the secondary display is |
290 // positioned correctly. | 297 // positioned correctly. |
291 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 298 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
292 EXPECT_LT(700, for_2nd_display.GetBaseLine()); | 299 EXPECT_LT(700, for_2nd_display.GetBaseLine()); |
293 } | 300 } |
294 | 301 |
295 TEST_F(AshPopupAlignmentDelegateTest, Unified) { | 302 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
296 if (!SupportsMultipleDisplays()) | 303 if (!SupportsMultipleDisplays()) |
297 return; | 304 return; |
298 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 305 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
299 display_manager->SetUnifiedDesktopEnabled(true); | 306 display_manager->SetUnifiedDesktopEnabled(true); |
300 | 307 |
301 // Reset the delegate as the primary display's shelf will be destroyed during | 308 // Reset the delegate as the primary display's shelf will be destroyed during |
302 // transition. | 309 // transition. |
303 SetAlignmentDelegate(nullptr); | 310 SetAlignmentDelegate(nullptr); |
304 | 311 |
305 UpdateDisplay("600x600,800x800"); | 312 UpdateDisplay("600x600,800x800"); |
306 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( | 313 SetAlignmentDelegate( |
307 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); | 314 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); |
308 | 315 |
309 EXPECT_GT(600, | 316 EXPECT_GT(600, |
310 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 317 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
311 } | 318 } |
312 | 319 |
313 // Tests that when the keyboard is showing that notifications appear above it, | 320 // Tests that when the keyboard is showing that notifications appear above it, |
314 // and that they return to normal once the keyboard is gone. | 321 // and that they return to normal once the keyboard is gone. |
315 #if defined(OS_WIN) && !defined(USE_ASH) | 322 #if defined(OS_WIN) && !defined(USE_ASH) |
316 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 323 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
317 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing | 324 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing |
(...skipping 11 matching lines...) Expand all Loading... |
329 SetKeyboardBounds(keyboard_bounds); | 336 SetKeyboardBounds(keyboard_bounds); |
330 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 337 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
331 EXPECT_NE(baseline, keyboard_baseline); | 338 EXPECT_NE(baseline, keyboard_baseline); |
332 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 339 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
333 | 340 |
334 SetKeyboardBounds(gfx::Rect()); | 341 SetKeyboardBounds(gfx::Rect()); |
335 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 342 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
336 } | 343 } |
337 | 344 |
338 } // namespace ash | 345 } // namespace ash |
OLD | NEW |