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

Side by Side Diff: ash/system/user/tray_user_unittest.cc

Issue 406413004: Cleanups for aura/test/event_generator.h (resolve TODOs) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase at r285842 Created 6 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 | Annotate | Revision Log
OLDNEW
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/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_layout_manager.h" 8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_delegate.h" 10 #include "ash/shell_delegate.h"
11 #include "ash/system/tray/system_tray.h" 11 #include "ash/system/tray/system_tray.h"
12 #include "ash/system/tray/tray_constants.h" 12 #include "ash/system/tray/tray_constants.h"
13 #include "ash/system/user/tray_user.h" 13 #include "ash/system/user/tray_user.h"
14 #include "ash/system/user/tray_user_separator.h" 14 #include "ash/system/user/tray_user_separator.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/test_session_state_delegate.h" 16 #include "ash/test/test_session_state_delegate.h"
17 #include "ash/test/test_shell_delegate.h" 17 #include "ash/test/test_shell_delegate.h"
18 #include "components/user_manager/user_info.h" 18 #include "components/user_manager/user_info.h"
19 #include "ui/aura/test/event_generator.h" 19 #include "ui/events/test/event_generator.h"
20 #include "ui/gfx/animation/animation_container_element.h" 20 #include "ui/gfx/animation/animation_container_element.h"
21 #include "ui/views/view.h" 21 #include "ui/views/view.h"
22 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
23 23
24 namespace ash { 24 namespace ash {
25 25
26 class TrayUserTest : public ash::test::AshTestBase { 26 class TrayUserTest : public ash::test::AshTestBase {
27 public: 27 public:
28 TrayUserTest(); 28 TrayUserTest();
29 29
30 // testing::Test: 30 // testing::Test:
31 virtual void SetUp() OVERRIDE; 31 virtual void SetUp() OVERRIDE;
32 32
33 // This has to be called prior to first use with the proper configuration. 33 // This has to be called prior to first use with the proper configuration.
34 void InitializeParameters(int users_logged_in, bool multiprofile); 34 void InitializeParameters(int users_logged_in, bool multiprofile);
35 35
36 // Show the system tray menu using the provided event generator. 36 // Show the system tray menu using the provided event generator.
37 void ShowTrayMenu(aura::test::EventGenerator* generator); 37 void ShowTrayMenu(ui::test::EventGenerator* generator);
38 38
39 // Move the mouse over the user item. 39 // Move the mouse over the user item.
40 void MoveOverUserItem(aura::test::EventGenerator* generator, int index); 40 void MoveOverUserItem(ui::test::EventGenerator* generator, int index);
41 41
42 // Click on the user item. Note that the tray menu needs to be shown. 42 // Click on the user item. Note that the tray menu needs to be shown.
43 void ClickUserItem(aura::test::EventGenerator* generator, int index); 43 void ClickUserItem(ui::test::EventGenerator* generator, int index);
44 44
45 // Accessors to various system components. 45 // Accessors to various system components.
46 ShelfLayoutManager* shelf() { return shelf_; } 46 ShelfLayoutManager* shelf() { return shelf_; }
47 SystemTray* tray() { return tray_; } 47 SystemTray* tray() { return tray_; }
48 ash::test::TestSessionStateDelegate* delegate() { return delegate_; } 48 ash::test::TestSessionStateDelegate* delegate() { return delegate_; }
49 ash::TrayUser* tray_user(int index) { return tray_user_[index]; } 49 ash::TrayUser* tray_user(int index) { return tray_user_[index]; }
50 ash::TrayUserSeparator* tray_user_separator() { return tray_user_separator_; } 50 ash::TrayUserSeparator* tray_user_separator() { return tray_user_separator_; }
51 51
52 private: 52 private:
53 ShelfLayoutManager* shelf_; 53 ShelfLayoutManager* shelf_;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 // the access easier. 97 // the access easier.
98 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { 98 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) {
99 tray_user_.push_back(new ash::TrayUser(tray_, i)); 99 tray_user_.push_back(new ash::TrayUser(tray_, i));
100 tray_->AddTrayItem(tray_user_[i]); 100 tray_->AddTrayItem(tray_user_[i]);
101 } 101 }
102 // We then add also the separator. 102 // We then add also the separator.
103 tray_user_separator_ = new ash::TrayUserSeparator(tray_); 103 tray_user_separator_ = new ash::TrayUserSeparator(tray_);
104 tray_->AddTrayItem(tray_user_separator_); 104 tray_->AddTrayItem(tray_user_separator_);
105 } 105 }
106 106
107 void TrayUserTest::ShowTrayMenu(aura::test::EventGenerator* generator) { 107 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) {
108 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); 108 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint();
109 109
110 generator->MoveMouseTo(center.x(), center.y()); 110 generator->MoveMouseTo(center.x(), center.y());
111 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 111 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
112 generator->ClickLeftButton(); 112 generator->ClickLeftButton();
113 } 113 }
114 114
115 void TrayUserTest::MoveOverUserItem(aura::test::EventGenerator* generator, 115 void TrayUserTest::MoveOverUserItem(ui::test::EventGenerator* generator,
116 int index) { 116 int index) {
117 gfx::Point center = 117 gfx::Point center =
118 tray_user(index)->GetUserPanelBoundsInScreenForTest().CenterPoint(); 118 tray_user(index)->GetUserPanelBoundsInScreenForTest().CenterPoint();
119 119
120 generator->MoveMouseTo(center.x(), center.y()); 120 generator->MoveMouseTo(center.x(), center.y());
121 } 121 }
122 122
123 void TrayUserTest::ClickUserItem(aura::test::EventGenerator* generator, 123 void TrayUserTest::ClickUserItem(ui::test::EventGenerator* generator,
124 int index) { 124 int index) {
125 MoveOverUserItem(generator, index); 125 MoveOverUserItem(generator, index);
126 generator->ClickLeftButton(); 126 generator->ClickLeftButton();
127 } 127 }
128 128
129 // Make sure that we show items for all users in the tray accordingly. 129 // Make sure that we show items for all users in the tray accordingly.
130 TEST_F(TrayUserTest, CheckTrayItemSize) { 130 TEST_F(TrayUserTest, CheckTrayItemSize) {
131 InitializeParameters(1, false); 131 InitializeParameters(1, false);
132 tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_GUEST); 132 tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_GUEST);
133 gfx::Size size = tray_user(0)->GetLayoutSizeForTest(); 133 gfx::Size size = tray_user(0)->GetLayoutSizeForTest();
134 EXPECT_EQ(kTrayItemSize, size.height()); 134 EXPECT_EQ(kTrayItemSize, size.height());
135 tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_USER); 135 tray_user(0)->UpdateAfterLoginStatusChangeForTest(user::LOGGED_IN_USER);
136 size = tray_user(0)->GetLayoutSizeForTest(); 136 size = tray_user(0)->GetLayoutSizeForTest();
137 EXPECT_EQ(kTrayItemSize, size.height()); 137 EXPECT_EQ(kTrayItemSize, size.height());
138 } 138 }
139 139
140 // Make sure that in single user mode the user panel cannot be activated and no 140 // Make sure that in single user mode the user panel cannot be activated and no
141 // separators are being created. 141 // separators are being created.
142 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { 142 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) {
143 InitializeParameters(1, false); 143 InitializeParameters(1, false);
144 144
145 // Move the mouse over the status area and click to open the status menu. 145 // Move the mouse over the status area and click to open the status menu.
146 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 146 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
147 147
148 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 148 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
149 149
150 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 150 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
151 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 151 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
152 EXPECT_FALSE(tray_user_separator()->separator_shown()); 152 EXPECT_FALSE(tray_user_separator()->separator_shown());
153 153
154 ShowTrayMenu(&generator); 154 ShowTrayMenu(&generator);
155 155
156 EXPECT_TRUE(tray()->HasSystemBubble()); 156 EXPECT_TRUE(tray()->HasSystemBubble());
157 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); 157 EXPECT_TRUE(tray()->IsAnyBubbleVisible());
158 158
159 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 159 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
160 EXPECT_EQ(i == 0 ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, 160 EXPECT_EQ(i == 0 ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN,
161 tray_user(i)->GetStateForTest()); 161 tray_user(i)->GetStateForTest());
162 EXPECT_FALSE(tray_user_separator()->separator_shown()); 162 EXPECT_FALSE(tray_user_separator()->separator_shown());
163 tray()->CloseSystemBubble(); 163 tray()->CloseSystemBubble();
164 } 164 }
165 165
166 #if defined(OS_CHROMEOS) 166 #if defined(OS_CHROMEOS)
167 // Make sure that in multi user mode the user panel can be activated and there 167 // Make sure that in multi user mode the user panel can be activated and there
168 // will be one panel for each user plus one additional separator at the end. 168 // will be one panel for each user plus one additional separator at the end.
169 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested 169 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested
170 // here since it does not work with the event system in unit tests. 170 // here since it does not work with the event system in unit tests.
171 TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) { 171 TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) {
172 InitializeParameters(1, true); 172 InitializeParameters(1, true);
173 173
174 // Move the mouse over the status area and click to open the status menu. 174 // Move the mouse over the status area and click to open the status menu.
175 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 175 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
176 generator.set_async(false); 176 generator.set_async(false);
177 177
178 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); 178 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers();
179 // Checking now for each amount of users that the correct is done. 179 // Checking now for each amount of users that the correct is done.
180 for (int j = 1; j < max_users; j++) { 180 for (int j = 1; j < max_users; j++) {
181 // Set the number of logged in users. 181 // Set the number of logged in users.
182 delegate()->set_logged_in_users(j); 182 delegate()->set_logged_in_users(j);
183 183
184 // Verify that nothing is shown. 184 // Verify that nothing is shown.
185 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 185 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 225 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
226 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 226 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
227 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 227 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
228 } 228 }
229 } 229 }
230 230
231 // Make sure that user changing gets properly executed. 231 // Make sure that user changing gets properly executed.
232 TEST_F(TrayUserTest, MutiUserModeButtonClicks) { 232 TEST_F(TrayUserTest, MutiUserModeButtonClicks) {
233 // Have two users. 233 // Have two users.
234 InitializeParameters(2, true); 234 InitializeParameters(2, true);
235 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 235 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
236 ShowTrayMenu(&generator); 236 ShowTrayMenu(&generator);
237 237
238 // Switch to a new user - which has a capitalized name. 238 // Switch to a new user - which has a capitalized name.
239 ClickUserItem(&generator, 1); 239 ClickUserItem(&generator, 1);
240 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo(); 240 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo();
241 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); 241 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1);
242 EXPECT_EQ(active_user->GetUserID(), second_user->GetUserID()); 242 EXPECT_EQ(active_user->GetUserID(), second_user->GetUserID());
243 // Since the name is capitalized, the email should be different then the 243 // Since the name is capitalized, the email should be different then the
244 // user_id. 244 // user_id.
245 EXPECT_NE(active_user->GetUserID(), second_user->GetEmail()); 245 EXPECT_NE(active_user->GetUserID(), second_user->GetEmail());
246 tray()->CloseSystemBubble(); 246 tray()->CloseSystemBubble();
247 } 247 }
248 248
249 #endif 249 #endif
250 250
251 } // namespace ash 251 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/system_tray_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