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

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

Issue 2111443002: mash: Migrate SessionStateDelegate access to WmShell. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. 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/system/tray/tray_constants.h" 7 #include "ash/common/system/tray/tray_constants.h"
8 #include "ash/common/system/user/tray_user_separator.h" 8 #include "ash/common/system/user/tray_user_separator.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.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/user/tray_user.h" 13 #include "ash/system/user/tray_user.h"
14 #include "ash/system/user/user_view.h" 14 #include "ash/system/user/user_view.h"
15 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/ash_test_helper.h"
16 #include "ash/test/test_session_state_delegate.h" 17 #include "ash/test/test_session_state_delegate.h"
17 #include "ash/test/test_shell_delegate.h" 18 #include "ash/test/test_shell_delegate.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 "components/user_manager/user_info.h"
21 #include "ui/accessibility/ax_view_state.h" 22 #include "ui/accessibility/ax_view_state.h"
22 #include "ui/events/test/event_generator.h" 23 #include "ui/events/test/event_generator.h"
23 #include "ui/gfx/animation/animation_container_element.h" 24 #include "ui/gfx/animation/animation_container_element.h"
24 #include "ui/views/view.h" 25 #include "ui/views/view.h"
25 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
26 27
27 namespace ash { 28 namespace ash {
28 29
29 class TrayUserTest : public ash::test::AshTestBase { 30 class TrayUserTest : public test::AshTestBase {
30 public: 31 public:
31 TrayUserTest() = default; 32 TrayUserTest() = default;
32 33
33 // testing::Test: 34 // testing::Test:
34 void SetUp() override; 35 void SetUp() override;
35 36
36 // This has to be called prior to first use with the proper configuration. 37 // This has to be called prior to first use with the proper configuration.
37 void InitializeParameters(int users_logged_in, bool multiprofile); 38 void InitializeParameters(int users_logged_in, bool multiprofile);
38 39
39 // Show the system tray menu using the provided event generator. 40 // Show the system tray menu using the provided event generator.
40 void ShowTrayMenu(ui::test::EventGenerator* generator); 41 void ShowTrayMenu(ui::test::EventGenerator* generator);
41 42
42 // Move the mouse over the user item. 43 // Move the mouse over the user item.
43 void MoveOverUserItem(ui::test::EventGenerator* generator, int index); 44 void MoveOverUserItem(ui::test::EventGenerator* generator, int index);
44 45
45 // Click on the user item. Note that the tray menu needs to be shown. 46 // Click on the user item. Note that the tray menu needs to be shown.
46 void ClickUserItem(ui::test::EventGenerator* generator, int index); 47 void ClickUserItem(ui::test::EventGenerator* generator, int index);
47 48
48 // Accessors to various system components. 49 // Accessors to various system components.
49 SystemTray* tray() { return tray_; } 50 SystemTray* tray() { return tray_; }
50 ash::test::TestSessionStateDelegate* delegate() { return delegate_; } 51 test::TestSessionStateDelegate* delegate() { return delegate_; }
51 ash::TrayUser* tray_user(int index) { return tray_user_[index]; } 52 TrayUser* tray_user(int index) { return tray_user_[index]; }
52 ash::TrayUserSeparator* tray_user_separator() { return tray_user_separator_; } 53 TrayUserSeparator* tray_user_separator() { return tray_user_separator_; }
53 54
54 private: 55 private:
55 SystemTray* tray_ = nullptr; 56 SystemTray* tray_ = nullptr;
56 ash::test::TestSessionStateDelegate* delegate_ = nullptr; 57 test::TestSessionStateDelegate* delegate_ = nullptr;
57 58
58 // Note that the ownership of these items is on the shelf. 59 // Note that the ownership of these items is on the shelf.
59 std::vector<ash::TrayUser*> tray_user_; 60 std::vector<TrayUser*> tray_user_;
60 61
61 // The separator between the tray users and the rest of the menu. 62 // The separator between the tray users and the rest of the menu.
62 // Note: The item will get owned by the shelf. 63 // Note: The item will get owned by the shelf.
63 TrayUserSeparator* tray_user_separator_ = nullptr; 64 TrayUserSeparator* tray_user_separator_ = nullptr;
64 65
65 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); 66 DISALLOW_COPY_AND_ASSIGN(TrayUserTest);
66 }; 67 };
67 68
68 void TrayUserTest::SetUp() { 69 void TrayUserTest::SetUp() {
69 ash::test::AshTestBase::SetUp(); 70 test::AshTestBase::SetUp();
70 tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray(); 71 tray_ = Shell::GetPrimaryRootWindowController()->GetSystemTray();
71 delegate_ = static_cast<ash::test::TestSessionStateDelegate*>( 72 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate();
72 ash::Shell::GetInstance()->session_state_delegate());
73 } 73 }
74 74
75 void TrayUserTest::InitializeParameters(int users_logged_in, 75 void TrayUserTest::InitializeParameters(int users_logged_in,
76 bool multiprofile) { 76 bool multiprofile) {
77 // Set our default assumptions. Note that it is sufficient to set these 77 // Set our default assumptions. Note that it is sufficient to set these
78 // after everything was created. 78 // after everything was created.
79 delegate_->set_logged_in_users(users_logged_in); 79 delegate_->set_logged_in_users(users_logged_in);
80 ash::test::TestShellDelegate* shell_delegate = 80 test::TestShellDelegate* shell_delegate =
81 static_cast<ash::test::TestShellDelegate*>( 81 static_cast<test::TestShellDelegate*>(Shell::GetInstance()->delegate());
82 ash::Shell::GetInstance()->delegate());
83 shell_delegate->set_multi_profiles_enabled(multiprofile); 82 shell_delegate->set_multi_profiles_enabled(multiprofile);
84 83
85 // Instead of using the existing tray panels we create new ones which makes 84 // Instead of using the existing tray panels we create new ones which makes
86 // the access easier. 85 // the access easier.
87 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { 86 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) {
88 tray_user_.push_back(new ash::TrayUser(tray_, i)); 87 tray_user_.push_back(new TrayUser(tray_, i));
89 tray_->AddTrayItem(tray_user_[i]); 88 tray_->AddTrayItem(tray_user_[i]);
90 } 89 }
91 // We then add also the separator. 90 // We then add also the separator.
92 tray_user_separator_ = new ash::TrayUserSeparator(tray_); 91 tray_user_separator_ = new TrayUserSeparator(tray_);
93 tray_->AddTrayItem(tray_user_separator_); 92 tray_->AddTrayItem(tray_user_separator_);
94 } 93 }
95 94
96 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { 95 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) {
97 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); 96 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint();
98 97
99 generator->MoveMouseTo(center.x(), center.y()); 98 generator->MoveMouseTo(center.x(), center.y());
100 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 99 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
101 generator->ClickLeftButton(); 100 generator->ClickLeftButton();
102 } 101 }
(...skipping 27 matching lines...) Expand all
130 // separators are being created. 129 // separators are being created.
131 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { 130 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) {
132 InitializeParameters(1, false); 131 InitializeParameters(1, false);
133 132
134 // Move the mouse over the status area and click to open the status menu. 133 // Move the mouse over the status area and click to open the status menu.
135 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 134 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
136 135
137 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 136 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
138 137
139 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 138 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
140 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 139 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
141 EXPECT_FALSE(tray_user_separator()->separator_shown()); 140 EXPECT_FALSE(tray_user_separator()->separator_shown());
142 141
143 ShowTrayMenu(&generator); 142 ShowTrayMenu(&generator);
144 143
145 EXPECT_TRUE(tray()->HasSystemBubble()); 144 EXPECT_TRUE(tray()->HasSystemBubble());
146 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); 145 EXPECT_TRUE(tray()->IsAnyBubbleVisible());
147 146
148 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 147 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
149 EXPECT_EQ(i == 0 ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, 148 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN,
150 tray_user(i)->GetStateForTest()); 149 tray_user(i)->GetStateForTest());
151 EXPECT_FALSE(tray_user_separator()->separator_shown()); 150 EXPECT_FALSE(tray_user_separator()->separator_shown());
152 tray()->CloseSystemBubble(); 151 tray()->CloseSystemBubble();
153 } 152 }
154 153
155 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { 154 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) {
156 InitializeParameters(1, false); 155 InitializeParameters(1, false);
157 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 156 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
158 ShowTrayMenu(&generator); 157 ShowTrayMenu(&generator);
159 158
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 EXPECT_FALSE(tray_user(i)->GetStateForTest()); 205 EXPECT_FALSE(tray_user(i)->GetStateForTest());
207 EXPECT_FALSE(tray_user_separator()->separator_shown()); 206 EXPECT_FALSE(tray_user_separator()->separator_shown());
208 // After clicking on the tray the menu should get shown and for each logged 207 // After clicking on the tray the menu should get shown and for each logged
209 // in user we should get a visible item. In addition, the separator should 208 // in user we should get a visible item. In addition, the separator should
210 // show up when we reach more then one user. 209 // show up when we reach more then one user.
211 ShowTrayMenu(&generator); 210 ShowTrayMenu(&generator);
212 211
213 EXPECT_TRUE(tray()->HasSystemBubble()); 212 EXPECT_TRUE(tray()->HasSystemBubble());
214 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); 213 EXPECT_TRUE(tray()->IsAnyBubbleVisible());
215 for (int i = 0; i < max_users; i++) { 214 for (int i = 0; i < max_users; i++) {
216 EXPECT_EQ(i < j ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, 215 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN,
217 tray_user(i)->GetStateForTest()); 216 tray_user(i)->GetStateForTest());
218 } 217 }
219 218
220 // Check the visibility of the separator. 219 // Check the visibility of the separator.
221 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); 220 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown());
222 221
223 // Move the mouse over the user item and it should hover. 222 // Move the mouse over the user item and it should hover.
224 MoveOverUserItem(&generator, 0); 223 MoveOverUserItem(&generator, 0);
225 EXPECT_EQ(ash::TrayUser::HOVERED, tray_user(0)->GetStateForTest()); 224 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest());
226 for (int i = 1; i < max_users; i++) { 225 for (int i = 1; i < max_users; i++) {
227 EXPECT_EQ(i < j ? ash::TrayUser::SHOWN : ash::TrayUser::HIDDEN, 226 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN,
228 tray_user(i)->GetStateForTest()); 227 tray_user(i)->GetStateForTest());
229 } 228 }
230 229
231 // Check that clicking the button allows to add item if we have still room 230 // Check that clicking the button allows to add item if we have still room
232 // for one more user. 231 // for one more user.
233 ClickUserItem(&generator, 0); 232 ClickUserItem(&generator, 0);
234 EXPECT_EQ(j == max_users ? ash::TrayUser::ACTIVE_BUT_DISABLED 233 EXPECT_EQ(j == max_users ? TrayUser::ACTIVE_BUT_DISABLED : TrayUser::ACTIVE,
235 : ash::TrayUser::ACTIVE,
236 tray_user(0)->GetStateForTest()); 234 tray_user(0)->GetStateForTest());
237 235
238 // Click the button again to see that the menu goes away. 236 // Click the button again to see that the menu goes away.
239 ClickUserItem(&generator, 0); 237 ClickUserItem(&generator, 0);
240 EXPECT_EQ(ash::TrayUser::HOVERED, tray_user(0)->GetStateForTest()); 238 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest());
241 239
242 // Close and check that everything is deleted. 240 // Close and check that everything is deleted.
243 tray()->CloseSystemBubble(); 241 tray()->CloseSystemBubble();
244 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); 242 EXPECT_FALSE(tray()->IsAnyBubbleVisible());
245 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) 243 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++)
246 EXPECT_EQ(ash::TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); 244 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest());
247 } 245 }
248 } 246 }
249 247
250 // Make sure that user changing gets properly executed. 248 // Make sure that user changing gets properly executed.
251 TEST_F(TrayUserTest, MutiUserModeButtonClicks) { 249 TEST_F(TrayUserTest, MutiUserModeButtonClicks) {
252 // Have two users. 250 // Have two users.
253 InitializeParameters(2, true); 251 InitializeParameters(2, true);
254 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); 252 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow());
255 ShowTrayMenu(&generator); 253 ShowTrayMenu(&generator);
256 254
257 // Switch to a new user - which has a capitalized name. 255 // Switch to a new user - which has a capitalized name.
258 ClickUserItem(&generator, 1); 256 ClickUserItem(&generator, 1);
259 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo(); 257 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo();
260 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); 258 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1);
261 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId()); 259 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId());
262 // Since the name is capitalized, the email should be different then the 260 // Since the name is capitalized, the email should be different then the
263 // user_id. 261 // user_id.
264 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), 262 EXPECT_NE(active_user->GetAccountId().GetUserEmail(),
265 second_user->GetEmail()); 263 second_user->GetEmail());
266 tray()->CloseSystemBubble(); 264 tray()->CloseSystemBubble();
267 } 265 }
268 266
269 #endif 267 #endif
270 268
271 } // namespace ash 269 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698