| OLD | NEW |
| 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 "chrome/browser/chromeos/policy/consumer_management_notifier.h" | 5 #include "chrome/browser/chromeos/policy/consumer_management_notifier.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include <memory> |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/browser_process_platform_part.h" | 11 #include "chrome/browser/browser_process_platform_part.h" |
| 10 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 12 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 11 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | 13 #include "chrome/browser/chromeos/policy/consumer_management_service.h" |
| 12 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" | 14 #include "chrome/browser/chromeos/policy/consumer_management_stage.h" |
| 13 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | 15 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" |
| 14 #include "chrome/browser/notifications/notification_ui_manager.h" | 16 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 15 #include "chrome/test/base/browser_with_test_window_test.h" | 17 #include "chrome/test/base/browser_with_test_window_test.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "chrome/test/base/testing_profile_manager.h" | 19 #include "chrome/test/base/testing_profile_manager.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 21 |
| 20 namespace policy { | 22 namespace policy { |
| 21 | 23 |
| 22 class ConsumerManagementNotifierTest : public BrowserWithTestWindowTest { | 24 class ConsumerManagementNotifierTest : public BrowserWithTestWindowTest { |
| 23 public: | 25 public: |
| 24 ConsumerManagementNotifierTest() | 26 ConsumerManagementNotifierTest() |
| 25 : fake_service_(new FakeConsumerManagementService()) { | 27 : fake_service_(new FakeConsumerManagementService()) { |
| 26 fake_service_->SetStatusAndStage( | 28 fake_service_->SetStatusAndStage( |
| 27 ConsumerManagementService::STATUS_UNENROLLED, | 29 ConsumerManagementService::STATUS_UNENROLLED, |
| 28 ConsumerManagementStage::None()); | 30 ConsumerManagementStage::None()); |
| 29 | 31 |
| 30 // Inject objects. | 32 // Inject objects. |
| 31 BrowserPolicyConnectorChromeOS* connector = | 33 BrowserPolicyConnectorChromeOS* connector = |
| 32 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 34 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 33 connector->SetConsumerManagementServiceForTesting( | 35 connector->SetConsumerManagementServiceForTesting( |
| 34 make_scoped_ptr(fake_service_)); | 36 base::WrapUnique(fake_service_)); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void SetUp() override { | 39 void SetUp() override { |
| 38 BrowserWithTestWindowTest::SetUp(); | 40 BrowserWithTestWindowTest::SetUp(); |
| 39 | 41 |
| 40 // Set up TestingProfileManager. This is required for NotificationUIManager. | 42 // Set up TestingProfileManager. This is required for NotificationUIManager. |
| 41 testing_profile_manager_.reset(new TestingProfileManager( | 43 testing_profile_manager_.reset(new TestingProfileManager( |
| 42 TestingBrowserProcess::GetGlobal())); | 44 TestingBrowserProcess::GetGlobal())); |
| 43 ASSERT_TRUE(testing_profile_manager_->SetUp()); | 45 ASSERT_TRUE(testing_profile_manager_->SetUp()); |
| 44 } | 46 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 64 NotificationUIManager::GetProfileID(profile())); | 66 NotificationUIManager::GetProfileID(profile())); |
| 65 } | 67 } |
| 66 | 68 |
| 67 bool HasUnenrollmentNotification() { | 69 bool HasUnenrollmentNotification() { |
| 68 return g_browser_process->notification_ui_manager()->FindById( | 70 return g_browser_process->notification_ui_manager()->FindById( |
| 69 "consumer_management.unenroll", | 71 "consumer_management.unenroll", |
| 70 NotificationUIManager::GetProfileID(profile())); | 72 NotificationUIManager::GetProfileID(profile())); |
| 71 } | 73 } |
| 72 | 74 |
| 73 FakeConsumerManagementService* fake_service_; | 75 FakeConsumerManagementService* fake_service_; |
| 74 scoped_ptr<TestingProfileManager> testing_profile_manager_; | 76 std::unique_ptr<TestingProfileManager> testing_profile_manager_; |
| 75 scoped_ptr<ConsumerManagementNotifier> notification_; | 77 std::unique_ptr<ConsumerManagementNotifier> notification_; |
| 76 }; | 78 }; |
| 77 | 79 |
| 78 TEST_F(ConsumerManagementNotifierTest, | 80 TEST_F(ConsumerManagementNotifierTest, |
| 79 ShowsEnrollmentNotificationWhenCreated) { | 81 ShowsEnrollmentNotificationWhenCreated) { |
| 80 fake_service_->SetStatusAndStage( | 82 fake_service_->SetStatusAndStage( |
| 81 ConsumerManagementService::STATUS_UNENROLLED, | 83 ConsumerManagementService::STATUS_UNENROLLED, |
| 82 ConsumerManagementStage::EnrollmentCanceled()); | 84 ConsumerManagementStage::EnrollmentCanceled()); |
| 83 EXPECT_FALSE(HasEnrollmentNotification()); | 85 EXPECT_FALSE(HasEnrollmentNotification()); |
| 84 EXPECT_FALSE(HasUnenrollmentNotification()); | 86 EXPECT_FALSE(HasUnenrollmentNotification()); |
| 85 | 87 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 145 |
| 144 fake_service_->SetStatusAndStage( | 146 fake_service_->SetStatusAndStage( |
| 145 ConsumerManagementService::STATUS_UNENROLLED, | 147 ConsumerManagementService::STATUS_UNENROLLED, |
| 146 ConsumerManagementStage::UnenrollmentSuccess()); | 148 ConsumerManagementStage::UnenrollmentSuccess()); |
| 147 EXPECT_EQ(ConsumerManagementStage::None(), fake_service_->GetStage()); | 149 EXPECT_EQ(ConsumerManagementStage::None(), fake_service_->GetStage()); |
| 148 EXPECT_FALSE(HasEnrollmentNotification()); | 150 EXPECT_FALSE(HasEnrollmentNotification()); |
| 149 EXPECT_TRUE(HasUnenrollmentNotification()); | 151 EXPECT_TRUE(HasUnenrollmentNotification()); |
| 150 } | 152 } |
| 151 | 153 |
| 152 } // namespace policy | 154 } // namespace policy |
| OLD | NEW |