OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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/policy/managed_prefs_banner_base.h" | |
6 #include "chrome/common/pref_names.h" | |
7 #include "chrome/test/testing_pref_service.h" | |
8 #include "testing/gmock/include/gmock/gmock.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace policy { | |
12 | |
13 // Tests whether managed preferences banner base functionality correctly | |
14 // determines banner visiblity. | |
15 class ManagedPrefsBannerBaseTest : public testing::Test { | |
16 public: | |
17 virtual void SetUp() { | |
18 user_prefs_.reset(new TestingPrefService); | |
19 user_prefs_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, | |
20 false, | |
21 PrefService::UNSYNCABLE_PREF); | |
22 user_prefs_->RegisterBooleanPref(prefs::kSearchSuggestEnabled, | |
23 false, | |
24 PrefService::UNSYNCABLE_PREF); | |
25 local_state_.reset(new TestingPrefService); | |
26 local_state_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, | |
27 false); | |
28 local_state_->RegisterBooleanPref(prefs::kMetricsReportingEnabled, | |
29 false); | |
30 } | |
31 | |
32 scoped_ptr<TestingPrefService> local_state_; | |
33 scoped_ptr<TestingPrefService> user_prefs_; | |
34 }; | |
35 | |
36 TEST_F(ManagedPrefsBannerBaseTest, VisibilityTest) { | |
37 ManagedPrefsBannerBase banner(local_state_.get(), | |
38 user_prefs_.get(), | |
39 OPTIONS_PAGE_ADVANCED); | |
40 banner.AddLocalStatePref(prefs::kMetricsReportingEnabled); | |
41 EXPECT_FALSE(banner.DetermineVisibility()); | |
42 user_prefs_->SetManagedPref(prefs::kHomePageIsNewTabPage, | |
43 Value::CreateBooleanValue(true)); | |
44 EXPECT_FALSE(banner.DetermineVisibility()); | |
45 user_prefs_->SetUserPref(prefs::kSearchSuggestEnabled, | |
46 Value::CreateBooleanValue(true)); | |
47 EXPECT_FALSE(banner.DetermineVisibility()); | |
48 user_prefs_->SetManagedPref(prefs::kSearchSuggestEnabled, | |
49 Value::CreateBooleanValue(false)); | |
50 EXPECT_TRUE(banner.DetermineVisibility()); | |
51 local_state_->SetManagedPref(prefs::kMetricsReportingEnabled, | |
52 Value::CreateBooleanValue(true)); | |
53 EXPECT_TRUE(banner.DetermineVisibility()); | |
54 user_prefs_->RemoveManagedPref(prefs::kSearchSuggestEnabled); | |
55 EXPECT_TRUE(banner.DetermineVisibility()); | |
56 local_state_->RemoveManagedPref(prefs::kMetricsReportingEnabled); | |
57 EXPECT_FALSE(banner.DetermineVisibility()); | |
58 local_state_->SetManagedPref(prefs::kHomePageIsNewTabPage, | |
59 Value::CreateBooleanValue(true)); | |
60 EXPECT_FALSE(banner.DetermineVisibility()); | |
61 } | |
62 | |
63 // Mock class that allows to capture the notification callback. | |
64 class ManagedPrefsBannerBaseMock : public ManagedPrefsBannerBase { | |
65 public: | |
66 ManagedPrefsBannerBaseMock(PrefService* local_state, | |
67 PrefService* user_prefs, | |
68 OptionsPage page) | |
69 : ManagedPrefsBannerBase(local_state, user_prefs, page) { } | |
70 | |
71 MOCK_METHOD0(OnUpdateVisibility, void()); | |
72 }; | |
73 | |
74 TEST_F(ManagedPrefsBannerBaseTest, NotificationTest) { | |
75 ManagedPrefsBannerBaseMock banner(local_state_.get(), | |
76 user_prefs_.get(), | |
77 OPTIONS_PAGE_ADVANCED); | |
78 banner.AddLocalStatePref(prefs::kMetricsReportingEnabled); | |
79 EXPECT_CALL(banner, OnUpdateVisibility()).Times(0); | |
80 user_prefs_->SetBoolean(prefs::kHomePageIsNewTabPage, true); | |
81 EXPECT_CALL(banner, OnUpdateVisibility()).Times(1); | |
82 user_prefs_->SetManagedPref(prefs::kSearchSuggestEnabled, | |
83 Value::CreateBooleanValue(false)); | |
84 EXPECT_CALL(banner, OnUpdateVisibility()).Times(1); | |
85 local_state_->SetManagedPref(prefs::kMetricsReportingEnabled, | |
86 Value::CreateBooleanValue(true)); | |
87 } | |
88 | |
89 } // namespace policy | |
OLD | NEW |