OLD | NEW |
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/launcher/launcher.h" | |
8 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shelf/shelf.h" |
9 #include "ash/shelf/shelf_button.h" | 9 #include "ash/shelf/shelf_button.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
11 #include "ash/shelf/shelf_model.h" | 11 #include "ash/shelf/shelf_model.h" |
12 #include "ash/shelf/shelf_view.h" | 12 #include "ash/shelf/shelf_view.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/test/ash_test_base.h" | 14 #include "ash/test/ash_test_base.h" |
15 #include "ash/test/launcher_test_api.h" | 15 #include "ash/test/shelf_test_api.h" |
16 #include "ash/test/shelf_view_test_api.h" | 16 #include "ash/test/shelf_view_test_api.h" |
17 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
18 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
19 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
20 #include "ui/gfx/screen.h" | 20 #include "ui/gfx/screen.h" |
21 #include "ui/views/corewm/corewm_switches.h" | 21 #include "ui/views/corewm/corewm_switches.h" |
22 #include "ui/views/view.h" | 22 #include "ui/views/view.h" |
23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
24 | 24 |
25 namespace ash { | 25 namespace ash { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 ShelfWidget* GetShelfWidget() { | 29 ShelfWidget* GetShelfWidget() { |
30 return Launcher::ForPrimaryDisplay()->shelf_widget(); | 30 return Shelf::ForPrimaryDisplay()->shelf_widget(); |
31 } | 31 } |
32 | 32 |
33 internal::ShelfLayoutManager* GetShelfLayoutManager() { | 33 internal::ShelfLayoutManager* GetShelfLayoutManager() { |
34 return GetShelfWidget()->shelf_layout_manager(); | 34 return GetShelfWidget()->shelf_layout_manager(); |
35 } | 35 } |
36 | 36 |
37 } // namespace | 37 } // namespace |
38 | 38 |
39 typedef test::AshTestBase ShelfWidgetTest; | 39 typedef test::AshTestBase ShelfWidgetTest; |
40 | 40 |
41 // Shelf can't be activated on mouse click, but it is activable from | 41 // Shelf can't be activated on mouse click, but it is activable from |
42 // the focus cycler or as fallback. | 42 // the focus cycler or as fallback. |
43 // TODO(mtomasz): make this test work with the FocusController. | 43 // TODO(mtomasz): make this test work with the FocusController. |
44 // crbug.com/285364. | 44 // crbug.com/285364. |
45 TEST_F(ShelfWidgetTest, DISABLED_ActivateAsFallback) { | 45 TEST_F(ShelfWidgetTest, DISABLED_ActivateAsFallback) { |
46 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 46 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
47 ShelfWidget* shelf_widget = launcher->shelf_widget(); | 47 ShelfWidget* shelf_widget = shelf->shelf_widget(); |
48 EXPECT_FALSE(shelf_widget->CanActivate()); | 48 EXPECT_FALSE(shelf_widget->CanActivate()); |
49 | 49 |
50 shelf_widget->WillActivateAsFallback(); | 50 shelf_widget->WillActivateAsFallback(); |
51 EXPECT_TRUE(shelf_widget->CanActivate()); | 51 EXPECT_TRUE(shelf_widget->CanActivate()); |
52 | 52 |
53 wm::ActivateWindow(shelf_widget->GetNativeWindow()); | 53 wm::ActivateWindow(shelf_widget->GetNativeWindow()); |
54 EXPECT_FALSE(shelf_widget->CanActivate()); | 54 EXPECT_FALSE(shelf_widget->CanActivate()); |
55 } | 55 } |
56 | 56 |
57 void TestLauncherAlignment(aura::Window* root, | 57 void TestLauncherAlignment(aura::Window* root, |
58 ShelfAlignment alignment, | 58 ShelfAlignment alignment, |
59 const std::string& expected) { | 59 const std::string& expected) { |
60 Shell::GetInstance()->SetShelfAlignment(alignment, root); | 60 Shell::GetInstance()->SetShelfAlignment(alignment, root); |
61 gfx::Screen* screen = gfx::Screen::GetScreenFor(root); | 61 gfx::Screen* screen = gfx::Screen::GetScreenFor(root); |
62 EXPECT_EQ(expected, | 62 EXPECT_EQ(expected, |
63 screen->GetDisplayNearestWindow(root).work_area().ToString()); | 63 screen->GetDisplayNearestWindow(root).work_area().ToString()); |
64 } | 64 } |
65 | 65 |
66 TEST_F(ShelfWidgetTest, TestAlignment) { | 66 TEST_F(ShelfWidgetTest, TestAlignment) { |
67 Launcher* launcher = Launcher::ForPrimaryDisplay(); | 67 Shelf* shelf = Shelf::ForPrimaryDisplay(); |
68 UpdateDisplay("400x400"); | 68 UpdateDisplay("400x400"); |
69 ASSERT_TRUE(launcher); | 69 ASSERT_TRUE(shelf); |
70 { | 70 { |
71 SCOPED_TRACE("Single Bottom"); | 71 SCOPED_TRACE("Single Bottom"); |
72 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | 72 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), |
73 SHELF_ALIGNMENT_BOTTOM, | 73 SHELF_ALIGNMENT_BOTTOM, |
74 "0,0 400x353"); | 74 "0,0 400x353"); |
75 } | 75 } |
76 { | 76 { |
77 SCOPED_TRACE("Single Right"); | 77 SCOPED_TRACE("Single Right"); |
78 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), | 78 TestLauncherAlignment(Shell::GetPrimaryRootWindow(), |
79 SHELF_ALIGNMENT_RIGHT, | 79 SHELF_ALIGNMENT_RIGHT, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 "300,0 453x500"); | 121 "300,0 453x500"); |
122 } | 122 } |
123 { | 123 { |
124 SCOPED_TRACE("Secondary Left"); | 124 SCOPED_TRACE("Secondary Left"); |
125 TestLauncherAlignment(root_windows[1], | 125 TestLauncherAlignment(root_windows[1], |
126 SHELF_ALIGNMENT_LEFT, | 126 SHELF_ALIGNMENT_LEFT, |
127 "347,0 453x500"); | 127 "347,0 453x500"); |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 // Makes sure the launcher is initially sized correctly. | 131 // Makes sure the shelf is initially sized correctly. |
132 TEST_F(ShelfWidgetTest, LauncherInitiallySized) { | 132 TEST_F(ShelfWidgetTest, LauncherInitiallySized) { |
133 ShelfWidget* shelf_widget = GetShelfWidget(); | 133 ShelfWidget* shelf_widget = GetShelfWidget(); |
134 Launcher* launcher = shelf_widget->launcher(); | 134 Shelf* shelf = shelf_widget->shelf(); |
135 ASSERT_TRUE(launcher); | 135 ASSERT_TRUE(shelf); |
136 internal::ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 136 internal::ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); |
137 ASSERT_TRUE(shelf_layout_manager); | 137 ASSERT_TRUE(shelf_layout_manager); |
138 ASSERT_TRUE(shelf_widget->status_area_widget()); | 138 ASSERT_TRUE(shelf_widget->status_area_widget()); |
139 int status_width = shelf_widget->status_area_widget()-> | 139 int status_width = shelf_widget->status_area_widget()-> |
140 GetWindowBoundsInScreen().width(); | 140 GetWindowBoundsInScreen().width(); |
141 // Test only makes sense if the status is > 0, which it better be. | 141 // Test only makes sense if the status is > 0, which it better be. |
142 EXPECT_GT(status_width, 0); | 142 EXPECT_GT(status_width, 0); |
143 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() - | 143 EXPECT_EQ(status_width, shelf_widget->GetContentsView()->width() - |
144 test::LauncherTestAPI(launcher).shelf_view()->width()); | 144 test::ShelfTestAPI(shelf).shelf_view()->width()); |
145 } | 145 } |
146 | 146 |
147 // Verifies when the shell is deleted with a full screen window we don't crash. | 147 // Verifies when the shell is deleted with a full screen window we don't crash. |
148 TEST_F(ShelfWidgetTest, DontReferenceLauncherAfterDeletion) { | 148 TEST_F(ShelfWidgetTest, DontReferenceShelfAfterDeletion) { |
149 views::Widget* widget = new views::Widget; | 149 views::Widget* widget = new views::Widget; |
150 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 150 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
151 params.bounds = gfx::Rect(0, 0, 200, 200); | 151 params.bounds = gfx::Rect(0, 0, 200, 200); |
152 params.context = CurrentContext(); | 152 params.context = CurrentContext(); |
153 // Widget is now owned by the parent window. | 153 // Widget is now owned by the parent window. |
154 widget->Init(params); | 154 widget->Init(params); |
155 widget->SetFullscreen(true); | 155 widget->SetFullscreen(true); |
156 } | 156 } |
157 | 157 |
158 #if defined(OS_CHROMEOS) | 158 #if defined(OS_CHROMEOS) |
159 // Verifies launcher is created with correct size after user login and when its | 159 // Verifies shelf is created with correct size after user login and when its |
160 // container and status widget has finished sizing. | 160 // container and status widget has finished sizing. |
161 // See http://crbug.com/252533 | 161 // See http://crbug.com/252533 |
162 TEST_F(ShelfWidgetTest, LauncherInitiallySizedAfterLogin) { | 162 TEST_F(ShelfWidgetTest, ShelfInitiallySizedAfterLogin) { |
163 SetUserLoggedIn(false); | 163 SetUserLoggedIn(false); |
164 UpdateDisplay("300x200,400x300"); | 164 UpdateDisplay("300x200,400x300"); |
165 | 165 |
166 ShelfWidget* shelf = NULL; | 166 ShelfWidget* shelf_widget = NULL; |
167 Shell::RootWindowControllerList controllers( | 167 Shell::RootWindowControllerList controllers( |
168 Shell::GetAllRootWindowControllers()); | 168 Shell::GetAllRootWindowControllers()); |
169 for (Shell::RootWindowControllerList::const_iterator i = controllers.begin(); | 169 for (Shell::RootWindowControllerList::const_iterator i = controllers.begin(); |
170 i != controllers.end(); | 170 i != controllers.end(); |
171 ++i) { | 171 ++i) { |
172 if (!(*i)->shelf()->launcher()) { | 172 if (!(*i)->shelf()->shelf()) { |
173 shelf = (*i)->shelf(); | 173 shelf_widget = (*i)->shelf(); |
174 break; | 174 break; |
175 } | 175 } |
176 } | 176 } |
| 177 ASSERT_TRUE(shelf_widget != NULL); |
| 178 |
| 179 SetUserLoggedIn(true); |
| 180 Shell::GetInstance()->CreateShelf(); |
| 181 |
| 182 Shelf* shelf = shelf_widget->shelf(); |
177 ASSERT_TRUE(shelf != NULL); | 183 ASSERT_TRUE(shelf != NULL); |
178 | 184 |
179 SetUserLoggedIn(true); | |
180 Shell::GetInstance()->CreateLauncher(); | |
181 | |
182 Launcher* launcher = shelf->launcher(); | |
183 ASSERT_TRUE(launcher != NULL); | |
184 | |
185 const int status_width = | 185 const int status_width = |
186 shelf->status_area_widget()->GetWindowBoundsInScreen().width(); | 186 shelf_widget->status_area_widget()->GetWindowBoundsInScreen().width(); |
187 EXPECT_GT(status_width, 0); | 187 EXPECT_GT(status_width, 0); |
188 EXPECT_EQ(status_width, | 188 EXPECT_EQ(status_width, |
189 shelf->GetContentsView()->width() - | 189 shelf_widget->GetContentsView()->width() - |
190 test::LauncherTestAPI(launcher).shelf_view()->width()); | 190 test::ShelfTestAPI(shelf).shelf_view()->width()); |
191 } | 191 } |
192 #endif | 192 #endif |
193 | 193 |
194 } // namespace ash | 194 } // namespace ash |
OLD | NEW |