OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_delegate.h" | 11 #include "ash/shell_delegate.h" |
12 #include "ash/system/tray/system_tray.h" | 12 #include "ash/system/tray/system_tray.h" |
13 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
14 #include "ash/system/user/tray_user.h" | 14 #include "ash/system/user/tray_user.h" |
15 #include "ash/system/user/tray_user_separator.h" | 15 #include "ash/system/user/tray_user_separator.h" |
16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/test_session_state_delegate.h" | 17 #include "ash/test/test_session_state_delegate.h" |
18 #include "ash/test/test_shell_delegate.h" | 18 #include "ash/test/test_shell_delegate.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "ui/aura/test/event_generator.h" | 20 #include "ui/aura/test/event_generator.h" |
21 #include "ui/gfx/animation/animation_container_element.h" | 21 #include "ui/gfx/animation/animation_container_element.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 namespace internal { | |
27 | 26 |
28 class TrayUserTest : public ash::test::AshTestBase { | 27 class TrayUserTest : public ash::test::AshTestBase { |
29 public: | 28 public: |
30 TrayUserTest(); | 29 TrayUserTest(); |
31 | 30 |
32 // testing::Test: | 31 // testing::Test: |
33 virtual void SetUp() OVERRIDE; | 32 virtual void SetUp() OVERRIDE; |
34 | 33 |
35 // This has to be called prior to first use with the proper configuration. | 34 // This has to be called prior to first use with the proper configuration. |
36 void InitializeParameters(int users_logged_in, bool multiprofile); | 35 void InitializeParameters(int users_logged_in, bool multiprofile); |
37 | 36 |
38 // Show the system tray menu using the provided event generator. | 37 // Show the system tray menu using the provided event generator. |
39 void ShowTrayMenu(aura::test::EventGenerator* generator); | 38 void ShowTrayMenu(aura::test::EventGenerator* generator); |
40 | 39 |
41 // Move the mouse over the user item. | 40 // Move the mouse over the user item. |
42 void MoveOverUserItem(aura::test::EventGenerator* generator, int index); | 41 void MoveOverUserItem(aura::test::EventGenerator* generator, int index); |
43 | 42 |
44 // Click on the user item. Note that the tray menu needs to be shown. | 43 // Click on the user item. Note that the tray menu needs to be shown. |
45 void ClickUserItem(aura::test::EventGenerator* generator, int index); | 44 void ClickUserItem(aura::test::EventGenerator* generator, int index); |
46 | 45 |
47 // Accessors to various system components. | 46 // Accessors to various system components. |
48 ShelfLayoutManager* shelf() { return shelf_; } | 47 ShelfLayoutManager* shelf() { return shelf_; } |
49 SystemTray* tray() { return tray_; } | 48 SystemTray* tray() { return tray_; } |
50 ash::test::TestSessionStateDelegate* delegate() { return delegate_; } | 49 ash::test::TestSessionStateDelegate* delegate() { return delegate_; } |
51 ash::internal::TrayUser* tray_user(int index) { return tray_user_[index]; } | 50 ash::TrayUser* tray_user(int index) { return tray_user_[index]; } |
52 ash::internal::TrayUserSeparator* tray_user_separator() { | 51 ash::TrayUserSeparator* tray_user_separator() { return tray_user_separator_; } |
53 return tray_user_separator_; | |
54 } | |
55 | 52 |
56 private: | 53 private: |
57 ShelfLayoutManager* shelf_; | 54 ShelfLayoutManager* shelf_; |
58 SystemTray* tray_; | 55 SystemTray* tray_; |
59 ash::test::TestSessionStateDelegate* delegate_; | 56 ash::test::TestSessionStateDelegate* delegate_; |
60 | 57 |
61 // Note that the ownership of these items is on the shelf. | 58 // Note that the ownership of these items is on the shelf. |
62 std::vector<ash::internal::TrayUser*> tray_user_; | 59 std::vector<ash::TrayUser*> tray_user_; |
63 | 60 |
64 // The separator between the tray users and the rest of the menu. | 61 // The separator between the tray users and the rest of the menu. |
65 // Note: The item will get owned by the shelf. | 62 // Note: The item will get owned by the shelf. |
66 TrayUserSeparator* tray_user_separator_; | 63 TrayUserSeparator* tray_user_separator_; |
67 | 64 |
68 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); | 65 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); |
69 }; | 66 }; |
70 | 67 |
71 TrayUserTest::TrayUserTest() | 68 TrayUserTest::TrayUserTest() |
72 : shelf_(NULL), | 69 : shelf_(NULL), |
(...skipping 20 matching lines...) Expand all Loading... |
93 // after everything was created. | 90 // after everything was created. |
94 delegate_->set_logged_in_users(users_logged_in); | 91 delegate_->set_logged_in_users(users_logged_in); |
95 ash::test::TestShellDelegate* shell_delegate = | 92 ash::test::TestShellDelegate* shell_delegate = |
96 static_cast<ash::test::TestShellDelegate*>( | 93 static_cast<ash::test::TestShellDelegate*>( |
97 ash::Shell::GetInstance()->delegate()); | 94 ash::Shell::GetInstance()->delegate()); |
98 shell_delegate->set_multi_profiles_enabled(multiprofile); | 95 shell_delegate->set_multi_profiles_enabled(multiprofile); |
99 | 96 |
100 // Instead of using the existing tray panels we create new ones which makes | 97 // Instead of using the existing tray panels we create new ones which makes |
101 // the access easier. | 98 // the access easier. |
102 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { | 99 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { |
103 tray_user_.push_back(new ash::internal::TrayUser(tray_, i)); | 100 tray_user_.push_back(new ash::TrayUser(tray_, i)); |
104 tray_->AddTrayItem(tray_user_[i]); | 101 tray_->AddTrayItem(tray_user_[i]); |
105 } | 102 } |
106 // We then add also the separator. | 103 // We then add also the separator. |
107 tray_user_separator_ = new ash::internal::TrayUserSeparator(tray_); | 104 tray_user_separator_ = new ash::TrayUserSeparator(tray_); |
108 tray_->AddTrayItem(tray_user_separator_); | 105 tray_->AddTrayItem(tray_user_separator_); |
109 } | 106 } |
110 | 107 |
111 void TrayUserTest::ShowTrayMenu(aura::test::EventGenerator* generator) { | 108 void TrayUserTest::ShowTrayMenu(aura::test::EventGenerator* generator) { |
112 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); | 109 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); |
113 | 110 |
114 generator->MoveMouseTo(center.x(), center.y()); | 111 generator->MoveMouseTo(center.x(), center.y()); |
115 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 112 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
116 generator->ClickLeftButton(); | 113 generator->ClickLeftButton(); |
117 } | 114 } |
(...skipping 27 matching lines...) Expand all Loading... |
145 // separators are being created. | 142 // separators are being created. |
146 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { | 143 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { |
147 InitializeParameters(1, false); | 144 InitializeParameters(1, false); |
148 | 145 |
149 // Move the mouse over the status area and click to open the status menu. | 146 // Move the mouse over the status area and click to open the status menu. |
150 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 147 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
151 | 148 |
152 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 149 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
153 | 150 |
154 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 151 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
155 EXPECT_EQ(ash::internal::TrayUser::HIDDEN, | 152 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); |
156 tray_user(i)->GetStateForTest()); | |
157 EXPECT_FALSE(tray_user_separator()->separator_shown()); | 153 EXPECT_FALSE(tray_user_separator()->separator_shown()); |
158 | 154 |
159 ShowTrayMenu(&generator); | 155 ShowTrayMenu(&generator); |
160 | 156 |
161 EXPECT_TRUE(tray()->HasSystemBubble()); | 157 EXPECT_TRUE(tray()->HasSystemBubble()); |
162 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); | 158 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); |
163 | 159 |
164 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 160 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
165 EXPECT_EQ(i == 0 ? ash::internal::TrayUser::SHOWN : | 161 EXPECT_EQ(i == 0 ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, |
166 ash::internal::TrayUser::HIDDEN, | |
167 tray_user(i)->GetStateForTest()); | 162 tray_user(i)->GetStateForTest()); |
168 EXPECT_FALSE(tray_user_separator()->separator_shown()); | 163 EXPECT_FALSE(tray_user_separator()->separator_shown()); |
169 tray()->CloseSystemBubble(); | 164 tray()->CloseSystemBubble(); |
170 } | 165 } |
171 | 166 |
172 #if defined(OS_CHROMEOS) | 167 #if defined(OS_CHROMEOS) |
173 // Make sure that in multi user mode the user panel can be activated and there | 168 // Make sure that in multi user mode the user panel can be activated and there |
174 // will be one panel for each user plus one additional separator at the end. | 169 // will be one panel for each user plus one additional separator at the end. |
175 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested | 170 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested |
176 // here since it does not work with the event system in unit tests. | 171 // here since it does not work with the event system in unit tests. |
(...skipping 16 matching lines...) Expand all Loading... |
193 EXPECT_FALSE(tray_user(i)->GetStateForTest()); | 188 EXPECT_FALSE(tray_user(i)->GetStateForTest()); |
194 EXPECT_FALSE(tray_user_separator()->separator_shown()); | 189 EXPECT_FALSE(tray_user_separator()->separator_shown()); |
195 // After clicking on the tray the menu should get shown and for each logged | 190 // After clicking on the tray the menu should get shown and for each logged |
196 // in user we should get a visible item. In addition, the separator should | 191 // in user we should get a visible item. In addition, the separator should |
197 // show up when we reach more then one user. | 192 // show up when we reach more then one user. |
198 ShowTrayMenu(&generator); | 193 ShowTrayMenu(&generator); |
199 | 194 |
200 EXPECT_TRUE(tray()->HasSystemBubble()); | 195 EXPECT_TRUE(tray()->HasSystemBubble()); |
201 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); | 196 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); |
202 for (int i = 0; i < max_users; i++) { | 197 for (int i = 0; i < max_users; i++) { |
203 EXPECT_EQ(i < j ? ash::internal::TrayUser::SHOWN : | 198 EXPECT_EQ(i < j ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, |
204 ash::internal::TrayUser::HIDDEN, | |
205 tray_user(i)->GetStateForTest()); | 199 tray_user(i)->GetStateForTest()); |
206 } | 200 } |
207 | 201 |
208 // Check the visibility of the separator. | 202 // Check the visibility of the separator. |
209 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); | 203 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); |
210 | 204 |
211 // Move the mouse over the user item and it should hover. | 205 // Move the mouse over the user item and it should hover. |
212 MoveOverUserItem(&generator, 0); | 206 MoveOverUserItem(&generator, 0); |
213 EXPECT_EQ(ash::internal::TrayUser::HOVERED, | 207 EXPECT_EQ(ash::TrayUser::HOVERED, tray_user(0)->GetStateForTest()); |
214 tray_user(0)->GetStateForTest()); | |
215 for (int i = 1; i < max_users; i++) { | 208 for (int i = 1; i < max_users; i++) { |
216 EXPECT_EQ(i < j ? ash::internal::TrayUser::SHOWN : | 209 EXPECT_EQ(i < j ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, |
217 ash::internal::TrayUser::HIDDEN, | |
218 tray_user(i)->GetStateForTest()); | 210 tray_user(i)->GetStateForTest()); |
219 } | 211 } |
220 | 212 |
221 // Check that clicking the button allows to add item if we have still room | 213 // Check that clicking the button allows to add item if we have still room |
222 // for one more user. | 214 // for one more user. |
223 ClickUserItem(&generator, 0); | 215 ClickUserItem(&generator, 0); |
224 EXPECT_EQ(j == max_users ? | 216 EXPECT_EQ(j == max_users ? ash::TrayUser::ACTIVE_BUT_DISABLED |
225 ash::internal::TrayUser::ACTIVE_BUT_DISABLED : | 217 : ash::TrayUser::ACTIVE, |
226 ash::internal::TrayUser::ACTIVE, | |
227 tray_user(0)->GetStateForTest()); | 218 tray_user(0)->GetStateForTest()); |
228 | 219 |
229 // Click the button again to see that the menu goes away. | 220 // Click the button again to see that the menu goes away. |
230 ClickUserItem(&generator, 0); | 221 ClickUserItem(&generator, 0); |
231 EXPECT_EQ(ash::internal::TrayUser::HOVERED, | 222 EXPECT_EQ(ash::TrayUser::HOVERED, tray_user(0)->GetStateForTest()); |
232 tray_user(0)->GetStateForTest()); | |
233 | 223 |
234 // Close and check that everything is deleted. | 224 // Close and check that everything is deleted. |
235 tray()->CloseSystemBubble(); | 225 tray()->CloseSystemBubble(); |
236 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 226 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
237 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 227 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
238 EXPECT_EQ(ash::internal::TrayUser::HIDDEN, | 228 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); |
239 tray_user(i)->GetStateForTest()); | |
240 } | 229 } |
241 } | 230 } |
242 | 231 |
243 // Make sure that user changing gets properly executed. | 232 // Make sure that user changing gets properly executed. |
244 TEST_F(TrayUserTest, MutiUserModeButtonClicks) { | 233 TEST_F(TrayUserTest, MutiUserModeButtonClicks) { |
245 // Have two users. | 234 // Have two users. |
246 InitializeParameters(2, true); | 235 InitializeParameters(2, true); |
247 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 236 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
248 ShowTrayMenu(&generator); | 237 ShowTrayMenu(&generator); |
249 | 238 |
250 // Switch to a new user - which has a capitalized name. | 239 // Switch to a new user - which has a capitalized name. |
251 ClickUserItem(&generator, 1); | 240 ClickUserItem(&generator, 1); |
252 EXPECT_EQ(delegate()->get_activated_user(), delegate()->GetUserID(1)); | 241 EXPECT_EQ(delegate()->get_activated_user(), delegate()->GetUserID(1)); |
253 // Since the name is capitalized, the email should be different then the | 242 // Since the name is capitalized, the email should be different then the |
254 // user_id. | 243 // user_id. |
255 EXPECT_NE(delegate()->get_activated_user(), delegate()->GetUserEmail(1)); | 244 EXPECT_NE(delegate()->get_activated_user(), delegate()->GetUserEmail(1)); |
256 tray()->CloseSystemBubble(); | 245 tray()->CloseSystemBubble(); |
257 } | 246 } |
258 | 247 |
259 #endif | 248 #endif |
260 | 249 |
261 } // namespace internal | |
262 } // namespace ash | 250 } // namespace ash |
OLD | NEW |