- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / managed / tray_locally_managed_user_unittest.cc
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 namespace internal {
20
21 class TrayLocallyManagedUserTest : public test::AshTestBase {
22  public:
23   TrayLocallyManagedUserTest() {}
24   virtual ~TrayLocallyManagedUserTest() {}
25
26  protected:
27   message_center::Notification* GetPopup();
28
29  private:
30   DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserTest);
31 };
32
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)
39       return *iter;
40   }
41   return NULL;
42 }
43
44 class TrayLocallyManagedUserInitialTest : public TrayLocallyManagedUserTest {
45  public:
46   TrayLocallyManagedUserInitialTest() {}
47   virtual ~TrayLocallyManagedUserInitialTest() {}
48
49   virtual void SetUp() OVERRIDE;
50   virtual void TearDown() OVERRIDE;
51
52  private:
53   DISALLOW_COPY_AND_ASSIGN(TrayLocallyManagedUserInitialTest);
54 };
55
56 void TrayLocallyManagedUserInitialTest::SetUp() {
57   test::TestSystemTrayDelegate::SetInitialLoginStatus(
58       user::LOGGED_IN_LOCALLY_MANAGED);
59   test::AshTestBase::SetUp();
60 }
61
62 void TrayLocallyManagedUserInitialTest::TearDown() {
63   test::AshTestBase::TearDown();
64   // SetInitialLoginStatus() is reset in AshTestHelper::TearDown().
65 }
66
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);
72
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);
77 }
78
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);
86 }
87
88 }  // namespace test
89 }  // namespace