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
3 // found in the LICENSE file.
5 #include "ash/system/chromeos/managed/tray_locally_managed_user.h"
8 #include "ash/system/user/login_status.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/test_system_tray_delegate.h"
11 #include "ui/message_center/message_center.h"
12 #include "ui/message_center/notification.h"
13 #include "ui/message_center/notification_list.h"
14 #include "ui/message_center/notification_types.h"
16 using message_center::NotificationList;
21 class TrayLocallyManagedUserTest : public test::AshTestBase {
23 TrayLocallyManagedUserTest() {}
24 virtual ~TrayLocallyManagedUserTest() {}
27 message_center::Notification* GetPopup();
30 DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserTest);
33 message_center::Notification* TrayLocallyManagedUserTest::GetPopup() {
34 NotificationList::PopupNotifications popups =
35 message_center::MessageCenter::Get()->GetPopupNotifications();
36 for (NotificationList::PopupNotifications::const_iterator iter =
37 popups.begin(); iter != popups.end(); ++iter) {
38 if ((*iter)->id() == TrayLocallyManagedUser::kNotificationId)
44 class TrayLocallyManagedUserInitialTest : public TrayLocallyManagedUserTest {
46 TrayLocallyManagedUserInitialTest() {}
47 virtual ~TrayLocallyManagedUserInitialTest() {}
49 virtual void SetUp() OVERRIDE;
50 virtual void TearDown() OVERRIDE;
53 DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserInitialTest);
56 void TrayLocallyManagedUserInitialTest::SetUp() {
57 test::TestSystemTrayDelegate::SetInitialLoginStatus(
58 user::LOGGED_IN_LOCALLY_MANAGED);
59 test::AshTestBase::SetUp();
62 void TrayLocallyManagedUserInitialTest::TearDown() {
63 test::AshTestBase::TearDown();
64 // SetInitialLoginStatus() is reset in AshTestHelper::TearDown().
67 TEST_F(TrayLocallyManagedUserTest, LocallyManagedUserHasNotification) {
68 test::TestSystemTrayDelegate* delegate =
69 static_cast<test::TestSystemTrayDelegate*>(
70 ash::Shell::GetInstance()->system_tray_delegate());
71 delegate->SetLoginStatus(user::LOGGED_IN_LOCALLY_MANAGED);
73 message_center::Notification* notification = GetPopup();
74 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification);
75 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY),
76 notification->rich_notification_data().priority);
79 TEST_F(TrayLocallyManagedUserInitialTest, LocallyManagedUserNoCrash) {
80 // Initial login status is already LOCALLY_MANAGED, which should create
81 // the notification and should not cause crashes.
82 message_center::Notification* notification = GetPopup();
83 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification);
84 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY),
85 notification->rich_notification_data().priority);