Chromium Code Reviews| 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 "chrome/browser/browser_process.h" | |
| 8 #include "chrome/browser/browser_process_platform_part.h" | |
| 9 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 10 #include "chrome/browser/chromeos/policy/consumer_management_service.h" | |
| 11 #include "chrome/browser/chromeos/policy/fake_consumer_management_service.h" | |
| 12 #include "chrome/browser/notifications/notification_ui_manager.h" | |
| 13 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 14 #include "chrome/test/base/testing_browser_process.h" | |
| 15 #include "chrome/test/base/testing_profile_manager.h" | |
| 16 #include "testing/gtest/include/gtest/gtest.h" | |
| 17 | |
| 18 namespace policy { | |
| 19 | |
| 20 class ConsumerManagementNotifierTest : public BrowserWithTestWindowTest { | |
| 21 public: | |
| 22 ConsumerManagementNotifierTest() | |
| 23 : fake_service_(new FakeConsumerManagementService()) { | |
| 24 fake_service_->SetStatusAndEnrollmentStage( | |
| 25 ConsumerManagementService::STATUS_UNENROLLED, | |
| 26 ConsumerManagementService::ENROLLMENT_STAGE_NONE); | |
| 27 | |
| 28 // Inject objects. | |
| 29 BrowserPolicyConnectorChromeOS* connector = | |
| 30 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 31 connector->SetConsumerManagementServiceForTesting( | |
| 32 make_scoped_ptr(fake_service_)); | |
|
bartfab (slow)
2014/11/27 14:09:09
Nit: #include "base/memory/scoped_ptr.h"
davidyu
2014/11/28 02:45:26
Done.
| |
| 33 } | |
| 34 | |
| 35 virtual void SetUp() override { | |
|
bartfab (slow)
2014/11/27 14:09:09
Nit: No |virtual| with |override|.
davidyu
2014/11/28 02:45:26
Done.
| |
| 36 BrowserWithTestWindowTest::SetUp(); | |
| 37 | |
| 38 // Set up TestingProfileManager. This is required for NotificationUIManager. | |
| 39 testing_profile_manager_.reset(new TestingProfileManager( | |
| 40 TestingBrowserProcess::GetGlobal())); | |
| 41 ASSERT_TRUE(testing_profile_manager_->SetUp()); | |
| 42 } | |
| 43 | |
| 44 virtual void TearDown() override { | |
| 45 if (notification_) | |
| 46 notification_->Shutdown(); | |
| 47 notification_.reset(); | |
| 48 g_browser_process->notification_ui_manager()->CancelAll(); | |
| 49 testing_profile_manager_.reset(); | |
| 50 | |
| 51 BrowserWithTestWindowTest::TearDown(); | |
| 52 } | |
| 53 | |
| 54 void CreateConsumerManagementNotifier() { | |
| 55 notification_.reset( | |
| 56 new ConsumerManagementNotifier(profile(), fake_service_)); | |
| 57 } | |
| 58 | |
| 59 bool HasEnrollmentNotification() { | |
| 60 return g_browser_process->notification_ui_manager()->FindById( | |
| 61 "consumer_management.enroll", | |
| 62 NotificationUIManager::GetProfileID(profile())); | |
| 63 } | |
| 64 | |
| 65 FakeConsumerManagementService* fake_service_; | |
| 66 scoped_ptr<TestingProfileManager> testing_profile_manager_; | |
| 67 scoped_ptr<ConsumerManagementNotifier> notification_; | |
| 68 }; | |
| 69 | |
| 70 TEST_F(ConsumerManagementNotifierTest, ShowsNotificationWhenCreated) { | |
| 71 fake_service_->SetStatusAndEnrollmentStage( | |
| 72 ConsumerManagementService::STATUS_UNENROLLED, | |
| 73 ConsumerManagementService::ENROLLMENT_STAGE_CANCELED); | |
| 74 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 75 | |
| 76 CreateConsumerManagementNotifier(); | |
| 77 | |
| 78 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE, | |
| 79 fake_service_->GetEnrollmentStage()); | |
| 80 EXPECT_TRUE(HasEnrollmentNotification()); | |
| 81 } | |
| 82 | |
| 83 TEST_F(ConsumerManagementNotifierTest, ShowsNotificationWhenStatusChanged) { | |
| 84 fake_service_->SetStatusAndEnrollmentStage( | |
| 85 ConsumerManagementService::STATUS_ENROLLING, | |
| 86 ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED); | |
| 87 | |
| 88 CreateConsumerManagementNotifier(); | |
| 89 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED, | |
| 90 fake_service_->GetEnrollmentStage()); | |
| 91 EXPECT_FALSE(HasEnrollmentNotification()); | |
| 92 | |
| 93 fake_service_->SetStatusAndEnrollmentStage( | |
| 94 ConsumerManagementService::STATUS_ENROLLED, | |
| 95 ConsumerManagementService::ENROLLMENT_STAGE_SUCCESS); | |
| 96 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE, | |
| 97 fake_service_->GetEnrollmentStage()); | |
| 98 EXPECT_TRUE(HasEnrollmentNotification()); | |
| 99 } | |
| 100 | |
| 101 } // namespace policy | |
| OLD | NEW |