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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
11 #include "ash/shelf/shelf_types.h" | 11 #include "ash/shelf/shelf_types.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/shell_window_ids.h" | 13 #include "ash/shell_window_ids.h" |
14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/test/display_manager_test_api.h" |
15 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
16 #include "ui/message_center/message_center_style.h" | 17 #include "ui/message_center/message_center_style.h" |
17 | 18 |
18 namespace ash { | 19 namespace ash { |
19 | 20 |
20 class AshPopupAlignmentDelegateTest : public test::AshTestBase { | 21 class AshPopupAlignmentDelegateTest : public test::AshTestBase { |
21 public: | 22 public: |
22 AshPopupAlignmentDelegateTest() {} | 23 AshPopupAlignmentDelegateTest() {} |
23 ~AshPopupAlignmentDelegateTest() override {} | 24 ~AshPopupAlignmentDelegateTest() override {} |
24 | 25 |
25 void SetUp() override { | 26 void SetUp() override { |
26 test::AshTestBase::SetUp(); | 27 test::AshTestBase::SetUp(); |
27 alignment_delegate_.reset(new AshPopupAlignmentDelegate()); | 28 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate())); |
28 alignment_delegate_->StartObserving( | |
29 Shell::GetScreen(), Shell::GetScreen()->GetPrimaryDisplay()); | |
30 } | 29 } |
31 | 30 |
32 void TearDown() override { | 31 void TearDown() override { |
33 alignment_delegate_.reset(); | 32 alignment_delegate_.reset(); |
34 test::AshTestBase::TearDown(); | 33 test::AshTestBase::TearDown(); |
35 } | 34 } |
36 | 35 |
37 protected: | 36 protected: |
38 enum Position { | 37 enum Position { |
39 TOP_LEFT, | 38 TOP_LEFT, |
40 TOP_RIGHT, | 39 TOP_RIGHT, |
41 BOTTOM_LEFT, | 40 BOTTOM_LEFT, |
42 BOTTOM_RIGHT, | 41 BOTTOM_RIGHT, |
43 OUTSIDE | 42 OUTSIDE |
44 }; | 43 }; |
45 | 44 |
46 AshPopupAlignmentDelegate* alignment_delegate() { | 45 AshPopupAlignmentDelegate* alignment_delegate() { |
47 return alignment_delegate_.get(); | 46 return alignment_delegate_.get(); |
48 } | 47 } |
49 | 48 |
| 49 void SetAlignmentDelegate(scoped_ptr<AshPopupAlignmentDelegate> delegate) { |
| 50 if (!delegate.get()) { |
| 51 alignment_delegate_.reset(); |
| 52 return; |
| 53 } |
| 54 alignment_delegate_ = delegate.Pass(); |
| 55 alignment_delegate_->StartObserving( |
| 56 Shell::GetScreen(), Shell::GetScreen()->GetPrimaryDisplay()); |
| 57 // Update the layout |
| 58 alignment_delegate_->OnDisplayWorkAreaInsetsChanged(); |
| 59 } |
| 60 |
50 Position GetPositionInDisplay(const gfx::Point& point) { | 61 Position GetPositionInDisplay(const gfx::Point& point) { |
51 const gfx::Rect& work_area = | 62 const gfx::Rect& work_area = |
52 Shell::GetScreen()->GetPrimaryDisplay().work_area(); | 63 Shell::GetScreen()->GetPrimaryDisplay().work_area(); |
53 const gfx::Point center_point = work_area.CenterPoint(); | 64 const gfx::Point center_point = work_area.CenterPoint(); |
54 if (work_area.x() > point.x() || work_area.y() > point.y() || | 65 if (work_area.x() > point.x() || work_area.y() > point.y() || |
55 work_area.right() < point.x() || work_area.bottom() < point.y()) { | 66 work_area.right() < point.x() || work_area.bottom() < point.y()) { |
56 return OUTSIDE; | 67 return OUTSIDE; |
57 } | 68 } |
58 | 69 |
59 if (center_point.x() < point.x()) | 70 if (center_point.x() < point.x()) |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 int baseline = alignment_delegate()->GetBaseLine(); | 222 int baseline = alignment_delegate()->GetBaseLine(); |
212 | 223 |
213 const int kTrayHeight = 100; | 224 const int kTrayHeight = 100; |
214 alignment_delegate()->SetSystemTrayHeight(kTrayHeight); | 225 alignment_delegate()->SetSystemTrayHeight(kTrayHeight); |
215 | 226 |
216 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 227 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
217 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, | 228 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, |
218 alignment_delegate()->GetBaseLine()); | 229 alignment_delegate()->GetBaseLine()); |
219 } | 230 } |
220 | 231 |
| 232 TEST_F(AshPopupAlignmentDelegateTest, Unified) { |
| 233 if (!SupportsMultipleDisplays()) |
| 234 return; |
| 235 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 236 test::DisplayManagerTestApi test_api(display_manager); |
| 237 test_api.SetDefaultMultiDisplayMode(DisplayManager::UNIFIED); |
| 238 display_manager->SetMultiDisplayMode(DisplayManager::UNIFIED); |
| 239 |
| 240 // Reset the delegate as the primary display's shelf will be destroyed during |
| 241 // transition. |
| 242 SetAlignmentDelegate(scoped_ptr<AshPopupAlignmentDelegate>()); |
| 243 |
| 244 UpdateDisplay("600x600,800x800"); |
| 245 SetAlignmentDelegate(make_scoped_ptr(new AshPopupAlignmentDelegate())); |
| 246 |
| 247 EXPECT_GT(600, |
| 248 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); |
| 249 } |
| 250 |
221 } // namespace ash | 251 } // namespace ash |
OLD | NEW |