| 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/material_design/material_design_controller.h" | |
| 8 #include "ash/common/shell_delegate.h" | 7 #include "ash/common/shell_delegate.h" |
| 9 #include "ash/common/system/tray/system_tray.h" | 8 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 11 #include "ash/common/system/user/tray_user.h" | 10 #include "ash/common/system/user/tray_user.h" |
| 12 #include "ash/common/system/user/tray_user_separator.h" | |
| 13 #include "ash/common/system/user/user_view.h" | 11 #include "ash/common/system/user/user_view.h" |
| 14 #include "ash/common/test/test_session_state_delegate.h" | 12 #include "ash/common/test/test_session_state_delegate.h" |
| 15 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.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_shell_delegate.h" | 16 #include "ash/test/test_shell_delegate.h" |
| 19 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.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_node_data.h" | 21 #include "ui/accessibility/ax_node_data.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" |
| 26 #include "ui/views/view.h" | 24 #include "ui/views/view.h" |
| 27 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
| 28 | 26 |
| 29 namespace ash { | 27 namespace ash { |
| 30 | 28 |
| 31 namespace { | 29 namespace { |
| 32 | 30 |
| 33 bool UseMd() { | |
| 34 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 35 } | |
| 36 | |
| 37 class TrayUserTest : public test::AshTestBase { | 31 class TrayUserTest : public test::AshTestBase { |
| 38 public: | 32 public: |
| 39 TrayUserTest() = default; | 33 TrayUserTest() = default; |
| 40 | 34 |
| 41 // testing::Test: | 35 // testing::Test: |
| 42 void SetUp() override; | 36 void SetUp() override; |
| 43 | 37 |
| 44 // This has to be called prior to first use with the proper configuration. | 38 // This has to be called prior to first use with the proper configuration. |
| 45 void InitializeParameters(int users_logged_in, bool multiprofile); | 39 void InitializeParameters(int users_logged_in, bool multiprofile); |
| 46 | 40 |
| 47 // Show the system tray menu using the provided event generator. | 41 // Show the system tray menu using the provided event generator. |
| 48 void ShowTrayMenu(ui::test::EventGenerator* generator); | 42 void ShowTrayMenu(ui::test::EventGenerator* generator); |
| 49 | 43 |
| 50 // Move the mouse over the user item. | 44 // Move the mouse over the user item. |
| 51 void MoveOverUserItem(ui::test::EventGenerator* generator, int index); | 45 void MoveOverUserItem(ui::test::EventGenerator* generator, int index); |
| 52 | 46 |
| 53 // 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. |
| 54 void ClickUserItem(ui::test::EventGenerator* generator, int index); | 48 void ClickUserItem(ui::test::EventGenerator* generator, int index); |
| 55 | 49 |
| 56 // Accessors to various system components. | 50 // Accessors to various system components. |
| 57 SystemTray* tray() { return tray_; } | 51 SystemTray* tray() { return tray_; } |
| 58 test::TestSessionStateDelegate* delegate() { return delegate_; } | 52 test::TestSessionStateDelegate* delegate() { return delegate_; } |
| 59 TrayUser* tray_user(int index) { return tray_user_[index]; } | 53 TrayUser* tray_user(int index) { return tray_user_[index]; } |
| 60 TrayUserSeparator* tray_user_separator() { return tray_user_separator_; } | |
| 61 | 54 |
| 62 private: | 55 private: |
| 63 SystemTray* tray_ = nullptr; | 56 SystemTray* tray_ = nullptr; |
| 64 test::TestSessionStateDelegate* delegate_ = nullptr; | 57 test::TestSessionStateDelegate* delegate_ = nullptr; |
| 65 | 58 |
| 66 // Note that the ownership of these items is on the shelf. | 59 // Note that the ownership of these items is on the shelf. |
| 67 std::vector<TrayUser*> tray_user_; | 60 std::vector<TrayUser*> tray_user_; |
| 68 | 61 |
| 69 // The separator between the tray users and the rest of the menu. | |
| 70 // Note: The item will get owned by the shelf. Not used in Material Design. | |
| 71 TrayUserSeparator* tray_user_separator_ = nullptr; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); | 62 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); |
| 74 }; | 63 }; |
| 75 | 64 |
| 76 void TrayUserTest::SetUp() { | 65 void TrayUserTest::SetUp() { |
| 77 test::AshTestBase::SetUp(); | 66 test::AshTestBase::SetUp(); |
| 78 tray_ = GetPrimarySystemTray(); | 67 tray_ = GetPrimarySystemTray(); |
| 79 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate(); | 68 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate(); |
| 80 } | 69 } |
| 81 | 70 |
| 82 void TrayUserTest::InitializeParameters(int users_logged_in, | 71 void TrayUserTest::InitializeParameters(int users_logged_in, |
| 83 bool multiprofile) { | 72 bool multiprofile) { |
| 84 // 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 |
| 85 // after everything was created. | 74 // after everything was created. |
| 86 delegate_->set_logged_in_users(users_logged_in); | 75 delegate_->set_logged_in_users(users_logged_in); |
| 87 test::TestShellDelegate* shell_delegate = | 76 test::TestShellDelegate* shell_delegate = |
| 88 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); | 77 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); |
| 89 shell_delegate->set_multi_profiles_enabled(multiprofile); | 78 shell_delegate->set_multi_profiles_enabled(multiprofile); |
| 90 | 79 |
| 91 // 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 |
| 92 // the access easier. | 81 // the access easier. |
| 93 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { | 82 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { |
| 94 tray_user_.push_back(new TrayUser(tray_, i)); | 83 tray_user_.push_back(new TrayUser(tray_, i)); |
| 95 tray_->AddTrayItem(base::WrapUnique(tray_user_[i])); | 84 tray_->AddTrayItem(base::WrapUnique(tray_user_[i])); |
| 96 } | 85 } |
| 97 if (!UseMd()) { | |
| 98 // We then add also the separator. | |
| 99 tray_user_separator_ = new TrayUserSeparator(tray_); | |
| 100 tray_->AddTrayItem(base::WrapUnique(tray_user_separator_)); | |
| 101 } | |
| 102 } | 86 } |
| 103 | 87 |
| 104 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { | 88 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { |
| 105 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); | 89 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); |
| 106 | 90 |
| 107 generator->MoveMouseTo(center.x(), center.y()); | 91 generator->MoveMouseTo(center.x(), center.y()); |
| 108 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 92 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
| 109 generator->ClickLeftButton(); | 93 generator->ClickLeftButton(); |
| 110 } | 94 } |
| 111 | 95 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 129 TEST_F(TrayUserTest, CheckTrayItemSize) { | 113 TEST_F(TrayUserTest, CheckTrayItemSize) { |
| 130 InitializeParameters(1, false); | 114 InitializeParameters(1, false); |
| 131 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::GUEST); | 115 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::GUEST); |
| 132 gfx::Size size = tray_user(0)->GetLayoutSizeForTest(); | 116 gfx::Size size = tray_user(0)->GetLayoutSizeForTest(); |
| 133 EXPECT_EQ(kTrayItemSize, size.height()); | 117 EXPECT_EQ(kTrayItemSize, size.height()); |
| 134 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::USER); | 118 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::USER); |
| 135 size = tray_user(0)->GetLayoutSizeForTest(); | 119 size = tray_user(0)->GetLayoutSizeForTest(); |
| 136 EXPECT_EQ(kTrayItemSize, size.height()); | 120 EXPECT_EQ(kTrayItemSize, size.height()); |
| 137 } | 121 } |
| 138 | 122 |
| 139 // Make sure that in single user mode the user panel cannot be activated and no | 123 // Make sure that in single user mode the user panel cannot be activated. |
| 140 // separators are being created. | |
| 141 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { | 124 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { |
| 142 InitializeParameters(1, false); | 125 InitializeParameters(1, false); |
| 143 | 126 |
| 144 // 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. |
| 145 ui::test::EventGenerator& generator = GetEventGenerator(); | 128 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 146 | 129 |
| 147 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 130 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
| 148 | 131 |
| 149 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 132 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 150 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); | 133 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); |
| 151 if (!UseMd()) | |
| 152 EXPECT_FALSE(tray_user_separator()->separator_shown()); | |
| 153 | 134 |
| 154 ShowTrayMenu(&generator); | 135 ShowTrayMenu(&generator); |
| 155 | 136 |
| 156 EXPECT_TRUE(tray()->HasSystemBubble()); | 137 EXPECT_TRUE(tray()->HasSystemBubble()); |
| 157 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); | 138 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); |
| 158 | 139 |
| 159 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 140 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 160 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, | 141 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 161 tray_user(i)->GetStateForTest()); | 142 tray_user(i)->GetStateForTest()); |
| 162 if (!UseMd()) | |
| 163 EXPECT_FALSE(tray_user_separator()->separator_shown()); | |
| 164 tray()->CloseSystemBubble(); | 143 tray()->CloseSystemBubble(); |
| 165 } | 144 } |
| 166 | 145 |
| 167 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { | 146 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { |
| 168 InitializeParameters(1, false); | 147 InitializeParameters(1, false); |
| 169 ui::test::EventGenerator& generator = GetEventGenerator(); | 148 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 170 ShowTrayMenu(&generator); | 149 ShowTrayMenu(&generator); |
| 171 | 150 |
| 172 views::View* view = | 151 views::View* view = |
| 173 tray_user(0)->user_view_for_test()->user_card_view_for_test(); | 152 tray_user(0)->user_view_for_test()->user_card_view_for_test(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 188 tray_user(0)->user_view_for_test()->user_card_view_for_test(); | 167 tray_user(0)->user_view_for_test()->user_card_view_for_test(); |
| 189 ui::AXNodeData node_data; | 168 ui::AXNodeData node_data; |
| 190 view->GetAccessibleNodeData(&node_data); | 169 view->GetAccessibleNodeData(&node_data); |
| 191 EXPECT_EQ( | 170 EXPECT_EQ( |
| 192 base::UTF8ToUTF16("Über tray Über tray Über tray Über tray First@tray"), | 171 base::UTF8ToUTF16("Über tray Über tray Über tray Über tray First@tray"), |
| 193 node_data.GetString16Attribute(ui::AX_ATTR_NAME)); | 172 node_data.GetString16Attribute(ui::AX_ATTR_NAME)); |
| 194 EXPECT_EQ(ui::AX_ROLE_BUTTON, node_data.role); | 173 EXPECT_EQ(ui::AX_ROLE_BUTTON, node_data.role); |
| 195 } | 174 } |
| 196 | 175 |
| 197 // Make sure that in multi user mode the user panel can be activated and there | 176 // Make sure that in multi user mode the user panel can be activated and there |
| 198 // will be one panel for each user plus one additional separator at the end. | 177 // will be one panel for each user. |
| 199 // 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 |
| 200 // 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. |
| 201 TEST_F(TrayUserTest, MultiUserModeDoesNotAllowToAddUser) { | 180 TEST_F(TrayUserTest, MultiUserModeDoesNotAllowToAddUser) { |
| 202 InitializeParameters(1, true); | 181 InitializeParameters(1, true); |
| 203 | 182 |
| 204 // 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. |
| 205 ui::test::EventGenerator& generator = GetEventGenerator(); | 184 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 206 generator.set_async(false); | 185 generator.set_async(false); |
| 207 | 186 |
| 208 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); | 187 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); |
| 209 // 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. |
| 210 for (int j = 1; j < max_users; j++) { | 189 for (int j = 1; j < max_users; j++) { |
| 211 // Set the number of logged in users. | 190 // Set the number of logged in users. |
| 212 delegate()->set_logged_in_users(j); | 191 delegate()->set_logged_in_users(j); |
| 213 | 192 |
| 214 // Verify that nothing is shown. | 193 // Verify that nothing is shown. |
| 215 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 194 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
| 216 for (int i = 0; i < max_users; i++) | 195 for (int i = 0; i < max_users; i++) |
| 217 EXPECT_FALSE(tray_user(i)->GetStateForTest()); | 196 EXPECT_FALSE(tray_user(i)->GetStateForTest()); |
| 218 if (!UseMd()) | |
| 219 EXPECT_FALSE(tray_user_separator()->separator_shown()); | |
| 220 // 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 |
| 221 // in user we should get a visible item. In addition, the separator should | 198 // in user we should get a visible item. |
| 222 // show up when we reach more than one user. | |
| 223 ShowTrayMenu(&generator); | 199 ShowTrayMenu(&generator); |
| 224 | 200 |
| 225 EXPECT_TRUE(tray()->HasSystemBubble()); | 201 EXPECT_TRUE(tray()->HasSystemBubble()); |
| 226 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); | 202 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); |
| 227 for (int i = 0; i < max_users; i++) { | 203 for (int i = 0; i < max_users; i++) { |
| 228 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, | 204 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 229 tray_user(i)->GetStateForTest()); | 205 tray_user(i)->GetStateForTest()); |
| 230 } | 206 } |
| 231 | 207 |
| 232 // Check the visibility of the separator. | |
| 233 if (!UseMd()) | |
| 234 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); | |
| 235 | |
| 236 // Move the mouse over the user item and it should hover. | 208 // Move the mouse over the user item and it should hover. |
| 237 MoveOverUserItem(&generator, 0); | 209 MoveOverUserItem(&generator, 0); |
| 238 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); | 210 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); |
| 239 for (int i = 1; i < max_users; i++) { | 211 for (int i = 1; i < max_users; i++) { |
| 240 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, | 212 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 241 tray_user(i)->GetStateForTest()); | 213 tray_user(i)->GetStateForTest()); |
| 242 } | 214 } |
| 243 | 215 |
| 244 // Check that clicking the button allows to add item if we have still room | 216 // Check that clicking the button allows to add item if we have still room |
| 245 // for one more user. | 217 // for one more user. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 273 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); | 245 const user_manager::UserInfo* second_user = delegate()->GetUserInfo(1); |
| 274 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId()); | 246 EXPECT_EQ(active_user->GetAccountId(), second_user->GetAccountId()); |
| 275 // Since the name is capitalized, the email should be different than the | 247 // Since the name is capitalized, the email should be different than the |
| 276 // user_id. | 248 // user_id. |
| 277 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), | 249 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), |
| 278 second_user->GetDisplayEmail()); | 250 second_user->GetDisplayEmail()); |
| 279 tray()->CloseSystemBubble(); | 251 tray()->CloseSystemBubble(); |
| 280 } | 252 } |
| 281 | 253 |
| 282 } // namespace ash | 254 } // namespace ash |
| OLD | NEW |