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

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

Issue 2125373002: mash: Migrate ash/system/user to ash/common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync and 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 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/common/shell_delegate.h" 7 #include "ash/common/shell_delegate.h"
8 #include "ash/common/system/tray/tray_constants.h" 8 #include "ash/common/system/tray/tray_constants.h"
9 #include "ash/common/system/user/tray_user.h"
9 #include "ash/common/system/user/tray_user_separator.h" 10 #include "ash/common/system/user/tray_user_separator.h"
11 #include "ash/common/system/user/user_view.h"
10 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
11 #include "ash/root_window_controller.h"
12 #include "ash/shell.h"
13 #include "ash/system/tray/system_tray.h" 13 #include "ash/system/tray/system_tray.h"
14 #include "ash/system/user/tray_user.h"
15 #include "ash/system/user/user_view.h"
16 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
17 #include "ash/test/ash_test_helper.h" 15 #include "ash/test/ash_test_helper.h"
18 #include "ash/test/test_session_state_delegate.h" 16 #include "ash/test/test_session_state_delegate.h"
19 #include "ash/test/test_shell_delegate.h" 17 #include "ash/test/test_shell_delegate.h"
20 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
21 #include "components/signin/core/account_id/account_id.h" 19 #include "components/signin/core/account_id/account_id.h"
22 #include "components/user_manager/user_info.h" 20 #include "components/user_manager/user_info.h"
23 #include "ui/accessibility/ax_view_state.h" 21 #include "ui/accessibility/ax_view_state.h"
24 #include "ui/events/test/event_generator.h" 22 #include "ui/events/test/event_generator.h"
25 #include "ui/gfx/animation/animation_container_element.h" 23 #include "ui/gfx/animation/animation_container_element.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 60
63 // 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.
64 // Note: The item will get owned by the shelf. 62 // Note: The item will get owned by the shelf.
65 TrayUserSeparator* tray_user_separator_ = nullptr; 63 TrayUserSeparator* tray_user_separator_ = nullptr;
66 64
67 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); 65 DISALLOW_COPY_AND_ASSIGN(TrayUserTest);
68 }; 66 };
69 67
70 void TrayUserTest::SetUp() { 68 void TrayUserTest::SetUp() {
71 test::AshTestBase::SetUp(); 69 test::AshTestBase::SetUp();
72 tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray(); 70 tray_ = GetPrimarySystemTray();
73 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate(); 71 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate();
74 } 72 }
75 73
76 void TrayUserTest::InitializeParameters(int users_logged_in, 74 void TrayUserTest::InitializeParameters(int users_logged_in,
77 bool multiprofile) { 75 bool multiprofile) {
78 // Set our default assumptions. Note that it is sufficient to set these 76 // Set our default assumptions. Note that it is sufficient to set these
79 // after everything was created. 77 // after everything was created.
80 delegate_->set_logged_in_users(users_logged_in); 78 delegate_->set_logged_in_users(users_logged_in);
81 test::TestShellDelegate* shell_delegate = 79 test::TestShellDelegate* shell_delegate =
82 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); 80 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate());
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 size = tray_user(0)->GetLayoutSizeForTest(); 123 size = tray_user(0)->GetLayoutSizeForTest();
126 EXPECT_EQ(kTrayItemSize, size.height()); 124 EXPECT_EQ(kTrayItemSize, size.height());
127 } 125 }
128 126
129 // Make sure that in single user mode the user panel cannot be activated and no 127 // Make sure that in single user mode the user panel cannot be activated and no
130 // separators are being created. 128 // separators are being created.
131 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { 129 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) {
132 InitializeParameters(1, false); 130 InitializeParameters(1, false);
133 131
134 // Move the mouse over the status area and click to open the status menu. 132 // Move the mouse over the status area and click to open the status menu.
135 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 133 ui::test::EventGenerator& generator = GetEventGenerator();
136 134
137 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 135 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
138 136
139 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 137 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
140 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 138 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
141 EXPECT_FALSE(tray_user_separator()->separator_shown()); 139 EXPECT_FALSE(tray_user_separator()->separator_shown());
142 140
143 ShowTrayMenu(&generator); 141 ShowTrayMenu(&generator);
144 142
145 EXPECT_TRUE(tray()->HasSystemBubble()); 143 EXPECT_TRUE(tray()->HasSystemBubble());
146 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); 144 EXPECT_TRUE(tray()->IsAnyBubbleVisible());
147 145
148 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 146 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
149 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, 147 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN,
150 tray_user(i)->GetStateForTest()); 148 tray_user(i)->GetStateForTest());
151 EXPECT_FALSE(tray_user_separator()->separator_shown()); 149 EXPECT_FALSE(tray_user_separator()->separator_shown());
152 tray()->CloseSystemBubble(); 150 tray()->CloseSystemBubble();
153 } 151 }
154 152
155 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { 153 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) {
156 InitializeParameters(1, false); 154 InitializeParameters(1, false);
157 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 155 ui::test::EventGenerator& generator = GetEventGenerator();
158 ShowTrayMenu(&generator); 156 ShowTrayMenu(&generator);
159 157
160 views::View* view = 158 views::View* view =
161 tray_user(0)->user_view_for_test()->user_card_view_for_test(); 159 tray_user(0)->user_view_for_test()->user_card_view_for_test();
162 ui::AXViewState state; 160 ui::AXViewState state;
163 view->GetAccessibleState(&state); 161 view->GetAccessibleState(&state);
164 EXPECT_EQ( 162 EXPECT_EQ(
165 base::UTF8ToUTF16("Über tray Über tray Über tray Über tray First@tray"), 163 base::UTF8ToUTF16("Über tray Über tray Über tray Über tray First@tray"),
166 state.name); 164 state.name);
167 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, state.role); 165 EXPECT_EQ(ui::AX_ROLE_STATIC_TEXT, state.role);
168 } 166 }
169 167
170 TEST_F(TrayUserTest, AccessibleLabelContainsMultiUserInfo) { 168 TEST_F(TrayUserTest, AccessibleLabelContainsMultiUserInfo) {
171 InitializeParameters(1, true); 169 InitializeParameters(1, true);
172 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 170 ui::test::EventGenerator& generator = GetEventGenerator();
173 ShowTrayMenu(&generator); 171 ShowTrayMenu(&generator);
174 172
175 views::View* view = 173 views::View* view =
176 tray_user(0)->user_view_for_test()->user_card_view_for_test(); 174 tray_user(0)->user_view_for_test()->user_card_view_for_test();
177 ui::AXViewState state; 175 ui::AXViewState state;
178 view->GetAccessibleState(&state); 176 view->GetAccessibleState(&state);
179 EXPECT_EQ( 177 EXPECT_EQ(
180 base::UTF8ToUTF16("Über tray Über tray Über tray Über tray First@tray"), 178 base::UTF8ToUTF16("Über tray Über tray Über tray Über tray First@tray"),
181 state.name); 179 state.name);
182 EXPECT_EQ(ui::AX_ROLE_BUTTON, state.role); 180 EXPECT_EQ(ui::AX_ROLE_BUTTON, state.role);
183 } 181 }
184 182
185 #if defined(OS_CHROMEOS) 183 #if defined(OS_CHROMEOS)
186 // Make sure that in multi user mode the user panel can be activated and there 184 // Make sure that in multi user mode the user panel can be activated and there
187 // will be one panel for each user plus one additional separator at the end. 185 // will be one panel for each user plus one additional separator at the end.
188 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested 186 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested
189 // here since it does not work with the event system in unit tests. 187 // here since it does not work with the event system in unit tests.
190 TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) { 188 TEST_F(TrayUserTest, MutiUserModeDoesNotAllowToAddUser) {
191 InitializeParameters(1, true); 189 InitializeParameters(1, true);
192 190
193 // Move the mouse over the status area and click to open the status menu. 191 // Move the mouse over the status area and click to open the status menu.
194 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 192 ui::test::EventGenerator& generator = GetEventGenerator();
195 generator.set_async(false); 193 generator.set_async(false);
196 194
197 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); 195 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers();
198 // Checking now for each amount of users that the correct is done. 196 // Checking now for each amount of users that the correct is done.
199 for (int j = 1; j < max_users; j++) { 197 for (int j = 1; j < max_users; j++) {
200 // Set the number of logged in users. 198 // Set the number of logged in users.
201 delegate()->set_logged_in_users(j); 199 delegate()->set_logged_in_users(j);
202 200
203 // Verify that nothing is shown. 201 // Verify that nothing is shown.
204 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 202 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 241 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
244 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 242 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
245 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 243 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
246 } 244 }
247 } 245 }
248 246
249 // Make sure that user changing gets properly executed. 247 // Make sure that user changing gets properly executed.
250 TEST_F(TrayUserTest, MutiUserModeButtonClicks) { 248 TEST_F(TrayUserTest, MutiUserModeButtonClicks) {
251 // Have two users. 249 // Have two users.
252 InitializeParameters(2, true); 250 InitializeParameters(2, true);
253 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 251 ui::test::EventGenerator& generator = GetEventGenerator();
254 ShowTrayMenu(&generator); 252 ShowTrayMenu(&generator);
255 253
256 // Switch to a new user - which has a capitalized name. 254 // Switch to a new user - which has a capitalized name.
257 ClickUserItem(&generator, 1); 255 ClickUserItem(&generator, 1);
258 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo(); 256 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo();
259 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); 257 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1);
260 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId()); 258 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId());
261 // Since the name is capitalized, the email should be different then the 259 // Since the name is capitalized, the email should be different then the
262 // user_id. 260 // user_id.
263 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), 261 EXPECT_NE(active_user->GetAccountId().GetUserEmail(),
264 second_user->GetEmail()); 262 second_user->GetEmail());
265 tray()->CloseSystemBubble(); 263 tray()->CloseSystemBubble();
266 } 264 }
267 265
268 #endif 266 #endif
269 267
270 } // namespace ash 268 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698