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

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

Issue 2029323002: mash: Convert AshPopupAlignmentDelegate to wm common types (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/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 {
32 namespace {
33
34 // Returns the shelf for the primary display.
35 WmShelf* GetPrimaryShelf() {
msw 2016/06/16 18:56:48 nit: Add to AshTestBase? We'll likely need this (o
James Cook 2016/06/16 21:08:14 Moved to AshTestBase.
36 return WmShell::Get()
37 ->GetPrimaryRootWindow()
38 ->GetRootWindowController()
39 ->GetShelf();
40 }
41
42 } // namespace
30 43
31 class AshPopupAlignmentDelegateTest : public test::AshTestBase { 44 class AshPopupAlignmentDelegateTest : public test::AshTestBase {
32 public: 45 public:
33 AshPopupAlignmentDelegateTest() {} 46 AshPopupAlignmentDelegateTest() {}
34 ~AshPopupAlignmentDelegateTest() override {} 47 ~AshPopupAlignmentDelegateTest() override {}
35 48
36 void SetUp() override { 49 void SetUp() override {
37 base::CommandLine::ForCurrentProcess()->AppendSwitch( 50 base::CommandLine::ForCurrentProcess()->AppendSwitch(
38 keyboard::switches::kEnableVirtualKeyboard); 51 keyboard::switches::kEnableVirtualKeyboard);
39 test::AshTestBase::SetUp(); 52 test::AshTestBase::SetUp();
40 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( 53 SetAlignmentDelegate(
41 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); 54 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf())));
42 } 55 }
43 56
44 void TearDown() override { 57 void TearDown() override {
45 alignment_delegate_.reset(); 58 alignment_delegate_.reset();
46 test::AshTestBase::TearDown(); 59 test::AshTestBase::TearDown();
47 } 60 }
48 61
49 void SetKeyboardBounds(const gfx::Rect& new_bounds) { 62 void SetKeyboardBounds(const gfx::Rect& new_bounds) {
50 Shelf::ForPrimaryDisplay() 63 Shelf::ForPrimaryDisplay()
51 ->shelf_layout_manager() 64 ->shelf_layout_manager()
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 ->GetRootWindowController() 125 ->GetRootWindowController()
113 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id, 126 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id,
114 &params); 127 &params);
115 widget->Init(params); 128 widget->Init(params);
116 widget->Show(); 129 widget->Show();
117 return widget; 130 return widget;
118 } 131 }
119 132
120 private: 133 private:
121 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; 134 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_;
135
136 DISALLOW_COPY_AND_ASSIGN(AshPopupAlignmentDelegateTest);
122 }; 137 };
123 138
124 #if defined(OS_WIN) && !defined(USE_ASH) 139 #if defined(OS_WIN) && !defined(USE_ASH)
125 // TODO(msw): Broken on Windows. http://crbug.com/584038 140 // TODO(msw): Broken on Windows. http://crbug.com/584038
126 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment 141 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment
127 #else 142 #else
128 #define MAYBE_ShelfAlignment ShelfAlignment 143 #define MAYBE_ShelfAlignment ShelfAlignment
129 #endif 144 #endif
130 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) { 145 TEST_F(AshPopupAlignmentDelegateTest, MAYBE_ShelfAlignment) {
131 const gfx::Rect toast_size(0, 0, 10, 10); 146 const gfx::Rect toast_size(0, 0, 10, 10);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 287
273 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 288 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
274 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems, 289 EXPECT_EQ(baseline - kTrayHeight - message_center::kMarginBetweenItems,
275 alignment_delegate()->GetBaseLine()); 290 alignment_delegate()->GetBaseLine());
276 } 291 }
277 292
278 TEST_F(AshPopupAlignmentDelegateTest, Extended) { 293 TEST_F(AshPopupAlignmentDelegateTest, Extended) {
279 if (!SupportsMultipleDisplays()) 294 if (!SupportsMultipleDisplays())
280 return; 295 return;
281 UpdateDisplay("600x600,800x800"); 296 UpdateDisplay("600x600,800x800");
282 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( 297 SetAlignmentDelegate(
283 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); 298 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf())));
284 299
285 display::Display second_display = ScreenUtil::GetSecondaryDisplay(); 300 display::Display second_display = ScreenUtil::GetSecondaryDisplay();
286 AshPopupAlignmentDelegate for_2nd_display( 301 WmShelf* second_shelf =
287 Shelf::ForDisplayId(second_display.id())->shelf_layout_manager()); 302 WmLookup::Get()
303 ->GetRootWindowControllerWithDisplayId(second_display.id())
304 ->GetShelf();
305 AshPopupAlignmentDelegate for_2nd_display(second_shelf);
288 UpdateWorkArea(&for_2nd_display, second_display); 306 UpdateWorkArea(&for_2nd_display, second_display);
289 // Make sure that the toast position on the secondary display is 307 // Make sure that the toast position on the secondary display is
290 // positioned correctly. 308 // positioned correctly.
291 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10))); 309 EXPECT_LT(1300, for_2nd_display.GetToastOriginX(gfx::Rect(0, 0, 10, 10)));
292 EXPECT_LT(700, for_2nd_display.GetBaseLine()); 310 EXPECT_LT(700, for_2nd_display.GetBaseLine());
293 } 311 }
294 312
295 TEST_F(AshPopupAlignmentDelegateTest, Unified) { 313 TEST_F(AshPopupAlignmentDelegateTest, Unified) {
296 if (!SupportsMultipleDisplays()) 314 if (!SupportsMultipleDisplays())
297 return; 315 return;
298 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 316 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
299 display_manager->SetUnifiedDesktopEnabled(true); 317 display_manager->SetUnifiedDesktopEnabled(true);
300 318
301 // Reset the delegate as the primary display's shelf will be destroyed during 319 // Reset the delegate as the primary display's shelf will be destroyed during
302 // transition. 320 // transition.
303 SetAlignmentDelegate(nullptr); 321 SetAlignmentDelegate(nullptr);
304 322
305 UpdateDisplay("600x600,800x800"); 323 UpdateDisplay("600x600,800x800");
306 SetAlignmentDelegate(base::WrapUnique(new AshPopupAlignmentDelegate( 324 SetAlignmentDelegate(
307 Shelf::ForPrimaryDisplay()->shelf_layout_manager()))); 325 base::WrapUnique(new AshPopupAlignmentDelegate(GetPrimaryShelf())));
308 326
309 EXPECT_GT(600, 327 EXPECT_GT(600,
310 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10))); 328 alignment_delegate()->GetToastOriginX(gfx::Rect(0, 0, 10, 10)));
311 } 329 }
312 330
313 // Tests that when the keyboard is showing that notifications appear above it, 331 // Tests that when the keyboard is showing that notifications appear above it,
314 // and that they return to normal once the keyboard is gone. 332 // and that they return to normal once the keyboard is gone.
315 #if defined(OS_WIN) && !defined(USE_ASH) 333 #if defined(OS_WIN) && !defined(USE_ASH)
316 // TODO(msw): Broken on Windows. http://crbug.com/584038 334 // TODO(msw): Broken on Windows. http://crbug.com/584038
317 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing 335 #define MAYBE_KeyboardShowing DISABLED_KeyboardShowing
(...skipping 11 matching lines...) Expand all
329 SetKeyboardBounds(keyboard_bounds); 347 SetKeyboardBounds(keyboard_bounds);
330 int keyboard_baseline = alignment_delegate()->GetBaseLine(); 348 int keyboard_baseline = alignment_delegate()->GetBaseLine();
331 EXPECT_NE(baseline, keyboard_baseline); 349 EXPECT_NE(baseline, keyboard_baseline);
332 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); 350 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline);
333 351
334 SetKeyboardBounds(gfx::Rect()); 352 SetKeyboardBounds(gfx::Rect());
335 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); 353 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine());
336 } 354 }
337 355
338 } // namespace ash 356 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698