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/common/system/web_notification/ash_popup_alignment_delegate.h" | 5 #include "ash/common/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/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
11 #include "ash/common/wm_lookup.h" | 11 #include "ash/common/wm_lookup.h" |
12 #include "ash/common/wm_root_window_controller.h" | 12 #include "ash/common/wm_root_window_controller.h" |
13 #include "ash/common/wm_window.h" | 13 #include "ash/common/wm_window.h" |
14 #include "ash/display/display_manager.h" | |
15 #include "ash/public/cpp/shelf_types.h" | 14 #include "ash/public/cpp/shelf_types.h" |
16 #include "ash/public/cpp/shell_window_ids.h" | 15 #include "ash/public/cpp/shell_window_ids.h" |
17 #include "ash/shell.h" | 16 #include "ash/shell.h" |
18 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
19 #include "base/command_line.h" | 18 #include "base/command_line.h" |
20 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "ui/display/manager/display_manager.h" |
21 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
22 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
23 #include "ui/keyboard/keyboard_switches.h" | 23 #include "ui/keyboard/keyboard_switches.h" |
24 #include "ui/keyboard/keyboard_util.h" | 24 #include "ui/keyboard/keyboard_util.h" |
25 #include "ui/message_center/message_center_style.h" | 25 #include "ui/message_center/message_center_style.h" |
26 | 26 |
27 namespace ash { | 27 namespace ash { |
28 | 28 |
29 // TODO(jamescook): Move this to //ash/common. http://crbug.com/620955 | 29 // TODO(jamescook): Move this to //ash/common. http://crbug.com/620955 |
30 class AshPopupAlignmentDelegateTest : public test::AshTestBase { | 30 class AshPopupAlignmentDelegateTest : public test::AshTestBase { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 return; | 212 return; |
213 | 213 |
214 const gfx::Rect toast_size(0, 0, 10, 10); | 214 const gfx::Rect toast_size(0, 0, 10, 10); |
215 UpdateDisplay("600x600"); | 215 UpdateDisplay("600x600"); |
216 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 216 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
217 int baseline = alignment_delegate()->GetBaseLine(); | 217 int baseline = alignment_delegate()->GetBaseLine(); |
218 | 218 |
219 // Emulate the docked mode; enter to an extended mode, then invoke | 219 // Emulate the docked mode; enter to an extended mode, then invoke |
220 // OnNativeDisplaysChanged() with the info for the secondary display only. | 220 // OnNativeDisplaysChanged() with the info for the secondary display only. |
221 UpdateDisplay("600x600,800x800"); | 221 UpdateDisplay("600x600,800x800"); |
222 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
223 | 222 |
224 std::vector<display::ManagedDisplayInfo> new_info; | 223 std::vector<display::ManagedDisplayInfo> new_info; |
225 new_info.push_back( | 224 new_info.push_back(display_manager()->GetDisplayInfo( |
226 display_manager->GetDisplayInfo(display_manager->GetDisplayAt(1u).id())); | 225 display_manager()->GetDisplayAt(1u).id())); |
227 display_manager->OnNativeDisplaysChanged(new_info); | 226 display_manager()->OnNativeDisplaysChanged(new_info); |
228 | 227 |
229 EXPECT_LT(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 228 EXPECT_LT(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
230 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); | 229 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); |
231 } | 230 } |
232 | 231 |
233 TEST_F(AshPopupAlignmentDelegateTest, TrayHeight) { | 232 TEST_F(AshPopupAlignmentDelegateTest, TrayHeight) { |
234 const gfx::Rect toast_size(0, 0, 10, 10); | 233 const gfx::Rect toast_size(0, 0, 10, 10); |
235 UpdateDisplay("600x600"); | 234 UpdateDisplay("600x600"); |
236 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 235 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
237 int baseline = alignment_delegate()->GetBaseLine(); | 236 int baseline = alignment_delegate()->GetBaseLine(); |
238 | 237 |
239 // Simulate the system tray bubble being open. | 238 // Simulate the system tray bubble being open. |
240 const int kTrayHeight = 100; | 239 const int kTrayHeight = 100; |
241 alignment_delegate()->SetTrayBubbleHeight(kTrayHeight); | 240 alignment_delegate()->SetTrayBubbleHeight(kTrayHeight); |
242 | 241 |
243 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 242 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
244 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, | 243 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, |
245 alignment_delegate()->GetBaseLine()); | 244 alignment_delegate()->GetBaseLine()); |
246 } | 245 } |
247 | 246 |
248 TEST_F(AshPopupAlignmentDelegateTest, Extended) { | 247 TEST_F(AshPopupAlignmentDelegateTest, Extended) { |
249 if (!SupportsMultipleDisplays()) | 248 if (!SupportsMultipleDisplays()) |
250 return; | 249 return; |
251 UpdateDisplay("600x600,800x800"); | 250 UpdateDisplay("600x600,800x800"); |
252 SetAlignmentDelegate( | 251 SetAlignmentDelegate( |
253 base::MakeUnique<AshPopupAlignmentDelegate>(GetPrimaryShelf())); | 252 base::MakeUnique<AshPopupAlignmentDelegate>(GetPrimaryShelf())); |
254 | 253 |
255 display::Display second_display = | 254 display::Display second_display = display_manager()->GetDisplayAt(1u); |
256 Shell::GetInstance()->display_manager()->GetDisplayAt(1u); | |
257 WmShelf* second_shelf = | 255 WmShelf* second_shelf = |
258 WmLookup::Get() | 256 WmLookup::Get() |
259 ->GetRootWindowControllerWithDisplayId(second_display.id()) | 257 ->GetRootWindowControllerWithDisplayId(second_display.id()) |
260 ->GetShelf(); | 258 ->GetShelf(); |
261 AshPopupAlignmentDelegate for_2nd_display(second_shelf); | 259 AshPopupAlignmentDelegate for_2nd_display(second_shelf); |
262 UpdateWorkArea(&for_2nd_display, second_display); | 260 UpdateWorkArea(&for_2nd_display, second_display); |
263 // Make sure that the toast position on the secondary display is | 261 // Make sure that the toast position on the secondary display is |
264 // positioned correctly. | 262 // positioned correctly. |
265 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); | 263 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
266 EXPECT_LT(700, for_2nd_display.GetBaseLine()); | 264 EXPECT_LT(700, for_2nd_display.GetBaseLine()); |
267 } | 265 } |
268 | 266 |
269 TEST_F(AshPopupAlignmentDelegateTest, Unified) { | 267 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
270 if (!SupportsMultipleDisplays()) | 268 if (!SupportsMultipleDisplays()) |
271 return; | 269 return; |
272 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 270 display_manager()->SetUnifiedDesktopEnabled(true); |
273 display_manager->SetUnifiedDesktopEnabled(true); | |
274 | 271 |
275 // Reset the delegate as the primary display's shelf will be destroyed during | 272 // Reset the delegate as the primary display's shelf will be destroyed during |
276 // transition. | 273 // transition. |
277 SetAlignmentDelegate(nullptr); | 274 SetAlignmentDelegate(nullptr); |
278 | 275 |
279 UpdateDisplay("600x600,800x800"); | 276 UpdateDisplay("600x600,800x800"); |
280 SetAlignmentDelegate( | 277 SetAlignmentDelegate( |
281 base::MakeUnique<AshPopupAlignmentDelegate>(GetPrimaryShelf())); | 278 base::MakeUnique<AshPopupAlignmentDelegate>(GetPrimaryShelf())); |
282 | 279 |
283 EXPECT_GT(600, | 280 EXPECT_GT(600, |
(...skipping 20 matching lines...) Expand all Loading... |
304 shelf->SetVirtualKeyboardBoundsForTesting(keyboard_bounds); | 301 shelf->SetVirtualKeyboardBoundsForTesting(keyboard_bounds); |
305 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 302 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
306 EXPECT_NE(baseline, keyboard_baseline); | 303 EXPECT_NE(baseline, keyboard_baseline); |
307 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 304 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
308 | 305 |
309 shelf->SetVirtualKeyboardBoundsForTesting(gfx::Rect()); | 306 shelf->SetVirtualKeyboardBoundsForTesting(gfx::Rect()); |
310 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 307 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
311 } | 308 } |
312 | 309 |
313 } // namespace ash | 310 } // namespace ash |
OLD | NEW |