Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: ash/system/web_notification/ash_popup_alignment_delegate_unittest.cc

Issue 2093283002: mash: Convert all of //ash/system to use WmShelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
31 namespace ash { 29 namespace ash {
32 30
33 class AshPopupAlignmentDelegateTest : public test::AshTestBase { 31 class AshPopupAlignmentDelegateTest : public test::AshTestBase {
34 public: 32 public:
35 AshPopupAlignmentDelegateTest() {} 33 AshPopupAlignmentDelegateTest() {}
36 ~AshPopupAlignmentDelegateTest() override {} 34 ~AshPopupAlignmentDelegateTest() override {}
37 35
38 void SetUp() override { 36 void SetUp() override {
39 base::CommandLine::ForCurrentProcess()->AppendSwitch( 37 base::CommandLine::ForCurrentProcess()->AppendSwitch(
40 keyboard::switches::kEnableVirtualKeyboard); 38 keyboard::switches::kEnableVirtualKeyboard);
41 test::AshTestBase::SetUp(); 39 test::AshTestBase::SetUp();
42 SetAlignmentDelegate( 40 SetAlignmentDelegate(base::WrapUnique(
43 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); 41 new AshPopupAlignmentDelegate(WmShelf::ForPrimaryDisplay())));
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 { 50 enum Position {
59 TOP_LEFT, 51 TOP_LEFT,
60 TOP_RIGHT, 52 TOP_RIGHT,
61 BOTTOM_LEFT, 53 BOTTOM_LEFT,
62 BOTTOM_RIGHT, 54 BOTTOM_RIGHT,
63 OUTSIDE 55 OUTSIDE
64 }; 56 };
65 57
66 AshPopupAlignmentDelegate* alignment_delegate() { 58 AshPopupAlignmentDelegate* alignment_delegate() {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) { 126 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) {
135 const gfx::Rect toast_size(0, 0, 10, 10); 127 const gfx::Rect toast_size(0, 0, 10, 10);
136 UpdateDisplay("600x600"); 128 UpdateDisplay("600x600");
137 gfx::Point toast_point; 129 gfx::Point toast_point;
138 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); 130 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size));
139 toast_point.set_y(alignment_delegate()->GetBaseLine()); 131 toast_point.set_y(alignment_delegate()->GetBaseLine());
140 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); 132 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point));
141 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 133 EXPECT_FALSE(alignment_delegate()->IsTopDown());
142 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 134 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
143 135
144 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_RIGHT); 136 WmShelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_RIGHT);
145 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); 137 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size));
146 toast_point.set_y(alignment_delegate()->GetBaseLine()); 138 toast_point.set_y(alignment_delegate()->GetBaseLine());
147 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); 139 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point));
148 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 140 EXPECT_FALSE(alignment_delegate()->IsTopDown());
149 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 141 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
150 142
151 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); 143 WmShelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT);
152 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); 144 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size));
153 toast_point.set_y(alignment_delegate()->GetBaseLine()); 145 toast_point.set_y(alignment_delegate()->GetBaseLine());
154 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point)); 146 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point));
155 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 147 EXPECT_FALSE(alignment_delegate()->IsTopDown());
156 EXPECT_TRUE(alignment_delegate()->IsFromLeft()); 148 EXPECT_TRUE(alignment_delegate()->IsFromLeft());
157 } 149 }
158 150
159 TEST_F(AshPopupAlignmentDelegateTest, LockScreen) { 151 TEST_F(AshPopupAlignmentDelegateTest, LockScreen) {
160 if (!SupportsHostWindowResize()) 152 if (!SupportsHostWindowResize())
161 return; 153 return;
162 154
163 const gfx::Rect toast_size(0, 0, 10, 10); 155 const gfx::Rect toast_size(0, 0, 10, 10);
164 156
165 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); 157 WmShelf::ForPrimaryDisplay()->SetAlignment(SHELF_ALIGNMENT_LEFT);
166 gfx::Point toast_point; 158 gfx::Point toast_point;
167 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); 159 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size));
168 toast_point.set_y(alignment_delegate()->GetBaseLine()); 160 toast_point.set_y(alignment_delegate()->GetBaseLine());
169 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point)); 161 EXPECT_EQ(BOTTOM_LEFT, GetPositionInDisplay(toast_point));
170 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 162 EXPECT_FALSE(alignment_delegate()->IsTopDown());
171 EXPECT_TRUE(alignment_delegate()->IsFromLeft()); 163 EXPECT_TRUE(alignment_delegate()->IsFromLeft());
172 164
173 BlockUserSession(BLOCKED_BY_LOCK_SCREEN); 165 BlockUserSession(BLOCKED_BY_LOCK_SCREEN);
174 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size)); 166 toast_point.set_x(alignment_delegate()->GetToastOriginX(toast_size));
175 toast_point.set_y(alignment_delegate()->GetBaseLine()); 167 toast_point.set_y(alignment_delegate()->GetBaseLine());
176 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point)); 168 EXPECT_EQ(BOTTOM_RIGHT, GetPositionInDisplay(toast_point));
177 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 169 EXPECT_FALSE(alignment_delegate()->IsTopDown());
178 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 170 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
179 } 171 }
180 172
181 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { 173 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) {
182 const gfx::Rect toast_size(0, 0, 10, 10); 174 const gfx::Rect toast_size(0, 0, 10, 10);
183 UpdateDisplay("600x600"); 175 UpdateDisplay("600x600");
184 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); 176 int origin_x = alignment_delegate()->GetToastOriginX(toast_size);
185 int baseline = alignment_delegate()->GetBaseLine(); 177 int baseline = alignment_delegate()->GetBaseLine();
186 178
187 // Create a window, otherwise autohide doesn't work. 179 // Create a window, otherwise autohide doesn't work.
188 std::unique_ptr<views::Widget> widget = 180 std::unique_ptr<views::Widget> widget =
189 CreateTestWidget(kShellWindowId_DefaultContainer); 181 CreateTestWidget(kShellWindowId_DefaultContainer);
190 Shelf* shelf = Shelf::ForPrimaryDisplay(); 182 WmShelf* shelf = WmShelf::ForPrimaryDisplay();
191 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 183 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
192 shelf->shelf_layout_manager()->UpdateAutoHideStateNow(); 184 shelf->UpdateVisibilityState();
msw 2016/06/25 00:18:30 q: should this be UpdateAutoHideState?
James Cook 2016/06/25 01:20:58 Actually, it's not needed at all. Removed.
193 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 185 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
194 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); 186 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine());
195 } 187 }
196 188
197 // Verify that docked window doesn't affect the popup alignment. 189 // Verify that docked window doesn't affect the popup alignment.
198 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { 190 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) {
199 const gfx::Rect toast_size(0, 0, 10, 10); 191 const gfx::Rect toast_size(0, 0, 10, 10);
200 UpdateDisplay("600x600"); 192 UpdateDisplay("600x600");
201 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); 193 int origin_x = alignment_delegate()->GetToastOriginX(toast_size);
202 int baseline = alignment_delegate()->GetBaseLine(); 194 int baseline = alignment_delegate()->GetBaseLine();
203 195
204 std::unique_ptr<views::Widget> widget = 196 std::unique_ptr<views::Widget> widget =
205 CreateTestWidget(kShellWindowId_DockedContainer); 197 CreateTestWidget(kShellWindowId_DockedContainer);
206 198
207 // Left-side dock should not affect popup alignment 199 // Left-side dock should not affect popup alignment
208 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 200 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
209 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); 201 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine());
210 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 202 EXPECT_FALSE(alignment_delegate()->IsTopDown());
211 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 203 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
212 204
213 // Force dock to right-side 205 // Force dock to right-side
214 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_LEFT); 206 WmShelf* shelf = WmShelf::ForPrimaryDisplay();
215 GetPrimaryShelf()->SetAlignment(SHELF_ALIGNMENT_BOTTOM); 207 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
208 shelf->SetAlignment(SHELF_ALIGNMENT_BOTTOM);
216 209
217 // Right-side dock should not affect popup alignment 210 // Right-side dock should not affect popup alignment
218 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 211 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
219 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); 212 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine());
220 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 213 EXPECT_FALSE(alignment_delegate()->IsTopDown());
221 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 214 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
222 } 215 }
223 216
224 #if defined(OS_WIN) && !defined(USE_ASH) 217 #if defined(OS_WIN) && !defined(USE_ASH)
225 // TODO(msw): Broken on Windows. http://crbug.com/584038 218 // TODO(msw): Broken on Windows. http://crbug.com/584038
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 269
277 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 270 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
278 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, 271 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems,
279 alignment_delegate()->GetBaseLine()); 272 alignment_delegate()->GetBaseLine());
280 } 273 }
281 274
282 TEST_F(AshPopupAlignmentDelegateTest, Extended) { 275 TEST_F(AshPopupAlignmentDelegateTest, Extended) {
283 if (!SupportsMultipleDisplays()) 276 if (!SupportsMultipleDisplays())
284 return; 277 return;
285 UpdateDisplay("600x600,800x800"); 278 UpdateDisplay("600x600,800x800");
286 SetAlignmentDelegate( 279 SetAlignmentDelegate(base::WrapUnique(
287 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); 280 new AshPopupAlignmentDelegate(WmShelf::ForPrimaryDisplay())));
288 281
289 display::Display second_display = ScreenUtil::GetSecondaryDisplay(); 282 display::Display second_display = ScreenUtil::GetSecondaryDisplay();
290 WmShelf* second_shelf = 283 WmShelf* second_shelf =
291 WmLookup::Get() 284 WmLookup::Get()
292 ->GetRootWindowControllerWithDisplayId(second_display.id()) 285 ->GetRootWindowControllerWithDisplayId(second_display.id())
293 ->GetShelf(); 286 ->GetShelf();
294 AshPopupAlignmentDelegate for_2nd_display(second_shelf); 287 AshPopupAlignmentDelegate for_2nd_display(second_shelf);
295 UpdateWorkArea(&for_2nd_display, second_display); 288 UpdateWorkArea(&for_2nd_display, second_display);
296 // Make sure that the toast position on the secondary display is 289 // Make sure that the toast position on the secondary display is
297 // positioned correctly. 290 // positioned correctly.
298 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); 291 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10)));
299 EXPECT_LT(700, for_2nd_display.GetBaseLine()); 292 EXPECT_LT(700, for_2nd_display.GetBaseLine());
300 } 293 }
301 294
302 TEST_F(AshPopupAlignmentDelegateTest, Unified) { 295 TEST_F(AshPopupAlignmentDelegateTest, Unified) {
303 if (!SupportsMultipleDisplays()) 296 if (!SupportsMultipleDisplays())
304 return; 297 return;
305 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 298 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
306 display_manager->SetUnifiedDesktopEnabled(true); 299 display_manager->SetUnifiedDesktopEnabled(true);
307 300
308 // Reset the delegate as the primary display's shelf will be destroyed during 301 // Reset the delegate as the primary display's shelf will be destroyed during
309 // transition. 302 // transition.
310 SetAlignmentDelegate(nullptr); 303 SetAlignmentDelegate(nullptr);
311 304
312 UpdateDisplay("600x600,800x800"); 305 UpdateDisplay("600x600,800x800");
313 SetAlignmentDelegate( 306 SetAlignmentDelegate(base::WrapUnique(
314 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf()))); 307 new AshPopupAlignmentDelegate(WmShelf::ForPrimaryDisplay())));
315 308
316 EXPECT_GT(600, 309 EXPECT_GT(600,
317 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); 310 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10)));
318 } 311 }
319 312
320 // Tests that when the keyboard is showing that notifications appear above it, 313 // Tests that when the keyboard is showing that notifications appear above it,
321 // and that they return to normal once the keyboard is gone. 314 // and that they return to normal once the keyboard is gone.
322 #if defined(OS_WIN) && !defined(USE_ASH) 315 #if defined(OS_WIN) && !defined(USE_ASH)
323 // TODO(msw): Broken on Windows. http://crbug.com/584038 316 // TODO(msw): Broken on Windows. http://crbug.com/584038
324 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing 317 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing
325 #else 318 #else
326 #define MAYBE_KeyboardShowing KeyboardShowing 319 #define MAYBE_KeyboardShowing KeyboardShowing
327 #endif 320 #endif
328 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_KeyboardShowing) { 321 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_KeyboardShowing) {
329 ASSERT_TRUE(keyboard::IsKeyboardEnabled()); 322 ASSERT_TRUE(keyboard::IsKeyboardEnabled());
330 ASSERT_TRUE(keyboard::IsKeyboardOverscrollEnabled()); 323 ASSERT_TRUE(keyboard::IsKeyboardOverscrollEnabled());
331 324
332 UpdateDisplay("600x600"); 325 UpdateDisplay("600x600");
333 int baseline = alignment_delegate()->GetBaseLine(); 326 int baseline = alignment_delegate()->GetBaseLine();
334 327
328 WmShelf* shelf = WmShelf::ForPrimaryDisplay();
335 gfx::Rect keyboard_bounds(0, 300, 600, 300); 329 gfx::Rect keyboard_bounds(0, 300, 600, 300);
336 SetKeyboardBounds(keyboard_bounds); 330 shelf->SetKeyboardBoundsForTesting(keyboard_bounds);
337 int keyboard_baseline = alignment_delegate()->GetBaseLine(); 331 int keyboard_baseline = alignment_delegate()->GetBaseLine();
338 EXPECT_NE(baseline, keyboard_baseline); 332 EXPECT_NE(baseline, keyboard_baseline);
339 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); 333 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline);
340 334
341 SetKeyboardBounds(gfx::Rect()); 335 shelf->SetKeyboardBoundsForTesting(gfx::Rect());
342 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); 336 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine());
343 } 337 }
344 338
345 } // namespace ash 339 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698