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/shelf/wm_shelf.h" |
12 #include "ash/common/shell_window_ids.h" | 12 #include "ash/common/shell_window_ids.h" |
13 #include "ash/common/wm_lookup.h" | 13 #include "ash/common/wm_lookup.h" |
14 #include "ash/common/wm_root_window_controller.h" | 14 #include "ash/common/wm_root_window_controller.h" |
15 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
16 #include "ash/common/wm_window.h" | 16 #include "ash/common/wm_window.h" |
17 #include "ash/display/display_manager.h" | 17 #include "ash/display/display_manager.h" |
18 #include "ash/screen_util.h" | 18 #include "ash/screen_util.h" |
19 #include "ash/shelf/shelf.h" | |
20 #include "ash/shelf/shelf_layout_manager.h" | |
21 #include "ash/shell.h" | 19 #include "ash/shell.h" |
22 #include "ash/test/ash_test_base.h" | 20 #include "ash/test/ash_test_base.h" |
23 #include "base/command_line.h" | 21 #include "base/command_line.h" |
24 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
25 #include "ui/display/screen.h" | 23 #include "ui/display/screen.h" |
26 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
27 #include "ui/keyboard/keyboard_switches.h" | 25 #include "ui/keyboard/keyboard_switches.h" |
28 #include "ui/keyboard/keyboard_util.h" | 26 #include "ui/keyboard/keyboard_util.h" |
29 #include "ui/message_center/message_center_style.h" | 27 #include "ui/message_center/message_center_style.h" |
30 | 28 |
(...skipping 10 matching lines...) Expand all Loading... |
41 test::AshTestBase::SetUp(); | 39 test::AshTestBase::SetUp(); |
42 SetAlignmentDelegate( | 40 SetAlignmentDelegate( |
43 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); | 41 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); |
44 } | 42 } |
45 | 43 |
46 void TearDown() override { | 44 void TearDown() override { |
47 alignment_delegate_.reset(); | 45 alignment_delegate_.reset(); |
48 test::AshTestBase::TearDown(); | 46 test::AshTestBase::TearDown(); |
49 } | 47 } |
50 | 48 |
51 void SetKeyboardBounds(const gfx::Rect& new_bounds) { | |
52 Shelf::ForPrimaryDisplay() | |
53 ->shelf_layout_manager() | |
54 ->OnKeyboardBoundsChanging(new_bounds); | |
55 } | |
56 | |
57 protected: | 49 protected: |
58 enum Position { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, OUTSIDE }; | 50 enum Position { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT, OUTSIDE }; |
59 | 51 |
60 AshPopupAlignmentDelegate* alignment_delegate() { | 52 AshPopupAlignmentDelegate* alignment_delegate() { |
61 return alignment_delegate_.get(); | 53 return alignment_delegate_.get(); |
62 } | 54 } |
63 | 55 |
64 void UpdateWorkArea(AshPopupAlignmentDelegate* alignment_delegate, | 56 void UpdateWorkArea(AshPopupAlignmentDelegate* alignment_delegate, |
65 const display::Display& display) { | 57 const display::Display& display) { |
66 alignment_delegate->StartObserving(display::Screen::GetScreen(), display); | 58 alignment_delegate->StartObserving(display::Screen::GetScreen(), display); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 | 164 |
173 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { | 165 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { |
174 const gfx::Rect toast_size(0, 0, 10, 10); | 166 const gfx::Rect toast_size(0, 0, 10, 10); |
175 UpdateDisplay("600x600"); | 167 UpdateDisplay("600x600"); |
176 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 168 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
177 int baseline = alignment_delegate()->GetBaseLine(); | 169 int baseline = alignment_delegate()->GetBaseLine(); |
178 | 170 |
179 // Create a window, otherwise autohide doesn't work. | 171 // Create a window, otherwise autohide doesn't work. |
180 std::unique_ptr<views::Widget> widget = | 172 std::unique_ptr<views::Widget> widget = |
181 CreateTestWidget(kShellWindowId_DefaultContainer); | 173 CreateTestWidget(kShellWindowId_DefaultContainer); |
182 Shelf* shelf = Shelf::ForPrimaryDisplay(); | 174 WmShelf* shelf = GetPrimaryShelf(); |
183 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 175 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
184 shelf->shelf_layout_manager()->UpdateAutoHideStateNow(); | |
185 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 176 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
186 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); | 177 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); |
187 } | 178 } |
188 | 179 |
189 // Verify that docked window doesn't affect the popup alignment. | 180 // Verify that docked window doesn't affect the popup alignment. |
190 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { | 181 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { |
191 const gfx::Rect toast_size(0, 0, 10, 10); | 182 const gfx::Rect toast_size(0, 0, 10, 10); |
192 UpdateDisplay("600x600"); | 183 UpdateDisplay("600x600"); |
193 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); | 184 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); |
194 int baseline = alignment_delegate()->GetBaseLine(); | 185 int baseline = alignment_delegate()->GetBaseLine(); |
195 | 186 |
196 std::unique_ptr<views::Widget> widget = | 187 std::unique_ptr<views::Widget> widget = |
197 CreateTestWidget(kShellWindowId_DockedContainer); | 188 CreateTestWidget(kShellWindowId_DockedContainer); |
198 | 189 |
199 // Left-side dock should not affect popup alignment | 190 // Left-side dock should not affect popup alignment |
200 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 191 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
201 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 192 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
202 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 193 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
203 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 194 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
204 | 195 |
205 // Force dock to right-side | 196 // Force dock to right-side |
206 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); | 197 WmShelf* shelf = GetPrimaryShelf(); |
207 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); | 198 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
| 199 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM); |
208 | 200 |
209 // Right-side dock should not affect popup alignment | 201 // Right-side dock should not affect popup alignment |
210 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); | 202 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); |
211 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 203 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
212 EXPECT_FALSE(alignment_delegate()->IsTopDown()); | 204 EXPECT_FALSE(alignment_delegate()->IsTopDown()); |
213 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); | 205 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); |
214 } | 206 } |
215 | 207 |
216 #if defined(OS_WIN) && !defined(USE_ASH) | 208 #if defined(OS_WIN) && !defined(USE_ASH) |
217 // TODO(msw): Broken on Windows. http://crbug.com/584038 | 209 // TODO(msw): Broken on Windows. http://crbug.com/584038 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 #else | 309 #else |
318 #define MAYBE_KeyboardShowing KeyboardShowing | 310 #define MAYBE_KeyboardShowing KeyboardShowing |
319 #endif | 311 #endif |
320 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_KeyboardShowing) { | 312 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_KeyboardShowing) { |
321 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); | 313 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); |
322 ASSERT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); | 314 ASSERT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); |
323 | 315 |
324 UpdateDisplay("600x600"); | 316 UpdateDisplay("600x600"); |
325 int baseline = alignment_delegate()->GetBaseLine(); | 317 int baseline = alignment_delegate()->GetBaseLine(); |
326 | 318 |
| 319 WmShelf* shelf = GetPrimaryShelf(); |
327 gfx::Rect keyboard_bounds(0, 300, 600, 300); | 320 gfx::Rect keyboard_bounds(0, 300, 600, 300); |
328 SetKeyboardBounds(keyboard_bounds); | 321 shelf->SetKeyboardBoundsForTesting(keyboard_bounds); |
329 int keyboard_baseline = alignment_delegate()->GetBaseLine(); | 322 int keyboard_baseline = alignment_delegate()->GetBaseLine(); |
330 EXPECT_NE(baseline, keyboard_baseline); | 323 EXPECT_NE(baseline, keyboard_baseline); |
331 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); | 324 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); |
332 | 325 |
333 SetKeyboardBounds(gfx::Rect()); | 326 shelf->SetKeyboardBoundsForTesting(gfx::Rect()); |
334 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); | 327 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); |
335 } | 328 } |
336 | 329 |
337 } // namespace ash | 330 } // namespace ash |
OLD | NEW |