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_notification.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/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.
| |
17 #include "testing/gtest/include/gtest/gtest.h" | |
18 | |
Mattias Nissler (ping if slow)
2014/11/18 10:02:27
nit: remove extra newline
davidyu
2014/11/19 02:54:21
Done.
| |
19 | |
20 using testing::NiceMock; | |
Mattias Nissler (ping if slow)
2014/11/18 10:02:27
not used
davidyu
2014/11/19 02:54:21
Done.
| |
21 | |
22 namespace policy { | |
23 | |
24 class ConsumerManagementNotificationTest : public BrowserWithTestWindowTest { | |
25 public: | |
26 ConsumerManagementNotificationTest() | |
27 : fake_service_(new FakeConsumerManagementService()) { | |
28 fake_service_->SetStatusAndEnrollmentStage( | |
29 ConsumerManagementService::STATUS_UNENROLLED, | |
30 ConsumerManagementService::ENROLLMENT_STAGE_NONE); | |
31 | |
32 // Inject objects. | |
33 BrowserPolicyConnectorChromeOS* connector = | |
34 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
35 connector->SetConsumerManagementServiceForTesting( | |
36 make_scoped_ptr(fake_service_)); | |
37 } | |
38 | |
39 virtual 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 virtual 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 CreateConsumerManagementNotification() { | |
59 notification_.reset( | |
60 new ConsumerManagementNotification(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 FakeConsumerManagementService* fake_service_; | |
70 scoped_ptr<TestingProfileManager> testing_profile_manager_; | |
71 scoped_ptr<ConsumerManagementNotification> notification_; | |
72 }; | |
73 | |
74 TEST_F(ConsumerManagementNotificationTest, ShowsNotificationWhenCreated) { | |
75 fake_service_->SetStatusAndEnrollmentStage( | |
76 ConsumerManagementService::STATUS_UNENROLLED, | |
77 ConsumerManagementService::ENROLLMENT_STAGE_CANCELED); | |
78 EXPECT_FALSE(HasEnrollmentNotification()); | |
79 | |
80 CreateConsumerManagementNotification(); | |
81 | |
82 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE, | |
83 fake_service_->GetEnrollmentStage()); | |
84 EXPECT_TRUE(HasEnrollmentNotification()); | |
85 } | |
86 | |
87 TEST_F(ConsumerManagementNotificationTest, ShowsNotificationWhenStatusChanged) { | |
88 fake_service_->SetStatusAndEnrollmentStage( | |
89 ConsumerManagementService::STATUS_ENROLLING, | |
90 ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED); | |
91 | |
92 CreateConsumerManagementNotification(); | |
93 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_OWNER_STORED, | |
94 fake_service_->GetEnrollmentStage()); | |
95 EXPECT_FALSE(HasEnrollmentNotification()); | |
96 | |
97 fake_service_->SetStatusAndEnrollmentStage( | |
98 ConsumerManagementService::STATUS_ENROLLED, | |
99 ConsumerManagementService::ENROLLMENT_STAGE_SUCCESS); | |
100 EXPECT_EQ(ConsumerManagementService::ENROLLMENT_STAGE_NONE, | |
101 fake_service_->GetEnrollmentStage()); | |
102 EXPECT_TRUE(HasEnrollmentNotification()); | |
103 } | |
104 | |
105 } // namespace policy | |
OLD | NEW |