| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/system/supervised/tray_supervised_user.h" | 5 #include "ash/system/supervised/tray_supervised_user.h" |
| 6 | 6 |
| 7 #include "ash/login_status.h" | 7 #include "ash/login_status.h" |
| 8 #include "ash/test/ash_test.h" | 8 #include "ash/session/session_controller.h" |
| 9 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/test/test_session_controller_client.h" |
| 9 #include "ash/test/test_system_tray_delegate.h" | 12 #include "ash/test/test_system_tray_delegate.h" |
| 10 #include "ui/message_center/message_center.h" | 13 #include "ui/message_center/message_center.h" |
| 11 #include "ui/message_center/notification.h" | 14 #include "ui/message_center/notification.h" |
| 12 #include "ui/message_center/notification_list.h" | 15 #include "ui/message_center/notification_list.h" |
| 13 #include "ui/message_center/notification_types.h" | 16 #include "ui/message_center/notification_types.h" |
| 14 | 17 |
| 15 using message_center::NotificationList; | 18 using message_center::NotificationList; |
| 16 | 19 |
| 17 namespace ash { | 20 namespace ash { |
| 18 | 21 |
| 19 class TraySupervisedUserTest : public AshTest { | 22 // Tests handle creating their own sessions. |
| 23 class TraySupervisedUserTest : public test::NoSessionAshTestBase { |
| 20 public: | 24 public: |
| 21 TraySupervisedUserTest() {} | 25 TraySupervisedUserTest() {} |
| 22 ~TraySupervisedUserTest() override {} | 26 ~TraySupervisedUserTest() override {} |
| 23 | 27 |
| 24 protected: | 28 protected: |
| 25 message_center::Notification* GetPopup(); | 29 message_center::Notification* GetPopup(); |
| 26 | 30 |
| 27 private: | 31 private: |
| 28 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest); | 32 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest); |
| 29 }; | 33 }; |
| 30 | 34 |
| 31 message_center::Notification* TraySupervisedUserTest::GetPopup() { | 35 message_center::Notification* TraySupervisedUserTest::GetPopup() { |
| 32 NotificationList::PopupNotifications popups = | 36 NotificationList::PopupNotifications popups = |
| 33 message_center::MessageCenter::Get()->GetPopupNotifications(); | 37 message_center::MessageCenter::Get()->GetPopupNotifications(); |
| 34 for (NotificationList::PopupNotifications::const_iterator iter = | 38 for (NotificationList::PopupNotifications::const_iterator iter = |
| 35 popups.begin(); | 39 popups.begin(); |
| 36 iter != popups.end(); ++iter) { | 40 iter != popups.end(); ++iter) { |
| 37 if ((*iter)->id() == TraySupervisedUser::kNotificationId) | 41 if ((*iter)->id() == TraySupervisedUser::kNotificationId) |
| 38 return *iter; | 42 return *iter; |
| 39 } | 43 } |
| 40 return NULL; | 44 return NULL; |
| 41 } | 45 } |
| 42 | 46 |
| 43 class TraySupervisedUserInitialTest : public TraySupervisedUserTest { | 47 // Verifies that when a supervised user logs in that a warning notification is |
| 44 public: | 48 // shown and ash does not crash. |
| 45 // Set the initial login status to supervised-user before AshTest::SetUp() | 49 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { |
| 46 // constructs the system tray. | 50 SessionController* session = Shell::Get()->session_controller(); |
| 47 TraySupervisedUserInitialTest() | 51 ASSERT_EQ(LoginStatus::NOT_LOGGED_IN, session->login_status()); |
| 48 : scoped_initial_login_status_(LoginStatus::SUPERVISED) {} | 52 ASSERT_FALSE(session->IsActiveUserSessionStarted()); |
| 49 ~TraySupervisedUserInitialTest() override {} | |
| 50 | 53 |
| 51 private: | 54 // Simulate a supervised user logging in. |
| 52 test::ScopedInitialLoginStatus scoped_initial_login_status_; | 55 test::TestSessionControllerClient* client = GetSessionControllerClient(); |
| 53 | 56 client->Reset(); |
| 54 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserInitialTest); | 57 client->AddUserSession("user1@test.com", user_manager::USER_TYPE_SUPERVISED); |
| 55 }; | 58 client->SetSessionState(session_manager::SessionState::ACTIVE); |
| 56 | |
| 57 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { | |
| 58 test::TestSystemTrayDelegate* delegate = GetSystemTrayDelegate(); | |
| 59 delegate->SetLoginStatus(LoginStatus::SUPERVISED); | |
| 60 | 59 |
| 61 message_center::Notification* notification = GetPopup(); | 60 message_center::Notification* notification = GetPopup(); |
| 62 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); | 61 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); |
| 63 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), | 62 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), |
| 64 notification->rich_notification_data().priority); | |
| 65 } | |
| 66 | |
| 67 TEST_F(TraySupervisedUserInitialTest, SupervisedUserNoCrash) { | |
| 68 // Initial login status is already SUPERVISED, which should create | |
| 69 // the notification and should not cause crashes. | |
| 70 message_center::Notification* notification = GetPopup(); | |
| 71 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); | |
| 72 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), | |
| 73 notification->rich_notification_data().priority); | 63 notification->rich_notification_data().priority); |
| 74 } | 64 } |
| 75 | 65 |
| 76 } // namespace ash | 66 } // namespace ash |
| OLD | NEW |