OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <set> | 5 #include <set> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/net/safe_search_util.h" | |
11 #include "chrome/browser/supervised_user/supervised_user_constants.h" | 10 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
12 #include "chrome/browser/supervised_user/supervised_user_pref_store.h" | 11 #include "chrome/browser/supervised_user/supervised_user_pref_store.h" |
13 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" | 12 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
14 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
15 #include "components/prefs/testing_pref_store.h" | 14 #include "components/prefs/testing_pref_store.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
17 | 16 |
18 using base::DictionaryValue; | 17 using base::DictionaryValue; |
19 using base::Value; | 18 using base::Value; |
20 | 19 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 bool allow_deleting_browser_history = true; | 106 bool allow_deleting_browser_history = true; |
108 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( | 107 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( |
109 prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history)); | 108 prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history)); |
110 EXPECT_FALSE(allow_deleting_browser_history); | 109 EXPECT_FALSE(allow_deleting_browser_history); |
111 | 110 |
112 // kSupervisedModeManualHosts does not have a hardcoded value. | 111 // kSupervisedModeManualHosts does not have a hardcoded value. |
113 base::DictionaryValue* manual_hosts = NULL; | 112 base::DictionaryValue* manual_hosts = NULL; |
114 EXPECT_FALSE(fixture.changed_prefs()->GetDictionary( | 113 EXPECT_FALSE(fixture.changed_prefs()->GetDictionary( |
115 prefs::kSupervisedUserManualHosts, &manual_hosts)); | 114 prefs::kSupervisedUserManualHosts, &manual_hosts)); |
116 | 115 |
117 // kForceGoogleSafeSearch defaults to true and kForceYouTubeRestrict defaults | 116 // kForceGoogleSafeSearch and kForceYouTubeSafetyMode default to true for |
118 // to Moderate for supervised users. | 117 // supervised users. |
119 bool force_google_safesearch = false; | 118 bool force_google_safesearch = false; |
120 int force_youtube_restrict = safe_search_util::YOUTUBE_RESTRICT_OFF; | 119 bool force_youtube_safety_mode = false; |
121 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, | 120 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, |
122 &force_google_safesearch)); | 121 &force_google_safesearch)); |
123 EXPECT_TRUE(fixture.changed_prefs()->GetInteger(prefs::kForceYouTubeRestrict, | 122 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( |
124 &force_youtube_restrict)); | 123 prefs::kForceYouTubeSafetyMode, &force_youtube_safety_mode)); |
125 EXPECT_TRUE(force_google_safesearch); | 124 EXPECT_TRUE(force_google_safesearch); |
126 EXPECT_EQ(force_youtube_restrict, | 125 EXPECT_TRUE(force_youtube_safety_mode); |
127 safe_search_util::YOUTUBE_RESTRICT_MODERATE); | |
128 | 126 |
129 // Activating the service again should not change anything. | 127 // Activating the service again should not change anything. |
130 fixture.changed_prefs()->Clear(); | 128 fixture.changed_prefs()->Clear(); |
131 service_.SetActive(true); | 129 service_.SetActive(true); |
132 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 130 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
133 | 131 |
134 // kSupervisedModeManualHosts can be configured by the custodian. | 132 // kSupervisedModeManualHosts can be configured by the custodian. |
135 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 133 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
136 dict->SetBoolean("example.com", true); | 134 dict->SetBoolean("example.com", true); |
137 dict->SetBoolean("moose.org", false); | 135 dict->SetBoolean("moose.org", false); |
138 service_.SetLocalSetting(supervised_users::kContentPackManualBehaviorHosts, | 136 service_.SetLocalSetting(supervised_users::kContentPackManualBehaviorHosts, |
139 std::unique_ptr<base::Value>(dict->DeepCopy())); | 137 std::unique_ptr<base::Value>(dict->DeepCopy())); |
140 EXPECT_EQ(1u, fixture.changed_prefs()->size()); | 138 EXPECT_EQ(1u, fixture.changed_prefs()->size()); |
141 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary( | 139 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary( |
142 prefs::kSupervisedUserManualHosts, &manual_hosts)); | 140 prefs::kSupervisedUserManualHosts, &manual_hosts)); |
143 EXPECT_TRUE(manual_hosts->Equals(dict.get())); | 141 EXPECT_TRUE(manual_hosts->Equals(dict.get())); |
144 | 142 |
145 // kForceGoogleSafeSearch and kForceYouTubeRestrict can be configured by the | 143 // kForceGoogleSafeSearch and kForceYouTubeSafetyMode can be configured by the |
146 // custodian, overriding the hardcoded default. | 144 // custodian, overriding the hardcoded default. |
147 fixture.changed_prefs()->Clear(); | 145 fixture.changed_prefs()->Clear(); |
148 service_.SetLocalSetting( | 146 service_.SetLocalSetting( |
149 supervised_users::kForceSafeSearch, | 147 supervised_users::kForceSafeSearch, |
150 std::unique_ptr<base::Value>(new base::FundamentalValue(false))); | 148 std::unique_ptr<base::Value>(new base::FundamentalValue(false))); |
151 EXPECT_EQ(1u, fixture.changed_prefs()->size()); | 149 EXPECT_EQ(1u, fixture.changed_prefs()->size()); |
152 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, | 150 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, |
153 &force_google_safesearch)); | 151 &force_google_safesearch)); |
154 EXPECT_TRUE(fixture.changed_prefs()->GetInteger(prefs::kForceYouTubeRestrict, | 152 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( |
155 &force_youtube_restrict)); | 153 prefs::kForceYouTubeSafetyMode, &force_youtube_safety_mode)); |
| 154 EXPECT_FALSE(force_youtube_safety_mode); |
156 EXPECT_FALSE(force_google_safesearch); | 155 EXPECT_FALSE(force_google_safesearch); |
157 EXPECT_EQ(force_youtube_restrict, safe_search_util::YOUTUBE_RESTRICT_OFF); | |
158 } | 156 } |
159 | 157 |
160 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) { | 158 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) { |
161 SupervisedUserPrefStoreFixture fixture(&service_); | 159 SupervisedUserPrefStoreFixture fixture(&service_); |
162 EXPECT_FALSE(fixture.initialization_completed()); | 160 EXPECT_FALSE(fixture.initialization_completed()); |
163 | 161 |
164 service_.SetActive(true); | 162 service_.SetActive(true); |
165 EXPECT_FALSE(fixture.initialization_completed()); | 163 EXPECT_FALSE(fixture.initialization_completed()); |
166 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 164 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
167 | 165 |
168 pref_store_->SetInitializationCompleted(); | 166 pref_store_->SetInitializationCompleted(); |
169 EXPECT_TRUE(fixture.initialization_completed()); | 167 EXPECT_TRUE(fixture.initialization_completed()); |
170 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 168 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
171 } | 169 } |
172 | 170 |
173 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) { | 171 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) { |
174 pref_store_->SetInitializationCompleted(); | 172 pref_store_->SetInitializationCompleted(); |
175 service_.SetActive(true); | 173 service_.SetActive(true); |
176 | 174 |
177 SupervisedUserPrefStoreFixture fixture(&service_); | 175 SupervisedUserPrefStoreFixture fixture(&service_); |
178 EXPECT_TRUE(fixture.initialization_completed()); | 176 EXPECT_TRUE(fixture.initialization_completed()); |
179 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 177 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
180 } | 178 } |
181 | 179 |
OLD | NEW |