| 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" |
| 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/tray_user_separator.h" | 12 #include "ash/common/system/user/tray_user_separator.h" |
| 12 #include "ash/common/system/user/user_view.h" | 13 #include "ash/common/system/user/user_view.h" |
| 13 #include "ash/common/test/test_session_state_delegate.h" | 14 #include "ash/common/test/test_session_state_delegate.h" |
| 14 #include "ash/common/wm_shell.h" | 15 #include "ash/common/wm_shell.h" |
| 15 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/test/ash_test_helper.h" | 17 #include "ash/test/ash_test_helper.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_node_data.h" | 22 #include "ui/accessibility/ax_node_data.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 |
| 30 namespace { |
| 31 |
| 32 bool UseMd() { |
| 33 return MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 34 } |
| 35 |
| 29 class TrayUserTest : public test::AshTestBase { | 36 class TrayUserTest : public test::AshTestBase { |
| 30 public: | 37 public: |
| 31 TrayUserTest() = default; | 38 TrayUserTest() = default; |
| 32 | 39 |
| 33 // testing::Test: | 40 // testing::Test: |
| 34 void SetUp() override; | 41 void SetUp() override; |
| 35 | 42 |
| 36 // This has to be called prior to first use with the proper configuration. | 43 // This has to be called prior to first use with the proper configuration. |
| 37 void InitializeParameters(int users_logged_in, bool multiprofile); | 44 void InitializeParameters(int users_logged_in, bool multiprofile); |
| 38 | 45 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 TrayUserSeparator* tray_user_separator() { return tray_user_separator_; } | 59 TrayUserSeparator* tray_user_separator() { return tray_user_separator_; } |
| 53 | 60 |
| 54 private: | 61 private: |
| 55 SystemTray* tray_ = nullptr; | 62 SystemTray* tray_ = nullptr; |
| 56 test::TestSessionStateDelegate* delegate_ = nullptr; | 63 test::TestSessionStateDelegate* delegate_ = nullptr; |
| 57 | 64 |
| 58 // Note that the ownership of these items is on the shelf. | 65 // Note that the ownership of these items is on the shelf. |
| 59 std::vector<TrayUser*> tray_user_; | 66 std::vector<TrayUser*> tray_user_; |
| 60 | 67 |
| 61 // The separator between the tray users and the rest of the menu. | 68 // The separator between the tray users and the rest of the menu. |
| 62 // Note: The item will get owned by the shelf. | 69 // Note: The item will get owned by the shelf. Not used in Material Design. |
| 63 TrayUserSeparator* tray_user_separator_ = nullptr; | 70 TrayUserSeparator* tray_user_separator_ = nullptr; |
| 64 | 71 |
| 65 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); | 72 DISALLOW_COPY_AND_ASSIGN(TrayUserTest); |
| 66 }; | 73 }; |
| 67 | 74 |
| 68 void TrayUserTest::SetUp() { | 75 void TrayUserTest::SetUp() { |
| 69 test::AshTestBase::SetUp(); | 76 test::AshTestBase::SetUp(); |
| 70 tray_ = GetPrimarySystemTray(); | 77 tray_ = GetPrimarySystemTray(); |
| 71 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate(); | 78 delegate_ = test::AshTestHelper::GetTestSessionStateDelegate(); |
| 72 } | 79 } |
| 73 | 80 |
| 74 void TrayUserTest::InitializeParameters(int users_logged_in, | 81 void TrayUserTest::InitializeParameters(int users_logged_in, |
| 75 bool multiprofile) { | 82 bool multiprofile) { |
| 76 // Set our default assumptions. Note that it is sufficient to set these | 83 // Set our default assumptions. Note that it is sufficient to set these |
| 77 // after everything was created. | 84 // after everything was created. |
| 78 delegate_->set_logged_in_users(users_logged_in); | 85 delegate_->set_logged_in_users(users_logged_in); |
| 79 test::TestShellDelegate* shell_delegate = | 86 test::TestShellDelegate* shell_delegate = |
| 80 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); | 87 static_cast<test::TestShellDelegate*>(WmShell::Get()->delegate()); |
| 81 shell_delegate->set_multi_profiles_enabled(multiprofile); | 88 shell_delegate->set_multi_profiles_enabled(multiprofile); |
| 82 | 89 |
| 83 // Instead of using the existing tray panels we create new ones which makes | 90 // Instead of using the existing tray panels we create new ones which makes |
| 84 // the access easier. | 91 // the access easier. |
| 85 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { | 92 for (int i = 0; i < delegate_->GetMaximumNumberOfLoggedInUsers(); i++) { |
| 86 tray_user_.push_back(new TrayUser(tray_, i)); | 93 tray_user_.push_back(new TrayUser(tray_, i)); |
| 87 tray_->AddTrayItem(tray_user_[i]); | 94 tray_->AddTrayItem(tray_user_[i]); |
| 88 } | 95 } |
| 89 // We then add also the separator. | 96 if (!UseMd()) { |
| 90 tray_user_separator_ = new TrayUserSeparator(tray_); | 97 // We then add also the separator. |
| 91 tray_->AddTrayItem(tray_user_separator_); | 98 tray_user_separator_ = new TrayUserSeparator(tray_); |
| 99 tray_->AddTrayItem(tray_user_separator_); |
| 100 } |
| 92 } | 101 } |
| 93 | 102 |
| 94 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { | 103 void TrayUserTest::ShowTrayMenu(ui::test::EventGenerator* generator) { |
| 95 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); | 104 gfx::Point center = tray()->GetBoundsInScreen().CenterPoint(); |
| 96 | 105 |
| 97 generator->MoveMouseTo(center.x(), center.y()); | 106 generator->MoveMouseTo(center.x(), center.y()); |
| 98 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 107 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
| 99 generator->ClickLeftButton(); | 108 generator->ClickLeftButton(); |
| 100 } | 109 } |
| 101 | 110 |
| 102 void TrayUserTest::MoveOverUserItem(ui::test::EventGenerator* generator, | 111 void TrayUserTest::MoveOverUserItem(ui::test::EventGenerator* generator, |
| 103 int index) { | 112 int index) { |
| 104 gfx::Point center = | 113 gfx::Point center = |
| 105 tray_user(index)->GetUserPanelBoundsInScreenForTest().CenterPoint(); | 114 tray_user(index)->GetUserPanelBoundsInScreenForTest().CenterPoint(); |
| 106 | 115 |
| 107 generator->MoveMouseTo(center.x(), center.y()); | 116 generator->MoveMouseTo(center.x(), center.y()); |
| 108 } | 117 } |
| 109 | 118 |
| 110 void TrayUserTest::ClickUserItem(ui::test::EventGenerator* generator, | 119 void TrayUserTest::ClickUserItem(ui::test::EventGenerator* generator, |
| 111 int index) { | 120 int index) { |
| 112 MoveOverUserItem(generator, index); | 121 MoveOverUserItem(generator, index); |
| 113 generator->ClickLeftButton(); | 122 generator->ClickLeftButton(); |
| 114 } | 123 } |
| 115 | 124 |
| 125 } // namespace |
| 126 |
| 116 // Make sure that we show items for all users in the tray accordingly. | 127 // Make sure that we show items for all users in the tray accordingly. |
| 117 TEST_F(TrayUserTest, CheckTrayItemSize) { | 128 TEST_F(TrayUserTest, CheckTrayItemSize) { |
| 118 InitializeParameters(1, false); | 129 InitializeParameters(1, false); |
| 119 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::GUEST); | 130 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::GUEST); |
| 120 gfx::Size size = tray_user(0)->GetLayoutSizeForTest(); | 131 gfx::Size size = tray_user(0)->GetLayoutSizeForTest(); |
| 121 EXPECT_EQ(kTrayItemSize, size.height()); | 132 EXPECT_EQ(kTrayItemSize, size.height()); |
| 122 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::USER); | 133 tray_user(0)->UpdateAfterLoginStatusChangeForTest(LoginStatus::USER); |
| 123 size = tray_user(0)->GetLayoutSizeForTest(); | 134 size = tray_user(0)->GetLayoutSizeForTest(); |
| 124 EXPECT_EQ(kTrayItemSize, size.height()); | 135 EXPECT_EQ(kTrayItemSize, size.height()); |
| 125 } | 136 } |
| 126 | 137 |
| 127 // Make sure that in single user mode the user panel cannot be activated and no | 138 // Make sure that in single user mode the user panel cannot be activated and no |
| 128 // separators are being created. | 139 // separators are being created. |
| 129 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { | 140 TEST_F(TrayUserTest, SingleUserModeDoesNotAllowAddingUser) { |
| 130 InitializeParameters(1, false); | 141 InitializeParameters(1, false); |
| 131 | 142 |
| 132 // Move the mouse over the status area and click to open the status menu. | 143 // Move the mouse over the status area and click to open the status menu. |
| 133 ui::test::EventGenerator& generator = GetEventGenerator(); | 144 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 134 | 145 |
| 135 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 146 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
| 136 | 147 |
| 137 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 148 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 138 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); | 149 EXPECT_EQ(TrayUser::HIDDEN, tray_user(i)->GetStateForTest()); |
| 139 EXPECT_FALSE(tray_user_separator()->separator_shown()); | 150 if (!UseMd()) |
| 151 EXPECT_FALSE(tray_user_separator()->separator_shown()); |
| 140 | 152 |
| 141 ShowTrayMenu(&generator); | 153 ShowTrayMenu(&generator); |
| 142 | 154 |
| 143 EXPECT_TRUE(tray()->HasSystemBubble()); | 155 EXPECT_TRUE(tray()->HasSystemBubble()); |
| 144 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); | 156 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); |
| 145 | 157 |
| 146 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) | 158 for (int i = 0; i < delegate()->GetMaximumNumberOfLoggedInUsers(); i++) |
| 147 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, | 159 EXPECT_EQ(i == 0 ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 148 tray_user(i)->GetStateForTest()); | 160 tray_user(i)->GetStateForTest()); |
| 149 EXPECT_FALSE(tray_user_separator()->separator_shown()); | 161 if (!UseMd()) |
| 162 EXPECT_FALSE(tray_user_separator()->separator_shown()); |
| 150 tray()->CloseSystemBubble(); | 163 tray()->CloseSystemBubble(); |
| 151 } | 164 } |
| 152 | 165 |
| 153 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { | 166 TEST_F(TrayUserTest, AccessibleLabelContainsSingleUserInfo) { |
| 154 InitializeParameters(1, false); | 167 InitializeParameters(1, false); |
| 155 ui::test::EventGenerator& generator = GetEventGenerator(); | 168 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 156 ShowTrayMenu(&generator); | 169 ShowTrayMenu(&generator); |
| 157 | 170 |
| 158 views::View* view = | 171 views::View* view = |
| 159 tray_user(0)->user_view_for_test()->user_card_view_for_test(); | 172 tray_user(0)->user_view_for_test()->user_card_view_for_test(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); | 208 int max_users = delegate()->GetMaximumNumberOfLoggedInUsers(); |
| 196 // Checking now for each amount of users that the correct is done. | 209 // Checking now for each amount of users that the correct is done. |
| 197 for (int j = 1; j < max_users; j++) { | 210 for (int j = 1; j < max_users; j++) { |
| 198 // Set the number of logged in users. | 211 // Set the number of logged in users. |
| 199 delegate()->set_logged_in_users(j); | 212 delegate()->set_logged_in_users(j); |
| 200 | 213 |
| 201 // Verify that nothing is shown. | 214 // Verify that nothing is shown. |
| 202 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); | 215 EXPECT_FALSE(tray()->IsAnyBubbleVisible()); |
| 203 for (int i = 0; i < max_users; i++) | 216 for (int i = 0; i < max_users; i++) |
| 204 EXPECT_FALSE(tray_user(i)->GetStateForTest()); | 217 EXPECT_FALSE(tray_user(i)->GetStateForTest()); |
| 205 EXPECT_FALSE(tray_user_separator()->separator_shown()); | 218 if (!UseMd()) |
| 219 EXPECT_FALSE(tray_user_separator()->separator_shown()); |
| 206 // After clicking on the tray the menu should get shown and for each logged | 220 // After clicking on the tray the menu should get shown and for each logged |
| 207 // in user we should get a visible item. In addition, the separator should | 221 // in user we should get a visible item. In addition, the separator should |
| 208 // show up when we reach more than one user. | 222 // show up when we reach more than one user. |
| 209 ShowTrayMenu(&generator); | 223 ShowTrayMenu(&generator); |
| 210 | 224 |
| 211 EXPECT_TRUE(tray()->HasSystemBubble()); | 225 EXPECT_TRUE(tray()->HasSystemBubble()); |
| 212 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); | 226 EXPECT_TRUE(tray()->IsAnyBubbleVisible()); |
| 213 for (int i = 0; i < max_users; i++) { | 227 for (int i = 0; i < max_users; i++) { |
| 214 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, | 228 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 215 tray_user(i)->GetStateForTest()); | 229 tray_user(i)->GetStateForTest()); |
| 216 } | 230 } |
| 217 | 231 |
| 218 // Check the visibility of the separator. | 232 // Check the visibility of the separator. |
| 219 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); | 233 if (!UseMd()) |
| 234 EXPECT_EQ(j > 1 ? true : false, tray_user_separator()->separator_shown()); |
| 220 | 235 |
| 221 // Move the mouse over the user item and it should hover. | 236 // Move the mouse over the user item and it should hover. |
| 222 MoveOverUserItem(&generator, 0); | 237 MoveOverUserItem(&generator, 0); |
| 223 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); | 238 EXPECT_EQ(TrayUser::HOVERED, tray_user(0)->GetStateForTest()); |
| 224 for (int i = 1; i < max_users; i++) { | 239 for (int i = 1; i < max_users; i++) { |
| 225 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, | 240 EXPECT_EQ(i < j ? TrayUser::SHOWN : TrayUser::HIDDEN, |
| 226 tray_user(i)->GetStateForTest()); | 241 tray_user(i)->GetStateForTest()); |
| 227 } | 242 } |
| 228 | 243 |
| 229 // Check that clicking the button allows to add item if we have still room | 244 // Check that clicking the button allows to add item if we have still room |
| (...skipping 30 matching lines...) Expand all Loading... |
| 260 // Since the name is capitalized, the email should be different than the | 275 // Since the name is capitalized, the email should be different than the |
| 261 // user_id. | 276 // user_id. |
| 262 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), | 277 EXPECT_NE(active_user->GetAccountId().GetUserEmail(), |
| 263 second_user->GetDisplayEmail()); | 278 second_user->GetDisplayEmail()); |
| 264 tray()->CloseSystemBubble(); | 279 tray()->CloseSystemBubble(); |
| 265 } | 280 } |
| 266 | 281 |
| 267 #endif | 282 #endif |
| 268 | 283 |
| 269 } // namespace ash | 284 } // namespace ash |
| OLD | NEW |