Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(563)

Unified Diff: chrome/browser/chromeos/policy/consumer_management_notifier_unittest.cc

Issue 733613005: Move the notification part out of ConsumerEnrollmentHandler so that it can be reused for unenrollme… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@enroll
Patch Set: Added a check for UserManager. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/policy/consumer_management_notifier_unittest.cc
diff --git a/chrome/browser/chromeos/policy/consumer_management_notifier_unittest.cc b/chrome/browser/chromeos/policy/consumer_management_notifier_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3216fe35bb825f4e9b8b0bef8f1d4117dd58882d
--- /dev/null
+++ b/chrome/browser/chromeos/policy/consumer_management_notifier_unittest.cc
@@ -0,0 +1,101 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/policy/consumer_management_notifier.h"
+
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/browser_process_platform_part.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/consumer_management_service.h"
+#include "chrome/browser/chromeos/policy/fake_consumer_management_service.h"
+#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/test/base/browser_with_test_window_test.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_profile_manager.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace policy {
+
+class ConsumerManagementNotifierTest : public BrowserWithTestWindowTest {
+ public:
+ ConsumerManagementNotifierTest()
+ : fake_service_(new FakeConsumerManagementService()) {
+ fake_service_->SetStatusAndEnrollmentStage(
+ ConsumerManagementService::STATUS_UNENROLLED,
+ ConsumerManagementService::ENROLLMENT_STAGE_NONE);
+
+ // Inject objects.
+ BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ connector->SetConsumerManagementServiceForTesting(
+ 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.
+ }
+
+ 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.
+ BrowserWithTestWindowTest::SetUp();
+
+ // Set up TestingProfileManager. This is required for NotificationUIManager.
+ testing_profile_manager_.reset(new TestingProfileManager(
+ TestingBrowserProcess::GetGlobal()));
+ ASSERT_TRUE(testing_profile_manager_->SetUp());
+ }
+
+ virtual void TearDown() override {
+ if (notification_)
+ notification_->Shutdown();
+ notification_.reset();
+ g_browser_process->notification_ui_manager()->CancelAll();
+ testing_profile_manager_.reset();
+
+ BrowserWithTestWindowTest::TearDown();
+ }
+
+ void CreateConsumerManagementNotifier() {
+ notification_.reset(
+ new ConsumerManagementNotifier(profile(), fake_service_));
+ }
+
+ bool HasEnrollmentNotification() {
+ return g_browser_process->notification_ui_manager()->FindById(
+ "consumer_management.enroll",
+ NotificationUIManager::GetProfileID(profile()));
+ }
+
+ FakeConsumerManagementService* fake_service_;
+ scoped_ptr<TestingProfileManager> testing_profile_manager_;
+ scoped_ptr<ConsumerManagementNotifier> notification_;
+};
+
+TEST_F(ConsumerManagementNotifierTest, ShowsNotificationWhenCreated) {
+ fake_service_->SetStatusAndEnrollmentStage(
+ ConsumerManagementService::STATUS_UNENROLLED,
+ ConsumerManagementService::ENROLLMENT_STAGE_CANCELED);
+ EXPECT_FALSE(HasEnrollmentNotification());
+
+ CreateConsumerManagementNotifier();
+
+ EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
+ fake_service_->GetEnrollmentStage());
+ EXPECT_TRUE(HasEnrollmentNotification());
+}
+
+TEST_F(ConsumerManagementNotifierTest, ShowsNotificationWhenStatusChanged) {
+ fake_service_->SetStatusAndEnrollmentStage(
+ ConsumerManagementService::STATUS_ENROLLING,
+ ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED);
+
+ CreateConsumerManagementNotifier();
+ EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED,
+ fake_service_->GetEnrollmentStage());
+ EXPECT_FALSE(HasEnrollmentNotification());
+
+ fake_service_->SetStatusAndEnrollmentStage(
+ ConsumerManagementService::STATUS_ENROLLED,
+ ConsumerManagementService::ENROLLMENT_STAGE_SUCCESS);
+ EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
+ fake_service_->GetEnrollmentStage());
+ EXPECT_TRUE(HasEnrollmentNotification());
+}
+
+} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698