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

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

Issue 2144003003: Add CreateTestWidget() to AshTestBase, collapse duplicates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@movetray
Patch Set: rebase Created 4 years, 5 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/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/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"
16 #include "ash/common/wm_window.h" 15 #include "ash/common/wm_window.h"
17 #include "ash/display/display_manager.h" 16 #include "ash/display/display_manager.h"
18 #include "ash/shell.h" 17 #include "ash/shell.h"
19 #include "ash/test/ash_test_base.h" 18 #include "ash/test/ash_test_base.h"
20 #include "base/command_line.h" 19 #include "base/command_line.h"
21 #include "base/memory/ptr_util.h" 20 #include "base/memory/ptr_util.h"
22 #include "ui/display/screen.h" 21 #include "ui/display/screen.h"
23 #include "ui/gfx/geometry/rect.h" 22 #include "ui/gfx/geometry/rect.h"
24 #include "ui/keyboard/keyboard_switches.h" 23 #include "ui/keyboard/keyboard_switches.h"
25 #include "ui/keyboard/keyboard_util.h" 24 #include "ui/keyboard/keyboard_util.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 80 }
82 81
83 if (center_point.x() < point.x()) 82 if (center_point.x() < point.x())
84 return (center_point.y() < point.y()) ? BOTTOM_RIGHT : TOP_RIGHT; 83 return (center_point.y() < point.y()) ? BOTTOM_RIGHT : TOP_RIGHT;
85 else 84 else
86 return (center_point.y() < point.y()) ? BOTTOM_LEFT : TOP_LEFT; 85 return (center_point.y() < point.y()) ? BOTTOM_LEFT : TOP_LEFT;
87 } 86 }
88 87
89 gfx::Rect GetWorkArea() { return alignment_delegate_->work_area_; } 88 gfx::Rect GetWorkArea() { return alignment_delegate_->work_area_; }
90 89
91 std::unique_ptr<views::Widget> CreateTestWidget(int container_id) {
92 std::unique_ptr<views::Widget> widget(new views::Widget);
93 views::Widget::InitParams params;
94 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
95 params.bounds = gfx::Rect(0, 0, 50, 50);
96 WmShell::Get()
97 ->GetPrimaryRootWindow()
98 ->GetRootWindowController()
99 ->ConfigureWidgetInitParamsForContainer(widget.get(), container_id,
100 &params);
101 widget->Init(params);
102 widget->Show();
103 return widget;
104 }
105
106 private: 90 private:
107 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_; 91 std::unique_ptr<AshPopupAlignmentDelegate> alignment_delegate_;
108 92
109 DISALLOW_COPY_AND_ASSIGN(AshPopupAlignmentDelegateTest); 93 DISALLOW_COPY_AND_ASSIGN(AshPopupAlignmentDelegateTest);
110 }; 94 };
111 95
112 #if defined(OS_WIN) && !defined(USE_ASH) 96 #if defined(OS_WIN) && !defined(USE_ASH)
113 // TODO(msw): Broken on Windows. http://crbug.com/584038 97 // TODO(msw): Broken on Windows. http://crbug.com/584038
114 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment 98 #define MAYBE_ShelfAlignment DISABLED_ShelfAlignment
115 #else 99 #else
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 146 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
163 } 147 }
164 148
165 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) { 149 TEST_F(AshPopupAlignmentDelegateTest, AutoHide) {
166 const gfx::Rect toast_size(0, 0, 10, 10); 150 const gfx::Rect toast_size(0, 0, 10, 10);
167 UpdateDisplay("600x600"); 151 UpdateDisplay("600x600");
168 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); 152 int origin_x = alignment_delegate()->GetToastOriginX(toast_size);
169 int baseline = alignment_delegate()->GetBaseLine(); 153 int baseline = alignment_delegate()->GetBaseLine();
170 154
171 // Create a window, otherwise autohide doesn't work. 155 // Create a window, otherwise autohide doesn't work.
172 std::unique_ptr<views::Widget> widget = 156 std::unique_ptr<views::Widget> widget = CreateTestWidget(
173 CreateTestWidget(kShellWindowId_DefaultContainer); 157 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(0, 0, 50, 50));
174 WmShelf* shelf = GetPrimaryShelf(); 158 WmShelf* shelf = GetPrimaryShelf();
175 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); 159 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS);
176 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 160 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
177 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine()); 161 EXPECT_LT(baseline, alignment_delegate()->GetBaseLine());
178 } 162 }
179 163
180 // Verify that docked window doesn't affect the popup alignment. 164 // Verify that docked window doesn't affect the popup alignment.
181 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) { 165 TEST_F(AshPopupAlignmentDelegateTest, DockedWindow) {
182 const gfx::Rect toast_size(0, 0, 10, 10); 166 const gfx::Rect toast_size(0, 0, 10, 10);
183 UpdateDisplay("600x600"); 167 UpdateDisplay("600x600");
184 int origin_x = alignment_delegate()->GetToastOriginX(toast_size); 168 int origin_x = alignment_delegate()->GetToastOriginX(toast_size);
185 int baseline = alignment_delegate()->GetBaseLine(); 169 int baseline = alignment_delegate()->GetBaseLine();
186 170
187 std::unique_ptr<views::Widget> widget = 171 std::unique_ptr<views::Widget> widget = CreateTestWidget(
188 CreateTestWidget(kShellWindowId_DockedContainer); 172 nullptr, kShellWindowId_DockedContainer, gfx::Rect(0, 0, 50, 50));
189 173
190 // Left-side dock should not affect popup alignment 174 // Left-side dock should not affect popup alignment
191 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size)); 175 EXPECT_EQ(origin_x, alignment_delegate()->GetToastOriginX(toast_size));
192 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); 176 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine());
193 EXPECT_FALSE(alignment_delegate()->IsTopDown()); 177 EXPECT_FALSE(alignment_delegate()->IsTopDown());
194 EXPECT_FALSE(alignment_delegate()->IsFromLeft()); 178 EXPECT_FALSE(alignment_delegate()->IsFromLeft());
195 179
196 // Force dock to right-side 180 // Force dock to right-side
197 WmShelf* shelf = GetPrimaryShelf(); 181 WmShelf* shelf = GetPrimaryShelf();
198 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); 182 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 shelf->SetKeyboardBoundsForTesting(keyboard_bounds); 307 shelf->SetKeyboardBoundsForTesting(keyboard_bounds);
324 int keyboard_baseline = alignment_delegate()->GetBaseLine(); 308 int keyboard_baseline = alignment_delegate()->GetBaseLine();
325 EXPECT_NE(baseline, keyboard_baseline); 309 EXPECT_NE(baseline, keyboard_baseline);
326 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline); 310 EXPECT_GT(keyboard_bounds.y(), keyboard_baseline);
327 311
328 shelf->SetKeyboardBoundsForTesting(gfx::Rect()); 312 shelf->SetKeyboardBoundsForTesting(gfx::Rect());
329 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine()); 313 EXPECT_EQ(baseline, alignment_delegate()->GetBaseLine());
330 } 314 }
331 315
332 } // namespace ash 316 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/default_header_painter_unittest.cc ('k') | ash/system/web_notification/web_notification_tray_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698