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

Unified Diff: chrome/browser/chromeos/policy/consumer_management_notification_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: 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_notification_unittest.cc
diff --git a/chrome/browser/chromeos/policy/consumer_management_notification_unittest.cc b/chrome/browser/chromeos/policy/consumer_management_notification_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..a90541c593b7fc7976c90e3a7becb384ac350579
--- /dev/null
+++ b/chrome/browser/chromeos/policy/consumer_management_notification_unittest.cc
@@ -0,0 +1,105 @@
+// 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_notification.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/gmock/include/gmock/gmock.h"
Mattias Nissler (ping if slow) 2014/11/18 10:02:27 not used
davidyu 2014/11/19 02:54:21 Done.
+#include "testing/gtest/include/gtest/gtest.h"
+
Mattias Nissler (ping if slow) 2014/11/18 10:02:27 nit: remove extra newline
davidyu 2014/11/19 02:54:21 Done.
+
+using testing::NiceMock;
Mattias Nissler (ping if slow) 2014/11/18 10:02:27 not used
davidyu 2014/11/19 02:54:21 Done.
+
+namespace policy {
+
+class ConsumerManagementNotificationTest : public BrowserWithTestWindowTest {
+ public:
+ ConsumerManagementNotificationTest()
+ : 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_));
+ }
+
+ virtual void SetUp() override {
+ 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 CreateConsumerManagementNotification() {
+ notification_.reset(
+ new ConsumerManagementNotification(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<ConsumerManagementNotification> notification_;
+};
+
+TEST_F(ConsumerManagementNotificationTest, ShowsNotificationWhenCreated) {
+ fake_service_->SetStatusAndEnrollmentStage(
+ ConsumerManagementService::STATUS_UNENROLLED,
+ ConsumerManagementService::ENROLLMENT_STAGE_CANCELED);
+ EXPECT_FALSE(HasEnrollmentNotification());
+
+ CreateConsumerManagementNotification();
+
+ EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE,
+ fake_service_->GetEnrollmentStage());
+ EXPECT_TRUE(HasEnrollmentNotification());
+}
+
+TEST_F(ConsumerManagementNotificationTest, ShowsNotificationWhenStatusChanged) {
+ fake_service_->SetStatusAndEnrollmentStage(
+ ConsumerManagementService::STATUS_ENROLLING,
+ ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED);
+
+ CreateConsumerManagementNotification();
+ 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