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

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

Issue 2734933004: ash: Use SessionController instead of SessionStateDelegate (Closed)
Patch Set: rebase to get WorkspaceLayoutManagerSoloTest change Created 3 years, 9 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/common/system/user/tray_user.cc ('k') | ash/common/system/user/user_card_view.cc » ('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 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/session/session_controller.h"
7 #include "ash/common/shell_delegate.h" 8 #include "ash/common/shell_delegate.h"
8 #include "ash/common/system/tray/system_tray.h" 9 #include "ash/common/system/tray/system_tray.h"
9 #include "ash/common/system/tray/tray_constants.h" 10 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/user/tray_user.h" 11 #include "ash/common/system/user/tray_user.h"
11 #include "ash/common/system/user/user_view.h" 12 #include "ash/common/system/user/user_view.h"
12 #include "ash/common/test/test_session_state_delegate.h" 13 #include "ash/common/test/test_session_controller_client.h"
14 #include "ash/common/wm_shell.h"
13 #include "ash/shell.h" 15 #include "ash/shell.h"
14 #include "ash/test/ash_test_base.h" 16 #include "ash/test/ash_test_base.h"
15 #include "ash/test/ash_test_helper.h"
16 #include "ash/test/test_shell_delegate.h" 17 #include "ash/test/test_shell_delegate.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "components/signin/core/account_id/account_id.h" 20 #include "components/signin/core/account_id/account_id.h"
20 #include "components/user_manager/user_info.h"
21 #include "ui/accessibility/ax_node_data.h" 21 #include "ui/accessibility/ax_node_data.h"
22 #include "ui/events/test/event_generator.h" 22 #include "ui/events/test/event_generator.h"
23 #include "ui/gfx/animation/animation_container_element.h" 23 #include "ui/gfx/animation/animation_container_element.h"
24 #include "ui/views/view.h" 24 #include "ui/views/view.h"
25 #include "ui/views/widget/widget.h" 25 #include "ui/views/widget/widget.h"
26 26
27 namespace ash { 27 namespace ash {
28 28
29 namespace { 29 namespace {
30 30
31 const char* kPredefinedUserEmails[] = {
32 // This is intended to be capitalized.
33 "First@tray",
34 // This is intended to be capitalized.
35 "Second@tray"};
36
31 class TrayUserTest : public test::AshTestBase { 37 class TrayUserTest : public test::AshTestBase {
32 public: 38 public:
33 TrayUserTest() = default; 39 TrayUserTest() = default;
34 40
35 // testing::Test: 41 // testing::Test:
36 void SetUp() override; 42 void SetUp() override;
37 43
38 // This has to be called prior to first use with the proper configuration. 44 // This has to be called prior to first use with the proper configuration.
39 void InitializeParameters(int users_logged_in, bool multiprofile); 45 void InitializeParameters(int users_logged_in, bool multiprofile);
40 46
41 // Show the system tray menu using the provided event generator. 47 // Show the system tray menu using the provided event generator.
42 void ShowTrayMenu(ui::test::EventGenerator* generator); 48 void ShowTrayMenu(ui::test::EventGenerator* generator);
43 49
44 // Move the mouse over the user item. 50 // Move the mouse over the user item.
45 void MoveOverUserItem(ui::test::EventGenerator* generator, int index); 51 void MoveOverUserItem(ui::test::EventGenerator* generator, int index);
46 52
47 // Click on the user item. Note that the tray menu needs to be shown. 53 // Click on the user item. Note that the tray menu needs to be shown.
48 void ClickUserItem(ui::test::EventGenerator* generator, int index); 54 void ClickUserItem(ui::test::EventGenerator* generator, int index);
49 55
50 // Accessors to various system components. 56 // Accessors to various system components.
51 SystemTray* tray() { return tray_; } 57 SystemTray* tray() { return tray_; }
52 test::TestSessionStateDelegate* delegate() { return delegate_; } 58 SessionController* controller() {
59 return WmShell::Get()->session_controller();
60 }
53 TrayUser* tray_user(int index) { return tray_user_[index]; } 61 TrayUser* tray_user(int index) { return tray_user_[index]; }
54 62
55 private: 63 private:
56 SystemTray* tray_ = nullptr; 64 SystemTray* tray_ = nullptr;
57 test::TestSessionStateDelegate* delegate_ = nullptr;
58 65
59 // Note that the ownership of these items is on the shelf. 66 // Note that the ownership of these items is on the shelf.
60 std::vector<TrayUser*> tray_user_; 67 std::vector<TrayUser*> tray_user_;
61 68
62 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); 69 DISALLOW_COPY_AND_ASSIGN(TrayUserTest);
63 }; 70 };
64 71
65 void TrayUserTest::SetUp() { 72 void TrayUserTest::SetUp() {
66 test::AshTestBase::SetUp(); 73 test::AshTestBase::SetUp();
67 tray_ = GetPrimarySystemTray(); 74 tray_ = GetPrimarySystemTray();
68 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate();
69 } 75 }
70 76
71 void TrayUserTest::InitializeParameters(int users_logged_in, 77 void TrayUserTest::InitializeParameters(int users_logged_in,
72 bool multiprofile) { 78 bool multiprofile) {
73 // Set our default assumptions. Note that it is sufficient to set these 79 // Set our default assumptions. Note that it is sufficient to set these
74 // after everything was created. 80 // after everything was created.
75 delegate_->set_logged_in_users(users_logged_in); 81 GetSessionControllerClient()->Reset();
82 ASSERT_LE(users_logged_in,
83 static_cast<int>(arraysize(kPredefinedUserEmails)));
84 for (int i = 0; i < users_logged_in; ++i)
85 GetSessionControllerClient()->AddUserSession(kPredefinedUserEmails[i]);
86 GetSessionControllerClient()->SetSessionState(
87 session_manager::SessionState::ACTIVE);
88
76 test::TestShellDelegate* shell_delegate = 89 test::TestShellDelegate* shell_delegate =
77 static_cast<test::TestShellDelegate*>(Shell::Get()->shell_delegate()); 90 static_cast<test::TestShellDelegate*>(Shell::Get()->shell_delegate());
78 shell_delegate->set_multi_profiles_enabled(multiprofile); 91 shell_delegate->set_multi_profiles_enabled(multiprofile);
79 92
80 // Instead of using the existing tray panels we create new ones which makes 93 // Instead of using the existing tray panels we create new ones which makes
81 // the access easier. 94 // the access easier.
82 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { 95 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++) {
83 tray_user_.push_back(new TrayUser(tray_, i)); 96 tray_user_.push_back(new TrayUser(tray_, i));
84 tray_->AddTrayItem(base::WrapUnique(tray_user_[i])); 97 tray_->AddTrayItem(base::WrapUnique(tray_user_[i]));
85 } 98 }
86 } 99 }
87 100
88 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { 101 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) {
89 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); 102 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint();
90 103
91 generator->MoveMouseTo(center.x(), center.y()); 104 generator->MoveMouseTo(center.x(), center.y());
92 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); 105 EXPECT_FALSE(tray()->IsSystemBubbleVisible());
(...skipping 29 matching lines...) Expand all
122 135
123 // Make sure that in single user mode the user panel cannot be activated. 136 // Make sure that in single user mode the user panel cannot be activated.
124 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { 137 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) {
125 InitializeParameters(1, false); 138 InitializeParameters(1, false);
126 139
127 // Move the mouse over the status area and click to open the status menu. 140 // Move the mouse over the status area and click to open the status menu.
128 ui::test::EventGenerator& generator = GetEventGenerator(); 141 ui::test::EventGenerator& generator = GetEventGenerator();
129 142
130 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); 143 EXPECT_FALSE(tray()->IsSystemBubbleVisible());
131 144
132 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 145 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++)
133 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 146 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
134 147
135 ShowTrayMenu(&generator); 148 ShowTrayMenu(&generator);
136 149
137 EXPECT_TRUE(tray()->HasSystemBubble()); 150 EXPECT_TRUE(tray()->HasSystemBubble());
138 EXPECT_TRUE(tray()->IsSystemBubbleVisible()); 151 EXPECT_TRUE(tray()->IsSystemBubbleVisible());
139 152
140 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 153 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++)
141 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, 154 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN,
142 tray_user(i)->GetStateForTest()); 155 tray_user(i)->GetStateForTest());
143 tray()->CloseSystemBubble(); 156 tray()->CloseSystemBubble();
144 } 157 }
145 158
146 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { 159 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) {
147 InitializeParameters(1, false); 160 InitializeParameters(1, false);
148 ui::test::EventGenerator& generator = GetEventGenerator(); 161 ui::test::EventGenerator& generator = GetEventGenerator();
149 ShowTrayMenu(&generator); 162 ShowTrayMenu(&generator);
150 163
(...skipping 26 matching lines...) Expand all
177 // will be one panel for each user. 190 // will be one panel for each user.
178 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested 191 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested
179 // here since it does not work with the event system in unit tests. 192 // here since it does not work with the event system in unit tests.
180 TEST_F(TrayUserTest, MultiUserModeDoesNotAllowToAddUser) { 193 TEST_F(TrayUserTest, MultiUserModeDoesNotAllowToAddUser) {
181 InitializeParameters(1, true); 194 InitializeParameters(1, true);
182 195
183 // Move the mouse over the status area and click to open the status menu. 196 // Move the mouse over the status area and click to open the status menu.
184 ui::test::EventGenerator& generator = GetEventGenerator(); 197 ui::test::EventGenerator& generator = GetEventGenerator();
185 generator.set_async(false); 198 generator.set_async(false);
186 199
187 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); 200 int max_users = controller()->GetMaximumNumberOfLoggedInUsers();
188 // Checking now for each amount of users that the correct is done. 201 // Checking now for each amount of users that the correct is done.
189 for (int j = 1; j < max_users; j++) { 202 for (int j = 1; j < max_users; j++) {
190 // Set the number of logged in users. 203 // Set the number of logged in users.
191 delegate()->set_logged_in_users(j); 204 GetSessionControllerClient()->CreatePredefinedUserSessions(j);
192 205
193 // Verify that nothing is shown. 206 // Verify that nothing is shown.
194 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); 207 EXPECT_FALSE(tray()->IsSystemBubbleVisible());
195 for (int i = 0; i < max_users; i++) 208 for (int i = 0; i < max_users; i++)
196 EXPECT_FALSE(tray_user(i)->GetStateForTest()); 209 EXPECT_FALSE(tray_user(i)->GetStateForTest());
197 // After clicking on the tray the menu should get shown and for each logged 210 // After clicking on the tray the menu should get shown and for each logged
198 // in user we should get a visible item. 211 // in user we should get a visible item.
199 ShowTrayMenu(&generator); 212 ShowTrayMenu(&generator);
200 213
201 EXPECT_TRUE(tray()->HasSystemBubble()); 214 EXPECT_TRUE(tray()->HasSystemBubble());
(...skipping 18 matching lines...) Expand all
220 tray_user(0)->GetStateForTest()); 233 tray_user(0)->GetStateForTest());
221 234
222 // Click the button again to see that the menu goes away. 235 // Click the button again to see that the menu goes away.
223 ClickUserItem(&generator, 0); 236 ClickUserItem(&generator, 0);
224 MoveOverUserItem(&generator, 0); 237 MoveOverUserItem(&generator, 0);
225 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); 238 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest());
226 239
227 // Close and check that everything is deleted. 240 // Close and check that everything is deleted.
228 tray()->CloseSystemBubble(); 241 tray()->CloseSystemBubble();
229 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); 242 EXPECT_FALSE(tray()->IsSystemBubbleVisible());
230 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 243 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++)
231 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 244 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
232 } 245 }
233 } 246 }
234 247
235 // Make sure that user changing gets properly executed. 248 // Make sure that user changing gets properly executed.
236 TEST_F(TrayUserTest, MultiUserModeButtonClicks) { 249 TEST_F(TrayUserTest, MultiUserModeButtonClicks) {
237 // Have two users. 250 // Have two users.
238 InitializeParameters(2, true); 251 InitializeParameters(2, true);
239 ui::test::EventGenerator& generator = GetEventGenerator(); 252 ui::test::EventGenerator& generator = GetEventGenerator();
240 ShowTrayMenu(&generator); 253 ShowTrayMenu(&generator);
241 254
242 // Switch to a new user - which has a capitalized name. 255 // Gets the second user before user switching.
256 const mojom::UserSession* second_user = controller()->GetUserSession(1);
257
258 // Switch to a new user "Second@tray" - which has a capitalized name.
243 ClickUserItem(&generator, 1); 259 ClickUserItem(&generator, 1);
244 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo(); 260
245 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); 261 // SwitchActiverUser is an async mojo call. Spin the loop to let it finish.
246 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId()); 262 RunAllPendingInMessageLoop();
263
264 const mojom::UserSession* active_user = controller()->GetUserSession(0);
265 EXPECT_EQ(active_user->account_id, second_user->account_id);
247 // Since the name is capitalized, the email should be different than the 266 // Since the name is capitalized, the email should be different than the
248 // user_id. 267 // user_id.
249 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), 268 EXPECT_NE(active_user->account_id.GetUserEmail(), second_user->display_email);
250 second_user->GetDisplayEmail());
251 tray()->CloseSystemBubble(); 269 tray()->CloseSystemBubble();
252 } 270 }
253 271
254 } // namespace ash 272 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/user/tray_user.cc ('k') | ash/common/system/user/user_card_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698