Chromium Code Reviews| 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/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 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 42 void ShowTrayMenu(ui::test::EventGenerator* generator); | 42 void ShowTrayMenu(ui::test::EventGenerator* generator); |
| 43 | 43 |
| 44 // Move the mouse over the user item. | 44 // Move the mouse over the user item. |
| 45 void MoveOverUserItem(ui::test::EventGenerator* generator, int index); | 45 void MoveOverUserItem(ui::test::EventGenerator* generator, int index); |
| 46 | 46 |
| 47 // Click on the user item. Note that the tray menu needs to be shown. | 47 // Click on the user item. Note that the tray menu needs to be shown. |
| 48 void ClickUserItem(ui::test::EventGenerator* generator, int index); | 48 void ClickUserItem(ui::test::EventGenerator* generator, int index); |
| 49 | 49 |
| 50 // Accessors to various system components. | 50 // Accessors to various system components. |
| 51 SystemTray* tray() { return tray_; } | 51 SystemTray* tray() { return tray_; } |
| 52 test::TestSessionStateDelegate* delegate() { return delegate_; } | 52 SessionController* controller() { |
| 53 return WmShell::Get()->session_controller(); | |
| 54 } | |
| 53 TrayUser* tray_user(int index) { return tray_user_[index]; } | 55 TrayUser* tray_user(int index) { return tray_user_[index]; } |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 SystemTray* tray_ = nullptr; | 58 SystemTray* tray_ = nullptr; |
| 57 test::TestSessionStateDelegate* delegate_ = nullptr; | |
| 58 | 59 |
| 59 // Note that the ownership of these items is on the shelf. | 60 // Note that the ownership of these items is on the shelf. |
| 60 std::vector<TrayUser*> tray_user_; | 61 std::vector<TrayUser*> tray_user_; |
| 61 | 62 |
| 62 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); | 63 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); |
| 63 }; | 64 }; |
| 64 | 65 |
| 65 void TrayUserTest::SetUp() { | 66 void TrayUserTest::SetUp() { |
| 66 test::AshTestBase::SetUp(); | 67 test::AshTestBase::SetUp(); |
| 67 tray_ = GetPrimarySystemTray(); | 68 tray_ = GetPrimarySystemTray(); |
| 68 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate(); | |
| 69 } | 69 } |
| 70 | 70 |
| 71 void TrayUserTest::InitializeParameters(int users_logged_in, | 71 void TrayUserTest::InitializeParameters(int users_logged_in, |
| 72 bool multiprofile) { | 72 bool multiprofile) { |
| 73 // Set our default assumptions. Note that it is sufficient to set these | 73 // Set our default assumptions. Note that it is sufficient to set these |
| 74 // after everything was created. | 74 // after everything was created. |
| 75 delegate_->set_logged_in_users(users_logged_in); | 75 GetSessionControllerClient()->SetPredefinedUserSessions(users_logged_in); |
| 76 test::TestShellDelegate* shell_delegate = | 76 test::TestShellDelegate* shell_delegate = |
| 77 static_cast<test::TestShellDelegate*>(Shell::Get()->shell_delegate()); | 77 static_cast<test::TestShellDelegate*>(Shell::Get()->shell_delegate()); |
| 78 shell_delegate->set_multi_profiles_enabled(multiprofile); | 78 shell_delegate->set_multi_profiles_enabled(multiprofile); |
| 79 | 79 |
| 80 // Instead of using the existing tray panels we create new ones which makes | 80 // Instead of using the existing tray panels we create new ones which makes |
| 81 // the access easier. | 81 // the access easier. |
| 82 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { | 82 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++) { |
| 83 tray_user_.push_back(new TrayUser(tray_, i)); | 83 tray_user_.push_back(new TrayUser(tray_, i)); |
| 84 tray_->AddTrayItem(base::WrapUnique(tray_user_[i])); | 84 tray_->AddTrayItem(base::WrapUnique(tray_user_[i])); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { | 88 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { |
| 89 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); | 89 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); |
| 90 | 90 |
| 91 generator->MoveMouseTo(center.x(), center.y()); | 91 generator->MoveMouseTo(center.x(), center.y()); |
| 92 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); | 92 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 122 | 122 |
| 123 // Make sure that in single user mode the user panel cannot be activated. | 123 // Make sure that in single user mode the user panel cannot be activated. |
| 124 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { | 124 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { |
| 125 InitializeParameters(1, false); | 125 InitializeParameters(1, false); |
| 126 | 126 |
| 127 // Move the mouse over the status area and click to open the status menu. | 127 // Move the mouse over the status area and click to open the status menu. |
| 128 ui::test::EventGenerator& generator = GetEventGenerator(); | 128 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 129 | 129 |
| 130 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); | 130 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); |
| 131 | 131 |
| 132 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 132 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 133 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); | 133 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); |
| 134 | 134 |
| 135 ShowTrayMenu(&generator); | 135 ShowTrayMenu(&generator); |
| 136 | 136 |
| 137 EXPECT_TRUE(tray()->HasSystemBubble()); | 137 EXPECT_TRUE(tray()->HasSystemBubble()); |
| 138 EXPECT_TRUE(tray()->IsSystemBubbleVisible()); | 138 EXPECT_TRUE(tray()->IsSystemBubbleVisible()); |
| 139 | 139 |
| 140 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 140 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 141 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, | 141 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 142 tray_user(i)->GetStateForTest()); | 142 tray_user(i)->GetStateForTest()); |
| 143 tray()->CloseSystemBubble(); | 143 tray()->CloseSystemBubble(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { | 146 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { |
| 147 InitializeParameters(1, false); | 147 InitializeParameters(1, false); |
| 148 ui::test::EventGenerator& generator = GetEventGenerator(); | 148 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 149 ShowTrayMenu(&generator); | 149 ShowTrayMenu(&generator); |
| 150 | 150 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 177 // will be one panel for each user. | 177 // will be one panel for each user. |
| 178 // Note: the mouse watcher (for automatic closing upon leave) cannot be tested | 178 // 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. | 179 // here since it does not work with the event system in unit tests. |
| 180 TEST_F(TrayUserTest, MultiUserModeDoesNotAllowToAddUser) { | 180 TEST_F(TrayUserTest, MultiUserModeDoesNotAllowToAddUser) { |
| 181 InitializeParameters(1, true); | 181 InitializeParameters(1, true); |
| 182 | 182 |
| 183 // Move the mouse over the status area and click to open the status menu. | 183 // Move the mouse over the status area and click to open the status menu. |
| 184 ui::test::EventGenerator& generator = GetEventGenerator(); | 184 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 185 generator.set_async(false); | 185 generator.set_async(false); |
| 186 | 186 |
| 187 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); | 187 int max_users = controller()->GetMaximumNumberOfLoggedInUsers(); |
| 188 // Checking now for each amount of users that the correct is done. | 188 // Checking now for each amount of users that the correct is done. |
| 189 for (int j = 1; j < max_users; j++) { | 189 for (int j = 1; j < max_users; j++) { |
| 190 // Set the number of logged in users. | 190 // Set the number of logged in users. |
| 191 delegate()->set_logged_in_users(j); | 191 GetSessionControllerClient()->SetPredefinedUserSessions(j); |
| 192 | 192 |
| 193 // Verify that nothing is shown. | 193 // Verify that nothing is shown. |
| 194 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); | 194 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); |
| 195 for (int i = 0; i < max_users; i++) | 195 for (int i = 0; i < max_users; i++) |
| 196 EXPECT_FALSE(tray_user(i)->GetStateForTest()); | 196 EXPECT_FALSE(tray_user(i)->GetStateForTest()); |
| 197 // After clicking on the tray the menu should get shown and for each logged | 197 // After clicking on the tray the menu should get shown and for each logged |
| 198 // in user we should get a visible item. | 198 // in user we should get a visible item. |
| 199 ShowTrayMenu(&generator); | 199 ShowTrayMenu(&generator); |
| 200 | 200 |
| 201 EXPECT_TRUE(tray()->HasSystemBubble()); | 201 EXPECT_TRUE(tray()->HasSystemBubble()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 220 tray_user(0)->GetStateForTest()); | 220 tray_user(0)->GetStateForTest()); |
| 221 | 221 |
| 222 // Click the button again to see that the menu goes away. | 222 // Click the button again to see that the menu goes away. |
| 223 ClickUserItem(&generator, 0); | 223 ClickUserItem(&generator, 0); |
| 224 MoveOverUserItem(&generator, 0); | 224 MoveOverUserItem(&generator, 0); |
| 225 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); | 225 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); |
| 226 | 226 |
| 227 // Close and check that everything is deleted. | 227 // Close and check that everything is deleted. |
| 228 tray()->CloseSystemBubble(); | 228 tray()->CloseSystemBubble(); |
| 229 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); | 229 EXPECT_FALSE(tray()->IsSystemBubbleVisible()); |
| 230 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 230 for (int i = 0; i < controller()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 231 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); | 231 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| 235 // Make sure that user changing gets properly executed. | 235 // Make sure that user changing gets properly executed. |
| 236 TEST_F(TrayUserTest, MultiUserModeButtonClicks) { | 236 TEST_F(TrayUserTest, MultiUserModeButtonClicks) { |
| 237 // Have two users. | 237 // Have two users. |
| 238 InitializeParameters(2, true); | 238 InitializeParameters(2, true); |
| 239 ui::test::EventGenerator& generator = GetEventGenerator(); | 239 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 240 ShowTrayMenu(&generator); | 240 ShowTrayMenu(&generator); |
| 241 | 241 |
| 242 // Switch to a new user - which has a capitalized name. | 242 // Gets the second user before user switching. |
| 243 const mojom::UserSession* second_user = controller()->GetUserSession(1); | |
|
xiyuan
2017/03/17 07:08:15
This has to be changed because the old code depend
| |
| 244 | |
| 245 // Switch to a new user "Second@tray" - which has a capitalized name. | |
|
James Cook
2017/03/17 17:14:35
For stuff like this could we provide a setter in T
xiyuan
2017/03/17 22:52:02
Make sense. Moved the predefined users from TestSe
| |
| 243 ClickUserItem(&generator, 1); | 246 ClickUserItem(&generator, 1); |
| 244 const user_manager::UserInfo* active_user = delegate()->GetActiveUserInfo(); | 247 |
| 245 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); | 248 // SwitchActiverUser is an async mojo call. Spin the loop to let it finish. |
| 246 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId()); | 249 RunAllPendingInMessageLoop(); |
| 250 | |
| 251 const mojom::UserSession* active_user = controller()->GetUserSession(0); | |
| 252 EXPECT_EQ(active_user->account_id, second_user->account_id); | |
| 247 // Since the name is capitalized, the email should be different than the | 253 // Since the name is capitalized, the email should be different than the |
| 248 // user_id. | 254 // user_id. |
| 249 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), | 255 EXPECT_NE(active_user->account_id.GetUserEmail(), second_user->display_email); |
| 250 second_user->GetDisplayEmail()); | |
| 251 tray()->CloseSystemBubble(); | 256 tray()->CloseSystemBubble(); |
| 252 } | 257 } |
| 253 | 258 |
| 254 } // namespace ash | 259 } // namespace ash |
| OLD | NEW |