Index: ash/system/supervised/tray_supervised_user_unittest.cc |
diff --git a/ash/system/supervised/tray_supervised_user_unittest.cc b/ash/system/supervised/tray_supervised_user_unittest.cc |
index 37c96c9643477a06981aa42bb6360f7cfa500e9f..6907a05ee513fd58d7031fb7e9a0f7b6ff9be3b8 100644 |
--- a/ash/system/supervised/tray_supervised_user_unittest.cc |
+++ b/ash/system/supervised/tray_supervised_user_unittest.cc |
@@ -7,13 +7,18 @@ |
#include "ash/login_status.h" |
#include "ash/session/session_controller.h" |
#include "ash/shell.h" |
+#include "ash/system/tray/label_tray_view.h" |
+#include "ash/system/tray/system_tray.h" |
#include "ash/test/ash_test_base.h" |
#include "ash/test/test_session_controller_client.h" |
#include "ash/test/test_system_tray_delegate.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/strings/utf_string_conversions.h" |
#include "ui/message_center/message_center.h" |
#include "ui/message_center/notification.h" |
#include "ui/message_center/notification_list.h" |
#include "ui/message_center/notification_types.h" |
+#include "ui/views/view.h" |
using message_center::NotificationList; |
@@ -54,13 +59,71 @@ TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { |
// Simulate a supervised user logging in. |
test::TestSessionControllerClient* client = GetSessionControllerClient(); |
client->Reset(); |
- client->AddUserSession("user1@test.com", user_manager::USER_TYPE_SUPERVISED); |
+ client->AddUserSession("child@test.com", user_manager::USER_TYPE_SUPERVISED); |
client->SetSessionState(session_manager::SessionState::ACTIVE); |
+ // No notification because custodian email not available yet. |
message_center::Notification* notification = GetPopup(); |
- ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); |
+ EXPECT_FALSE(notification); |
+ |
+ // Update the user session with the custodian data (which happens after the |
+ // profile loads). |
+ mojom::UserSessionPtr user_session = session->GetUserSession(0)->Clone(); |
+ user_session->custodian_email = "parent1@test.com"; |
+ session->UpdateUserSession(std::move(user_session)); |
+ |
+ // Notification is shown. |
+ notification = GetPopup(); |
+ ASSERT_TRUE(notification); |
EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), |
notification->rich_notification_data().priority); |
+ EXPECT_EQ( |
+ "Usage and history of this user can be reviewed by the manager " |
+ "(parent1@test.com) on chrome.com.", |
+ UTF16ToUTF8(notification->message())); |
+ |
+ // Update the user session with new custodian data. |
+ user_session = session->GetUserSession(0)->Clone(); |
+ user_session->custodian_email = "parent2@test.com"; |
+ session->UpdateUserSession(std::move(user_session)); |
+ |
+ // Notification is shown with updated message. |
+ notification = GetPopup(); |
+ ASSERT_TRUE(notification); |
+ EXPECT_EQ( |
+ "Usage and history of this user can be reviewed by the manager " |
+ "(parent2@test.com) on chrome.com.", |
+ UTF16ToUTF8(notification->message())); |
+} |
+ |
+// Verifies an item is created for a supervised user. |
+TEST_F(TraySupervisedUserTest, CreateDefaultView) { |
+ TraySupervisedUser* tray = |
+ GetPrimarySystemTray()->GetTraySupervisedUserForTesting(); |
+ SessionController* session = Shell::Get()->session_controller(); |
+ ASSERT_FALSE(session->IsActiveUserSessionStarted()); |
+ |
+ // Before login there is no supervised user item. |
+ const LoginStatus unused = LoginStatus::NOT_LOGGED_IN; |
+ EXPECT_FALSE(tray->CreateDefaultView(unused)); |
+ |
+ // Simulate a supervised user logging in. |
+ test::TestSessionControllerClient* client = GetSessionControllerClient(); |
+ client->Reset(); |
+ client->AddUserSession("child@test.com", user_manager::USER_TYPE_SUPERVISED); |
+ client->SetSessionState(session_manager::SessionState::ACTIVE); |
+ mojom::UserSessionPtr user_session = session->GetUserSession(0)->Clone(); |
+ user_session->custodian_email = "parent@test.com"; |
+ session->UpdateUserSession(std::move(user_session)); |
+ |
+ // Now there is a supervised user item. |
+ std::unique_ptr<views::View> view = |
+ base::WrapUnique(tray->CreateDefaultView(unused)); |
+ ASSERT_TRUE(view); |
+ EXPECT_EQ( |
+ "Usage and history of this user can be reviewed by the manager " |
+ "(parent@test.com) on chrome.com.", |
+ UTF16ToUTF8(static_cast<LabelTrayView*>(view.get())->message())); |
} |
} // namespace ash |