OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ash/system/chromeos/managed/tray_locally_managed_user.h" | |
6 | |
7 #include "ash/shell.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" | |
15 | |
16 using message_center::NotificationList; | |
17 | |
18 namespace ash { | |
19 | |
20 class TrayLocallyManagedUserTest : public test::AshTestBase { | |
21 public: | |
22 TrayLocallyManagedUserTest() {} | |
23 virtual ~TrayLocallyManagedUserTest() {} | |
24 | |
25 protected: | |
26 message_center::Notification* GetPopup(); | |
27 | |
28 private: | |
29 DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserTest); | |
30 }; | |
31 | |
32 message_center::Notification* TrayLocallyManagedUserTest::GetPopup() { | |
33 NotificationList::PopupNotifications popups = | |
34 message_center::MessageCenter::Get()->GetPopupNotifications(); | |
35 for (NotificationList::PopupNotifications::const_iterator iter = | |
36 popups.begin(); iter != popups.end(); ++iter) { | |
37 if ((*iter)->id() == TrayLocallyManagedUser::kNotificationId) | |
38 return *iter; | |
39 } | |
40 return NULL; | |
41 } | |
42 | |
43 class TrayLocallyManagedUserInitialTest : public TrayLocallyManagedUserTest { | |
44 public: | |
45 TrayLocallyManagedUserInitialTest() {} | |
46 virtual ~TrayLocallyManagedUserInitialTest() {} | |
47 | |
48 virtual void SetUp() OVERRIDE; | |
49 virtual void TearDown() OVERRIDE; | |
50 | |
51 private: | |
52 DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserInitialTest); | |
53 }; | |
54 | |
55 void TrayLocallyManagedUserInitialTest::SetUp() { | |
56 test::TestSystemTrayDelegate::SetInitialLoginStatus( | |
57 user::LOGGED_IN_LOCALLY_MANAGED); | |
58 test::AshTestBase::SetUp(); | |
59 } | |
60 | |
61 void TrayLocallyManagedUserInitialTest::TearDown() { | |
62 test::AshTestBase::TearDown(); | |
63 // SetInitialLoginStatus() is reset in AshTestHelper::TearDown(). | |
64 } | |
65 | |
66 TEST_F(TrayLocallyManagedUserTest, LocallyManagedUserHasNotification) { | |
67 test::TestSystemTrayDelegate* delegate = | |
68 static_cast<test::TestSystemTrayDelegate*>( | |
69 ash::Shell::GetInstance()->system_tray_delegate()); | |
70 delegate->SetLoginStatus(user::LOGGED_IN_LOCALLY_MANAGED); | |
71 | |
72 message_center::Notification* notification = GetPopup(); | |
73 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); | |
74 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), | |
75 notification->rich_notification_data().priority); | |
76 } | |
77 | |
78 TEST_F(TrayLocallyManagedUserInitialTest, LocallyManagedUserNoCrash) { | |
79 // Initial login status is already LOCALLY_MANAGED, which should create | |
80 // the notification and should not cause crashes. | |
81 message_center::Notification* notification = GetPopup(); | |
82 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); | |
83 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), | |
84 notification->rich_notification_data().priority); | |
85 } | |
86 | |
87 } // namespace | |
OLD | NEW |