| 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/common/system/chromeos/supervised/tray_supervised_user.h" | 5 #include "ash/common/system/chromeos/supervised/tray_supervised_user.h" |
| 6 | 6 |
| 7 #include "ash/common/login_status.h" | 7 #include "ash/common/login_status.h" |
| 8 #include "ash/common/test/ash_test.h" |
| 8 #include "ash/common/test/test_system_tray_delegate.h" | 9 #include "ash/common/test/test_system_tray_delegate.h" |
| 9 #include "ash/test/ash_test_base.h" | |
| 10 #include "ui/message_center/message_center.h" | 10 #include "ui/message_center/message_center.h" |
| 11 #include "ui/message_center/notification.h" | 11 #include "ui/message_center/notification.h" |
| 12 #include "ui/message_center/notification_list.h" | 12 #include "ui/message_center/notification_list.h" |
| 13 #include "ui/message_center/notification_types.h" | 13 #include "ui/message_center/notification_types.h" |
| 14 | 14 |
| 15 using message_center::NotificationList; | 15 using message_center::NotificationList; |
| 16 | 16 |
| 17 namespace ash { | 17 namespace ash { |
| 18 | 18 |
| 19 class TraySupervisedUserTest : public test::AshTestBase { | 19 class TraySupervisedUserTest : public AshTest { |
| 20 public: | 20 public: |
| 21 TraySupervisedUserTest() {} | 21 TraySupervisedUserTest() {} |
| 22 ~TraySupervisedUserTest() override {} | 22 ~TraySupervisedUserTest() override {} |
| 23 | 23 |
| 24 protected: | 24 protected: |
| 25 message_center::Notification* GetPopup(); | 25 message_center::Notification* GetPopup(); |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest); | 28 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest); |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 message_center::Notification* TraySupervisedUserTest::GetPopup() { | 31 message_center::Notification* TraySupervisedUserTest::GetPopup() { |
| 32 NotificationList::PopupNotifications popups = | 32 NotificationList::PopupNotifications popups = |
| 33 message_center::MessageCenter::Get()->GetPopupNotifications(); | 33 message_center::MessageCenter::Get()->GetPopupNotifications(); |
| 34 for (NotificationList::PopupNotifications::const_iterator iter = | 34 for (NotificationList::PopupNotifications::const_iterator iter = |
| 35 popups.begin(); | 35 popups.begin(); |
| 36 iter != popups.end(); ++iter) { | 36 iter != popups.end(); ++iter) { |
| 37 if ((*iter)->id() == TraySupervisedUser::kNotificationId) | 37 if ((*iter)->id() == TraySupervisedUser::kNotificationId) |
| 38 return *iter; | 38 return *iter; |
| 39 } | 39 } |
| 40 return NULL; | 40 return NULL; |
| 41 } | 41 } |
| 42 | 42 |
| 43 class TraySupervisedUserInitialTest : public TraySupervisedUserTest { | 43 class TraySupervisedUserInitialTest : public TraySupervisedUserTest { |
| 44 public: | 44 public: |
| 45 TraySupervisedUserInitialTest() {} | 45 // Set the initial login status to supervised-user before AshTest::SetUp() |
| 46 // constructs the system tray. |
| 47 TraySupervisedUserInitialTest() |
| 48 : scoped_initial_login_status_(LoginStatus::SUPERVISED) {} |
| 46 ~TraySupervisedUserInitialTest() override {} | 49 ~TraySupervisedUserInitialTest() override {} |
| 47 | 50 |
| 48 void SetUp() override; | 51 private: |
| 49 void TearDown() override; | 52 test::ScopedInitialLoginStatus scoped_initial_login_status_; |
| 50 | 53 |
| 51 private: | |
| 52 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserInitialTest); | 54 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserInitialTest); |
| 53 }; | 55 }; |
| 54 | 56 |
| 55 void TraySupervisedUserInitialTest::SetUp() { | |
| 56 test::TestSystemTrayDelegate::SetInitialLoginStatus(LoginStatus::SUPERVISED); | |
| 57 test::AshTestBase::SetUp(); | |
| 58 } | |
| 59 | |
| 60 void TraySupervisedUserInitialTest::TearDown() { | |
| 61 test::AshTestBase::TearDown(); | |
| 62 // SetInitialLoginStatus() is reset in AshTestHelper::TearDown(). | |
| 63 } | |
| 64 | |
| 65 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { | 57 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { |
| 66 test::TestSystemTrayDelegate* delegate = GetSystemTrayDelegate(); | 58 test::TestSystemTrayDelegate* delegate = GetSystemTrayDelegate(); |
| 67 delegate->SetLoginStatus(LoginStatus::SUPERVISED); | 59 delegate->SetLoginStatus(LoginStatus::SUPERVISED); |
| 68 | 60 |
| 69 message_center::Notification* notification = GetPopup(); | 61 message_center::Notification* notification = GetPopup(); |
| 70 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); | 62 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); |
| 71 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), | 63 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), |
| 72 notification->rich_notification_data().priority); | 64 notification->rich_notification_data().priority); |
| 73 } | 65 } |
| 74 | 66 |
| 75 TEST_F(TraySupervisedUserInitialTest, SupervisedUserNoCrash) { | 67 TEST_F(TraySupervisedUserInitialTest, SupervisedUserNoCrash) { |
| 76 // Initial login status is already SUPERVISED, which should create | 68 // Initial login status is already SUPERVISED, which should create |
| 77 // the notification and should not cause crashes. | 69 // the notification and should not cause crashes. |
| 78 message_center::Notification* notification = GetPopup(); | 70 message_center::Notification* notification = GetPopup(); |
| 79 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); | 71 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); |
| 80 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), | 72 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), |
| 81 notification->rich_notification_data().priority); | 73 notification->rich_notification_data().priority); |
| 82 } | 74 } |
| 83 | 75 |
| 84 } // namespace ash | 76 } // namespace ash |
| OLD | NEW |