| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/policy/consumer_management_notifier.h" | |
| 6 | |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/memory/ptr_util.h" | |
| 10 #include "chrome/browser/browser_process.h" | |
| 11 #include "chrome/browser/browser_process_platform_part.h" | |
| 12 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 13 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 14 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | |
| 15 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | |
| 16 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 17 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 18 #include "chrome/test/base/testing_browser_process.h" | |
| 19 #include "chrome/test/base/testing_profile_manager.h" | |
| 20 #include "testing/gtest/include/gtest/gtest.h" | |
| 21 | |
| 22 namespace policy { | |
| 23 | |
| 24 class ConsumerManagementNotifierTest : public BrowserWithTestWindowTest { | |
| 25 public: | |
| 26 ConsumerManagementNotifierTest() | |
| 27 : fake_service_(new FakeConsumerManagementService()) { | |
| 28 fake_service_->SetStatusAndStage( | |
| 29 ConsumerManagementService::STATUS_UNENROLLED, | |
| 30 ConsumerManagementStage::None()); | |
| 31 | |
| 32 // Inject objects. | |
| 33 BrowserPolicyConnectorChromeOS* connector = | |
| 34 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 35 connector->SetConsumerManagementServiceForTesting( | |
| 36 base::WrapUnique(fake_service_)); | |
| 37 } | |
| 38 | |
| 39 void SetUp() override { | |
| 40 BrowserWithTestWindowTest::SetUp(); | |
| 41 | |
| 42 // Set up TestingProfileManager. This is required for NotificationUIManager. | |
| 43 testing_profile_manager_.reset(new TestingProfileManager( | |
| 44 TestingBrowserProcess::GetGlobal())); | |
| 45 ASSERT_TRUE(testing_profile_manager_->SetUp()); | |
| 46 } | |
| 47 | |
| 48 void TearDown() override { | |
| 49 if (notification_) | |
| 50 notification_->Shutdown(); | |
| 51 notification_.reset(); | |
| 52 g_browser_process->notification_ui_manager()->CancelAll(); | |
| 53 testing_profile_manager_.reset(); | |
| 54 | |
| 55 BrowserWithTestWindowTest::TearDown(); | |
| 56 } | |
| 57 | |
| 58 void CreateConsumerManagementNotifier() { | |
| 59 notification_.reset( | |
| 60 new ConsumerManagementNotifier(profile(), fake_service_)); | |
| 61 } | |
| 62 | |
| 63 bool HasEnrollmentNotification() { | |
| 64 return g_browser_process->notification_ui_manager()->FindById( | |
| 65 "consumer_management.enroll", | |
| 66 NotificationUIManager::GetProfileID(profile())); | |
| 67 } | |
| 68 | |
| 69 bool HasUnenrollmentNotification() { | |
| 70 return g_browser_process->notification_ui_manager()->FindById( | |
| 71 "consumer_management.unenroll", | |
| 72 NotificationUIManager::GetProfileID(profile())); | |
| 73 } | |
| 74 | |
| 75 FakeConsumerManagementService* fake_service_; | |
| 76 std::unique_ptr<TestingProfileManager> testing_profile_manager_; | |
| 77 std::unique_ptr<ConsumerManagementNotifier> notification_; | |
| 78 }; | |
| 79 | |
| 80 TEST_F(ConsumerManagementNotifierTest, | |
| 81 ShowsEnrollmentNotificationWhenCreated) { | |
| 82 fake_service_->SetStatusAndStage( | |
| 83 ConsumerManagementService::STATUS_UNENROLLED, | |
| 84 ConsumerManagementStage::EnrollmentCanceled()); | |
| 85 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 86 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 87 | |
| 88 CreateConsumerManagementNotifier(); | |
| 89 | |
| 90 EXPECT_EQ(ConsumerManagementStage::None(), fake_service_->GetStage()); | |
| 91 EXPECT_TRUE(HasEnrollmentNotification()); | |
| 92 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 93 } | |
| 94 | |
| 95 TEST_F(ConsumerManagementNotifierTest, | |
| 96 ShowsUnenrollmentNotificationWhenCreated) { | |
| 97 fake_service_->SetStatusAndStage( | |
| 98 ConsumerManagementService::STATUS_UNENROLLED, | |
| 99 ConsumerManagementStage::UnenrollmentSuccess()); | |
| 100 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 101 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 102 | |
| 103 CreateConsumerManagementNotifier(); | |
| 104 | |
| 105 EXPECT_EQ(ConsumerManagementStage::None(), fake_service_->GetStage()); | |
| 106 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 107 EXPECT_TRUE(HasUnenrollmentNotification()); | |
| 108 } | |
| 109 | |
| 110 TEST_F(ConsumerManagementNotifierTest, | |
| 111 ShowsEnrollmentNotificationWhenStatusChanged) { | |
| 112 fake_service_->SetStatusAndStage( | |
| 113 ConsumerManagementService::STATUS_ENROLLING, | |
| 114 ConsumerManagementStage::EnrollmentOwnerStored()); | |
| 115 | |
| 116 CreateConsumerManagementNotifier(); | |
| 117 EXPECT_EQ(ConsumerManagementStage::EnrollmentOwnerStored(), | |
| 118 fake_service_->GetStage()); | |
| 119 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 120 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 121 | |
| 122 fake_service_->SetStatusAndStage( | |
| 123 ConsumerManagementService::STATUS_ENROLLED, | |
| 124 ConsumerManagementStage::EnrollmentSuccess()); | |
| 125 EXPECT_EQ(ConsumerManagementStage::None(), fake_service_->GetStage()); | |
| 126 EXPECT_TRUE(HasEnrollmentNotification()); | |
| 127 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 128 } | |
| 129 | |
| 130 TEST_F(ConsumerManagementNotifierTest, | |
| 131 ShowsUnenrollmentNotificationWhenStatusChanged) { | |
| 132 fake_service_->SetStatusAndStage( | |
| 133 ConsumerManagementService::STATUS_ENROLLED, | |
| 134 ConsumerManagementStage::None()); | |
| 135 | |
| 136 CreateConsumerManagementNotifier(); | |
| 137 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 138 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 139 | |
| 140 fake_service_->SetStatusAndStage( | |
| 141 ConsumerManagementService::STATUS_UNENROLLING, | |
| 142 ConsumerManagementStage::UnenrollmentRequested()); | |
| 143 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 144 EXPECT_FALSE(HasUnenrollmentNotification()); | |
| 145 | |
| 146 fake_service_->SetStatusAndStage( | |
| 147 ConsumerManagementService::STATUS_UNENROLLED, | |
| 148 ConsumerManagementStage::UnenrollmentSuccess()); | |
| 149 EXPECT_EQ(ConsumerManagementStage::None(), fake_service_->GetStage()); | |
| 150 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 151 EXPECT_TRUE(HasUnenrollmentNotification()); | |
| 152 } | |
| 153 | |
| 154 } // namespace policy | |
| OLD | NEW |