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

Side by Side Diff: ash/shelf/shelf_widget_unittest.cc

Issue 2237903003: mash: Migrate Shelf aura::Window uses to WmWindow. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move shelf notify functions to WmShell. Created 4 years, 4 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
« no previous file with comments | « ash/shelf/shelf_view_unittest.cc ('k') | ash/shell.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/shelf_delegate.h" 8 #include "ash/common/shelf/shelf_delegate.h"
9 #include "ash/common/shelf/shelf_view.h" 9 #include "ash/common/shelf/shelf_view.h"
10 #include "ash/common/system/status_area_widget.h" 10 #include "ash/common/system/status_area_widget.h"
11 #include "ash/common/wm_shell.h"
12 #include "ash/common/wm_window.h"
11 #include "ash/root_window_controller.h" 13 #include "ash/root_window_controller.h"
12 #include "ash/shelf/shelf.h" 14 #include "ash/shelf/shelf.h"
13 #include "ash/shelf/shelf_layout_manager.h" 15 #include "ash/shelf/shelf_layout_manager.h"
14 #include "ash/shell.h" 16 #include "ash/shell.h"
15 #include "ash/test/ash_md_test_base.h" 17 #include "ash/test/ash_md_test_base.h"
16 #include "ash/test/ash_test_helper.h" 18 #include "ash/test/ash_test_helper.h"
17 #include "ash/test/shelf_test_api.h" 19 #include "ash/test/shelf_test_api.h"
18 #include "ash/test/shelf_view_test_api.h" 20 #include "ash/test/shelf_view_test_api.h"
19 #include "ash/test/test_shell_delegate.h" 21 #include "ash/test/test_shell_delegate.h"
20 #include "ash/wm/window_util.h" 22 #include "ash/wm/window_util.h"
21 #include "ui/aura/window_event_dispatcher.h" 23 #include "ui/aura/window_event_dispatcher.h"
22 #include "ui/display/display.h" 24 #include "ui/display/display.h"
23 #include "ui/display/screen.h"
24 #include "ui/events/event_utils.h" 25 #include "ui/events/event_utils.h"
25 #include "ui/views/view.h" 26 #include "ui/views/view.h"
26 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
27 28
28 namespace ash { 29 namespace ash {
29 30
30 namespace { 31 namespace {
31 32
32 ShelfWidget* GetShelfWidget() { 33 ShelfWidget* GetShelfWidget() {
33 return Shelf::ForPrimaryDisplay()->shelf_widget(); 34 return Shelf::ForPrimaryDisplay()->shelf_widget();
34 } 35 }
35 36
36 ShelfLayoutManager* GetShelfLayoutManager() { 37 ShelfLayoutManager* GetShelfLayoutManager() {
37 return GetShelfWidget()->shelf_layout_manager(); 38 return GetShelfWidget()->shelf_layout_manager();
38 } 39 }
39 40
40 } // namespace 41 } // namespace
41 42
42 using ShelfWidgetTest = test::AshMDTestBase; 43 using ShelfWidgetTest = test::AshMDTestBase;
43 44
44 INSTANTIATE_TEST_CASE_P( 45 INSTANTIATE_TEST_CASE_P(
45 /* prefix intentionally left blank due to only one parameterization */, 46 /* prefix intentionally left blank due to only one parameterization */,
46 ShelfWidgetTest, 47 ShelfWidgetTest,
47 testing::Values(MaterialDesignController::NON_MATERIAL, 48 testing::Values(MaterialDesignController::NON_MATERIAL,
48 MaterialDesignController::MATERIAL_NORMAL, 49 MaterialDesignController::MATERIAL_NORMAL,
49 MaterialDesignController::MATERIAL_EXPERIMENTAL)); 50 MaterialDesignController::MATERIAL_EXPERIMENTAL));
50 51
51 void TestLauncherAlignment(aura::Window* root, 52 void TestLauncherAlignment(WmWindow* root,
52 ShelfAlignment alignment, 53 ShelfAlignment alignment,
53 const std::string& expected) { 54 const gfx::Rect& expected) {
54 Shelf::ForWindow(root)->SetAlignment(alignment); 55 Shelf::ForWindow(root)->SetAlignment(alignment);
55 display::Screen* screen = display::Screen::GetScreen(); 56 EXPECT_EQ(expected.ToString(),
56 EXPECT_EQ(expected, 57 root->GetDisplayNearestWindow().work_area().ToString());
57 screen->GetDisplayNearestWindow(root).work_area().ToString());
58 } 58 }
59 59
60 // TODO(msw): Broken on Windows. http://crbug.com/584038
61 #if defined(OS_CHROMEOS)
62 TEST_P(ShelfWidgetTest, TestAlignment) { 60 TEST_P(ShelfWidgetTest, TestAlignment) {
61 if (!SupportsHostWindowResize())
62 return;
63
63 // Note that for a left- and right-aligned shelf, this offset must be 64 // Note that for a left- and right-aligned shelf, this offset must be
64 // applied to a maximized window's width rather than its height. 65 // applied to a maximized window's width rather than its height.
65 const int offset = GetMdMaximizedWindowHeightOffset(); 66 const int offset = GetMdMaximizedWindowHeightOffset();
66 const int kShelfSize = GetShelfConstant(SHELF_SIZE); 67 const int kShelfSize = GetShelfConstant(SHELF_SIZE);
67 UpdateDisplay("400x400"); 68 UpdateDisplay("400x400");
68 { 69 {
69 SCOPED_TRACE("Single Bottom"); 70 SCOPED_TRACE("Single Bottom");
70 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_BOTTOM, 71 TestLauncherAlignment(WmShell::Get()->GetPrimaryRootWindow(),
71 gfx::Rect(0, 0, 400, 353 + offset).ToString()); 72 SHELF_ALIGNMENT_BOTTOM,
73 gfx::Rect(0, 0, 400, 353 + offset));
72 } 74 }
73 { 75 {
74 SCOPED_TRACE("Single Locked"); 76 SCOPED_TRACE("Single Locked");
75 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), 77 TestLauncherAlignment(WmShell::Get()->GetPrimaryRootWindow(),
76 SHELF_ALIGNMENT_BOTTOM_LOCKED, 78 SHELF_ALIGNMENT_BOTTOM_LOCKED,
77 gfx::Rect(0, 0, 400, 353 + offset).ToString()); 79 gfx::Rect(0, 0, 400, 353 + offset));
78 } 80 }
79 { 81 {
80 SCOPED_TRACE("Single Right"); 82 SCOPED_TRACE("Single Right");
81 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_RIGHT, 83 TestLauncherAlignment(WmShell::Get()->GetPrimaryRootWindow(),
82 gfx::Rect(0, 0, 353 + offset, 400).ToString()); 84 SHELF_ALIGNMENT_RIGHT,
85 gfx::Rect(0, 0, 353 + offset, 400));
83 } 86 }
84 { 87 {
85 SCOPED_TRACE("Single Left"); 88 SCOPED_TRACE("Single Left");
86 TestLauncherAlignment( 89 TestLauncherAlignment(WmShell::Get()->GetPrimaryRootWindow(),
87 Shell::GetPrimaryRootWindow(), SHELF_ALIGNMENT_LEFT, 90 SHELF_ALIGNMENT_LEFT,
88 gfx::Rect(kShelfSize, 0, 353 + offset, 400).ToString()); 91 gfx::Rect(kShelfSize, 0, 353 + offset, 400));
89 } 92 }
93 }
94
95 TEST_P(ShelfWidgetTest, TestAlignmentForMultipleDisplays) {
90 if (!SupportsMultipleDisplays()) 96 if (!SupportsMultipleDisplays())
91 return; 97 return;
92 98
99 // Note that for a left- and right-aligned shelf, this offset must be
100 // applied to a maximized window's width rather than its height.
101 const int offset = GetMdMaximizedWindowHeightOffset();
102 const int kShelfSize = GetShelfConstant(SHELF_SIZE);
93 UpdateDisplay("300x300,500x500"); 103 UpdateDisplay("300x300,500x500");
94 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 104 std::vector<WmWindow*> root_windows = WmShell::Get()->GetAllRootWindows();
95 { 105 {
96 SCOPED_TRACE("Primary Bottom"); 106 SCOPED_TRACE("Primary Bottom");
97 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_BOTTOM, 107 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_BOTTOM,
98 gfx::Rect(0, 0, 300, 253 + offset).ToString()); 108 gfx::Rect(0, 0, 300, 253 + offset));
99 } 109 }
100 { 110 {
101 SCOPED_TRACE("Primary Locked"); 111 SCOPED_TRACE("Primary Locked");
102 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_BOTTOM_LOCKED, 112 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_BOTTOM_LOCKED,
103 gfx::Rect(0, 0, 300, 253 + offset).ToString()); 113 gfx::Rect(0, 0, 300, 253 + offset));
104 } 114 }
105 { 115 {
106 SCOPED_TRACE("Primary Right"); 116 SCOPED_TRACE("Primary Right");
107 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_RIGHT, 117 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_RIGHT,
108 gfx::Rect(0, 0, 253 + offset, 300).ToString()); 118 gfx::Rect(0, 0, 253 + offset, 300));
109 } 119 }
110 { 120 {
111 SCOPED_TRACE("Primary Left"); 121 SCOPED_TRACE("Primary Left");
112 TestLauncherAlignment( 122 TestLauncherAlignment(root_windows[0], SHELF_ALIGNMENT_LEFT,
113 root_windows[0], SHELF_ALIGNMENT_LEFT, 123 gfx::Rect(kShelfSize, 0, 253 + offset, 300));
114 gfx::Rect(kShelfSize, 0, 253 + offset, 300).ToString());
115 } 124 }
116 { 125 {
117 SCOPED_TRACE("Secondary Bottom"); 126 SCOPED_TRACE("Secondary Bottom");
118 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_BOTTOM, 127 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_BOTTOM,
119 gfx::Rect(300, 0, 500, 453 + offset).ToString()); 128 gfx::Rect(300, 0, 500, 453 + offset));
120 } 129 }
121 { 130 {
122 SCOPED_TRACE("Secondary Locked"); 131 SCOPED_TRACE("Secondary Locked");
123 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_BOTTOM_LOCKED, 132 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_BOTTOM_LOCKED,
124 gfx::Rect(300, 0, 500, 453 + offset).ToString()); 133 gfx::Rect(300, 0, 500, 453 + offset));
125 } 134 }
126 { 135 {
127 SCOPED_TRACE("Secondary Right"); 136 SCOPED_TRACE("Secondary Right");
128 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_RIGHT, 137 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_RIGHT,
129 gfx::Rect(300, 0, 453 + offset, 500).ToString()); 138 gfx::Rect(300, 0, 453 + offset, 500));
130 } 139 }
131 { 140 {
132 SCOPED_TRACE("Secondary Left"); 141 SCOPED_TRACE("Secondary Left");
133 TestLauncherAlignment( 142 TestLauncherAlignment(root_windows[1], SHELF_ALIGNMENT_LEFT,
134 root_windows[1], SHELF_ALIGNMENT_LEFT, 143 gfx::Rect(300 + kShelfSize, 0, 453 + offset, 500));
135 gfx::Rect(300 + kShelfSize, 0, 453 + offset, 500).ToString());
136 } 144 }
137 } 145 }
138 #endif // defined(OS_CHROMEOS)
139 146
140 // Makes sure the shelf is initially sized correctly. 147 // Makes sure the shelf is initially sized correctly.
141 TEST_P(ShelfWidgetTest, LauncherInitiallySized) { 148 TEST_P(ShelfWidgetTest, LauncherInitiallySized) {
142 ShelfWidget* shelf_widget = GetShelfWidget(); 149 ShelfWidget* shelf_widget = GetShelfWidget();
143 Shelf* shelf = shelf_widget->shelf(); 150 Shelf* shelf = shelf_widget->shelf();
144 ASSERT_TRUE(shelf); 151 ASSERT_TRUE(shelf);
145 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); 152 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager();
146 ASSERT_TRUE(shelf_layout_manager); 153 ASSERT_TRUE(shelf_layout_manager);
147 ASSERT_TRUE(shelf_widget->status_area_widget()); 154 ASSERT_TRUE(shelf_widget->status_area_widget());
148 int status_width = 155 int status_width =
149 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width(); 156 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width();
150 // Test only makes sense if the status is > 0, which it better be. 157 // Test only makes sense if the status is > 0, which it better be.
151 EXPECT_GT(status_width, 0); 158 EXPECT_GT(status_width, 0);
152 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() - 159 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() -
153 test::ShelfTestAPI(shelf).shelf_view()->width()); 160 test::ShelfTestAPI(shelf).shelf_view()->width());
154 } 161 }
155 162
156 // Verifies when the shell is deleted with a full screen window we don't crash. 163 // Verifies when the shell is deleted with a full screen window we don't crash.
157 TEST_P(ShelfWidgetTest, DontReferenceShelfAfterDeletion) { 164 TEST_P(ShelfWidgetTest, DontReferenceShelfAfterDeletion) {
158 views::Widget* widget = new views::Widget; 165 views::Widget* widget = new views::Widget;
159 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 166 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
160 params.bounds = gfx::Rect(0, 0, 200, 200); 167 params.bounds = gfx::Rect(0, 0, 200, 200);
161 params.context = CurrentContext(); 168 params.context = CurrentContext();
162 // Widget is now owned by the parent window. 169 // Widget is now owned by the parent window.
163 widget->Init(params); 170 widget->Init(params);
164 widget->SetFullscreen(true); 171 widget->SetFullscreen(true);
165 } 172 }
166 173
167 #if defined(OS_CHROMEOS)
168 // Verifies shelf is created with correct size after user login and when its 174 // Verifies shelf is created with correct size after user login and when its
169 // container and status widget has finished sizing. 175 // container and status widget has finished sizing.
170 // See http://crbug.com/252533 176 // See http://crbug.com/252533
171 TEST_P(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) { 177 TEST_P(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) {
178 if (!SupportsMultipleDisplays())
179 return;
180
172 SetUserLoggedIn(false); 181 SetUserLoggedIn(false);
173 UpdateDisplay("300x200,400x300"); 182 UpdateDisplay("300x200,400x300");
174 183
175 ShelfWidget* shelf_widget = NULL; 184 ShelfWidget* shelf_widget = nullptr;
176 Shell::RootWindowControllerList controllers( 185 Shell::RootWindowControllerList controllers(
177 Shell::GetAllRootWindowControllers()); 186 Shell::GetAllRootWindowControllers());
178 for (Shell::RootWindowControllerList::const_iterator i = controllers.begin(); 187 for (Shell::RootWindowControllerList::const_iterator i = controllers.begin();
179 i != controllers.end(); ++i) { 188 i != controllers.end(); ++i) {
180 if (!(*i)->shelf_widget()->shelf()) { 189 if (!(*i)->shelf_widget()->shelf()) {
181 shelf_widget = (*i)->shelf_widget(); 190 shelf_widget = (*i)->shelf_widget();
182 break; 191 break;
183 } 192 }
184 } 193 }
185 ASSERT_TRUE(shelf_widget != NULL); 194 ASSERT_TRUE(shelf_widget);
186 195
187 SetUserLoggedIn(true); 196 SetUserLoggedIn(true);
188 Shell::GetInstance()->CreateShelf(); 197 Shell::GetInstance()->CreateShelf();
189 198
190 Shelf* shelf = shelf_widget->shelf(); 199 Shelf* shelf = shelf_widget->shelf();
191 ASSERT_TRUE(shelf != NULL); 200 ASSERT_TRUE(shelf);
192 201
193 const int status_width = 202 const int status_width =
194 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width(); 203 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width();
195 EXPECT_GT(status_width, 0); 204 EXPECT_GT(status_width, 0);
196 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() - 205 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() -
197 test::ShelfTestAPI(shelf).shelf_view()->width()); 206 test::ShelfTestAPI(shelf).shelf_view()->width());
198 } 207 }
199 #endif // defined(OS_CHROMEOS)
200 208
201 // Tests that the shelf lets mouse-events close to the edge fall through to the 209 // Tests that the shelf lets mouse-events close to the edge fall through to the
202 // window underneath. 210 // window underneath.
203 TEST_P(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) { 211 TEST_P(ShelfWidgetTest, ShelfEdgeOverlappingWindowHitTestMouse) {
204 if (!SupportsHostWindowResize()) 212 if (!SupportsHostWindowResize())
205 return; 213 return;
206 214
207 UpdateDisplay("400x400"); 215 UpdateDisplay("400x400");
208 ShelfWidget* shelf_widget = GetShelfWidget(); 216 ShelfWidget* shelf_widget = GetShelfWidget();
209 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen(); 217 gfx::Rect shelf_bounds = shelf_widget->GetWindowBoundsInScreen();
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 487 }
480 488
481 TEST_P(ShelfWidgetTestWithDelegate, CreateLockedShelf) { 489 TEST_P(ShelfWidgetTestWithDelegate, CreateLockedShelf) {
482 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior. 490 // The auto hide state 'HIDDEN' is returned for any non-auto-hide behavior.
483 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED, 491 TestCreateShelfWithInitialValues(SHELF_ALIGNMENT_BOTTOM_LOCKED,
484 SHELF_AUTO_HIDE_BEHAVIOR_NEVER, 492 SHELF_AUTO_HIDE_BEHAVIOR_NEVER,
485 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN); 493 SHELF_VISIBLE, SHELF_AUTO_HIDE_HIDDEN);
486 } 494 }
487 495
488 } // namespace ash 496 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view_unittest.cc ('k') | ash/shell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698