Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: ash/system/supervised/tray_supervised_user_unittest.cc

Issue 2829813002: cros: Move IsUserSupervised and IsUserChild off SystemTrayDelegate (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/public/interfaces/session_controller.mojom.h"
9 #include "ash/session/session_controller.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/test_session_controller_client.h"
9 #include "ash/test/test_system_tray_delegate.h" 13 #include "ash/test/test_system_tray_delegate.h"
10 #include "ui/message_center/message_center.h" 14 #include "ui/message_center/message_center.h"
11 #include "ui/message_center/notification.h" 15 #include "ui/message_center/notification.h"
12 #include "ui/message_center/notification_list.h" 16 #include "ui/message_center/notification_list.h"
13 #include "ui/message_center/notification_types.h" 17 #include "ui/message_center/notification_types.h"
14 18
15 using message_center::NotificationList; 19 using message_center::NotificationList;
16 20
17 namespace ash { 21 namespace ash {
18 22
19 class TraySupervisedUserTest : public AshTest { 23 // Tests handle creating their own sessions.
24 class TraySupervisedUserTest : public test::NoSessionAshTestBase {
20 public: 25 public:
21 TraySupervisedUserTest() {} 26 TraySupervisedUserTest() {}
22 ~TraySupervisedUserTest() override {} 27 ~TraySupervisedUserTest() override {}
23 28
24 protected: 29 protected:
25 message_center::Notification* GetPopup(); 30 message_center::Notification* GetPopup();
26 31
27 private: 32 private:
28 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest); 33 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest);
29 }; 34 };
30 35
31 message_center::Notification* TraySupervisedUserTest::GetPopup() { 36 message_center::Notification* TraySupervisedUserTest::GetPopup() {
32 NotificationList::PopupNotifications popups = 37 NotificationList::PopupNotifications popups =
33 message_center::MessageCenter::Get()->GetPopupNotifications(); 38 message_center::MessageCenter::Get()->GetPopupNotifications();
34 for (NotificationList::PopupNotifications::const_iterator iter = 39 for (NotificationList::PopupNotifications::const_iterator iter =
35 popups.begin(); 40 popups.begin();
36 iter != popups.end(); ++iter) { 41 iter != popups.end(); ++iter) {
37 if ((*iter)->id() == TraySupervisedUser::kNotificationId) 42 if ((*iter)->id() == TraySupervisedUser::kNotificationId)
38 return *iter; 43 return *iter;
39 } 44 }
40 return NULL; 45 return NULL;
41 } 46 }
42 47
43 class TraySupervisedUserInitialTest : public TraySupervisedUserTest { 48 // Verifies that when a supervised user logs in that a warning notification is
44 public: 49 // shown and ash does not crash.
45 // Set the initial login status to supervised-user before AshTest::SetUp() 50 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) {
46 // constructs the system tray. 51 ASSERT_EQ(LoginStatus::NOT_LOGGED_IN,
47 TraySupervisedUserInitialTest() 52 GetSystemTrayDelegate()->GetUserLoginStatus());
xiyuan 2017/04/19 20:58:00 I would vote to merge GetUserLoginStatus with the
James Cook 2017/04/19 22:16:37 I think that's a good idea, but we need to elimina
48 : scoped_initial_login_status_(LoginStatus::SUPERVISED) {} 53 ASSERT_FALSE(
49 ~TraySupervisedUserInitialTest() override {} 54 Shell::Get()->session_controller()->IsActiveUserSessionStarted());
50 55
51 private: 56 // Simulate a supervised user logging in.
52 test::ScopedInitialLoginStatus scoped_initial_login_status_; 57 test::TestSessionControllerClient* client = GetSessionControllerClient();
53 58 client->Reset();
54 DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserInitialTest); 59 mojom::UserSessionPtr session = mojom::UserSession::New();
55 }; 60 session->session_id = 1;
56 61 session->type = user_manager::USER_TYPE_SUPERVISED;
57 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { 62 Shell::Get()->session_controller()->UpdateUserSession(std::move(session));
xiyuan 2017/04/19 20:58:00 Make TestSessionControllerClient::AddUserSession t
James Cook 2017/04/19 22:16:37 Done.
58 test::TestSystemTrayDelegate* delegate = GetSystemTrayDelegate(); 63 client->SetSessionState(session_manager::SessionState::ACTIVE);
59 delegate->SetLoginStatus(LoginStatus::SUPERVISED);
60 64
61 message_center::Notification* notification = GetPopup(); 65 message_center::Notification* notification = GetPopup();
62 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); 66 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification);
63 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), 67 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); 68 notification->rich_notification_data().priority);
74 } 69 }
75 70
76 } // namespace ash 71 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698