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

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

Issue 2832903002: cros: Remove supervised user methods from SystemTrayDelegate (Closed)
Patch Set: ready 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/session/session_controller.h" 8 #include "ash/session/session_controller.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/tray/label_tray_view.h"
11 #include "ash/system/tray/system_tray.h"
10 #include "ash/test/ash_test_base.h" 12 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_session_controller_client.h" 13 #include "ash/test/test_session_controller_client.h"
12 #include "ash/test/test_system_tray_delegate.h" 14 #include "ash/test/test_system_tray_delegate.h"
15 #include "base/memory/ptr_util.h"
16 #include "base/strings/utf_string_conversions.h"
13 #include "ui/message_center/message_center.h" 17 #include "ui/message_center/message_center.h"
14 #include "ui/message_center/notification.h" 18 #include "ui/message_center/notification.h"
15 #include "ui/message_center/notification_list.h" 19 #include "ui/message_center/notification_list.h"
16 #include "ui/message_center/notification_types.h" 20 #include "ui/message_center/notification_types.h"
21 #include "ui/views/view.h"
17 22
18 using message_center::NotificationList; 23 using message_center::NotificationList;
19 24
20 namespace ash { 25 namespace ash {
21 26
22 // Tests handle creating their own sessions. 27 // Tests handle creating their own sessions.
23 class TraySupervisedUserTest : public test::NoSessionAshTestBase { 28 class TraySupervisedUserTest : public test::NoSessionAshTestBase {
24 public: 29 public:
25 TraySupervisedUserTest() {} 30 TraySupervisedUserTest() {}
26 ~TraySupervisedUserTest() override {} 31 ~TraySupervisedUserTest() override {}
(...skipping 20 matching lines...) Expand all
47 // Verifies that when a supervised user logs in that a warning notification is 52 // Verifies that when a supervised user logs in that a warning notification is
48 // shown and ash does not crash. 53 // shown and ash does not crash.
49 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { 54 TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) {
50 SessionController* session = Shell::Get()->session_controller(); 55 SessionController* session = Shell::Get()->session_controller();
51 ASSERT_EQ(LoginStatus::NOT_LOGGED_IN, session->login_status()); 56 ASSERT_EQ(LoginStatus::NOT_LOGGED_IN, session->login_status());
52 ASSERT_FALSE(session->IsActiveUserSessionStarted()); 57 ASSERT_FALSE(session->IsActiveUserSessionStarted());
53 58
54 // Simulate a supervised user logging in. 59 // Simulate a supervised user logging in.
55 test::TestSessionControllerClient* client = GetSessionControllerClient(); 60 test::TestSessionControllerClient* client = GetSessionControllerClient();
56 client->Reset(); 61 client->Reset();
57 client->AddUserSession("user1@test.com", user_manager::USER_TYPE_SUPERVISED); 62 client->AddUserSession("child@test.com", user_manager::USER_TYPE_SUPERVISED);
58 client->SetSessionState(session_manager::SessionState::ACTIVE); 63 client->SetSessionState(session_manager::SessionState::ACTIVE);
59 64
65 // No notification because custodian email not available yet.
60 message_center::Notification* notification = GetPopup(); 66 message_center::Notification* notification = GetPopup();
61 ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); 67 EXPECT_FALSE(notification);
68
69 // Update the user session with the custodian data (which happens after the
70 // profile loads).
71 mojom::UserSessionPtr user_session = session->GetUserSession(0)->Clone();
72 user_session->custodian_email = "parent1@test.com";
73 session->UpdateUserSession(std::move(user_session));
74
75 // Notification is shown.
76 notification = GetPopup();
77 ASSERT_TRUE(notification);
62 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), 78 EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY),
63 notification->rich_notification_data().priority); 79 notification->rich_notification_data().priority);
80 EXPECT_EQ(
81 "Usage and history of this user can be reviewed by the manager "
82 "(parent1@test.com) on chrome.com.",
83 UTF16ToUTF8(notification->message()));
84
85 // Update the user session with new custodian data.
86 user_session = session->GetUserSession(0)->Clone();
87 user_session->custodian_email = "parent2@test.com";
88 session->UpdateUserSession(std::move(user_session));
89
90 // Notification is shown with updated message.
91 notification = GetPopup();
92 ASSERT_TRUE(notification);
93 EXPECT_EQ(
94 "Usage and history of this user can be reviewed by the manager "
95 "(parent2@test.com) on chrome.com.",
96 UTF16ToUTF8(notification->message()));
97 }
98
99 // Verifies an item is created for a supervised user.
100 TEST_F(TraySupervisedUserTest, CreateDefaultView) {
101 TraySupervisedUser* tray =
102 GetPrimarySystemTray()->GetTraySupervisedUserForTesting();
103 SessionController* session = Shell::Get()->session_controller();
104 ASSERT_FALSE(session->IsActiveUserSessionStarted());
105
106 // Before login there is no supervised user item.
107 const LoginStatus unused = LoginStatus::NOT_LOGGED_IN;
108 EXPECT_FALSE(tray->CreateDefaultView(unused));
109
110 // Simulate a supervised user logging in.
111 test::TestSessionControllerClient* client = GetSessionControllerClient();
112 client->Reset();
113 client->AddUserSession("child@test.com", user_manager::USER_TYPE_SUPERVISED);
114 client->SetSessionState(session_manager::SessionState::ACTIVE);
115 mojom::UserSessionPtr user_session = session->GetUserSession(0)->Clone();
116 user_session->custodian_email = "parent@test.com";
117 session->UpdateUserSession(std::move(user_session));
118
119 // Now there is a supervised user item.
120 std::unique_ptr<views::View> view =
121 base::WrapUnique(tray->CreateDefaultView(unused));
122 ASSERT_TRUE(view);
123 EXPECT_EQ(
124 "Usage and history of this user can be reviewed by the manager "
125 "(parent@test.com) on chrome.com.",
126 UTF16ToUTF8(static_cast<LabelTrayView*>(view.get())->message()));
64 } 127 }
65 128
66 } // namespace ash 129 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698