15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file. 43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ash/system/chromeos/supervised/tray_supervised_user.h" 63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/shell.h" 83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/system/user/login_status.h" 93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ash/test/ash_test_base.h" 10d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)#include "ash/test/test_system_tray_delegate.h" 113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/message_center/message_center.h" 123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/message_center/notification.h" 133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/message_center/notification_list.h" 143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/message_center/notification_types.h" 153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)using message_center::NotificationList; 173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace ash { 193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class TraySupervisedUserTest : public test::AshTestBase { 213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public: 225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TraySupervisedUserTest() {} 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual ~TraySupervisedUserTest() {} 243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) protected: 263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) message_center::Notification* GetPopup(); 273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) private: 295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserTest); 303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)message_center::Notification* TraySupervisedUserTest::GetPopup() { 333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) NotificationList::PopupNotifications popups = 343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) message_center::MessageCenter::Get()->GetPopupNotifications(); 353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) for (NotificationList::PopupNotifications::const_iterator iter = 363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) popups.begin(); iter != popups.end(); ++iter) { 375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if ((*iter)->id() == TraySupervisedUser::kNotificationId) 383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return *iter; 393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return NULL; 413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)class TraySupervisedUserInitialTest : public TraySupervisedUserTest { 443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public: 455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) TraySupervisedUserInitialTest() {} 465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) virtual ~TraySupervisedUserInitialTest() {} 473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void SetUp() OVERRIDE; 493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void TearDown() OVERRIDE; 503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) private: 525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(TraySupervisedUserInitialTest); 533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void TraySupervisedUserInitialTest::SetUp() { 563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) test::TestSystemTrayDelegate::SetInitialLoginStatus( 575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) user::LOGGED_IN_SUPERVISED); 583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) test::AshTestBase::SetUp(); 593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)void TraySupervisedUserInitialTest::TearDown() { 623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) test::AshTestBase::TearDown(); 633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // SetInitialLoginStatus() is reset in AshTestHelper::TearDown(). 643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST_F(TraySupervisedUserTest, SupervisedUserHasNotification) { 673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) test::TestSystemTrayDelegate* delegate = 683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) static_cast<test::TestSystemTrayDelegate*>( 693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ash::Shell::GetInstance()->system_tray_delegate()); 705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) delegate->SetLoginStatus(user::LOGGED_IN_SUPERVISED); 713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) message_center::Notification* notification = GetPopup(); 733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); 743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), 753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) notification->rich_notification_data().priority); 763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST_F(TraySupervisedUserInitialTest, SupervisedUserNoCrash) { 795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Initial login status is already SUPERVISED, which should create 803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // the notification and should not cause crashes. 813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) message_center::Notification* notification = GetPopup(); 823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ASSERT_NE(static_cast<message_center::Notification*>(NULL), notification); 833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) EXPECT_EQ(static_cast<int>(message_center::SYSTEM_PRIORITY), 843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) notification->rich_notification_data().priority); 853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} // namespace 88