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

Side by Side Diff: chrome/browser/supervised_user/supervised_user_pref_store_unittest.cc

Issue 2401743003: Recommit and fix of "Added a ForceYouTubeRestrict policy and deprecated the old ForceYouTubeSafetyM… (Closed)
Patch Set: Rebase Created 4 years, 2 months 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 unified diff | Download patch
OLDNEW
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"
10 #include "chrome/browser/supervised_user/supervised_user_constants.h" 11 #include "chrome/browser/supervised_user/supervised_user_constants.h"
11 #include "chrome/browser/supervised_user/supervised_user_pref_store.h" 12 #include "chrome/browser/supervised_user/supervised_user_pref_store.h"
12 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" 13 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 #include "components/prefs/testing_pref_store.h" 15 #include "components/prefs/testing_pref_store.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 17
17 using base::DictionaryValue; 18 using base::DictionaryValue;
18 using base::Value; 19 using base::Value;
19 20
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 bool allow_deleting_browser_history = true; 107 bool allow_deleting_browser_history = true;
107 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( 108 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(
108 prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history)); 109 prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history));
109 EXPECT_FALSE(allow_deleting_browser_history); 110 EXPECT_FALSE(allow_deleting_browser_history);
110 111
111 // kSupervisedModeManualHosts does not have a hardcoded value. 112 // kSupervisedModeManualHosts does not have a hardcoded value.
112 base::DictionaryValue* manual_hosts = NULL; 113 base::DictionaryValue* manual_hosts = NULL;
113 EXPECT_FALSE(fixture.changed_prefs()->GetDictionary( 114 EXPECT_FALSE(fixture.changed_prefs()->GetDictionary(
114 prefs::kSupervisedUserManualHosts, &manual_hosts)); 115 prefs::kSupervisedUserManualHosts, &manual_hosts));
115 116
116 // kForceGoogleSafeSearch and kForceYouTubeSafetyMode default to true for 117 // kForceGoogleSafeSearch defaults to true and kForceYouTubeRestrict defaults
117 // supervised users. 118 // to Moderate for supervised users.
118 bool force_google_safesearch = false; 119 bool force_google_safesearch = false;
119 bool force_youtube_safety_mode = false; 120 int force_youtube_restrict = safe_search_util::YOUTUBE_RESTRICT_OFF;
120 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, 121 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch,
121 &force_google_safesearch)); 122 &force_google_safesearch));
122 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( 123 EXPECT_TRUE(fixture.changed_prefs()->GetInteger(prefs::kForceYouTubeRestrict,
123 prefs::kForceYouTubeSafetyMode, &force_youtube_safety_mode)); 124 &force_youtube_restrict));
124 EXPECT_TRUE(force_google_safesearch); 125 EXPECT_TRUE(force_google_safesearch);
125 EXPECT_TRUE(force_youtube_safety_mode); 126 EXPECT_EQ(force_youtube_restrict,
127 safe_search_util::YOUTUBE_RESTRICT_MODERATE);
126 128
127 // Activating the service again should not change anything. 129 // Activating the service again should not change anything.
128 fixture.changed_prefs()->Clear(); 130 fixture.changed_prefs()->Clear();
129 service_.SetActive(true); 131 service_.SetActive(true);
130 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 132 EXPECT_EQ(0u, fixture.changed_prefs()->size());
131 133
132 // kSupervisedModeManualHosts can be configured by the custodian. 134 // kSupervisedModeManualHosts can be configured by the custodian.
133 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); 135 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
134 dict->SetBoolean("example.com", true); 136 dict->SetBoolean("example.com", true);
135 dict->SetBoolean("moose.org", false); 137 dict->SetBoolean("moose.org", false);
136 service_.SetLocalSetting(supervised_users::kContentPackManualBehaviorHosts, 138 service_.SetLocalSetting(supervised_users::kContentPackManualBehaviorHosts,
137 std::unique_ptr<base::Value>(dict->DeepCopy())); 139 std::unique_ptr<base::Value>(dict->DeepCopy()));
138 EXPECT_EQ(1u, fixture.changed_prefs()->size()); 140 EXPECT_EQ(1u, fixture.changed_prefs()->size());
139 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary( 141 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary(
140 prefs::kSupervisedUserManualHosts, &manual_hosts)); 142 prefs::kSupervisedUserManualHosts, &manual_hosts));
141 EXPECT_TRUE(manual_hosts->Equals(dict.get())); 143 EXPECT_TRUE(manual_hosts->Equals(dict.get()));
142 144
143 // kForceGoogleSafeSearch and kForceYouTubeSafetyMode can be configured by the 145 // kForceGoogleSafeSearch and kForceYouTubeRestrict can be configured by the
144 // custodian, overriding the hardcoded default. 146 // custodian, overriding the hardcoded default.
145 fixture.changed_prefs()->Clear(); 147 fixture.changed_prefs()->Clear();
146 service_.SetLocalSetting( 148 service_.SetLocalSetting(
147 supervised_users::kForceSafeSearch, 149 supervised_users::kForceSafeSearch,
148 std::unique_ptr<base::Value>(new base::FundamentalValue(false))); 150 std::unique_ptr<base::Value>(new base::FundamentalValue(false)));
149 EXPECT_EQ(1u, fixture.changed_prefs()->size()); 151 EXPECT_EQ(1u, fixture.changed_prefs()->size());
150 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, 152 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch,
151 &force_google_safesearch)); 153 &force_google_safesearch));
152 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( 154 EXPECT_TRUE(fixture.changed_prefs()->GetInteger(prefs::kForceYouTubeRestrict,
153 prefs::kForceYouTubeSafetyMode, &force_youtube_safety_mode)); 155 &force_youtube_restrict));
154 EXPECT_FALSE(force_youtube_safety_mode);
155 EXPECT_FALSE(force_google_safesearch); 156 EXPECT_FALSE(force_google_safesearch);
157 EXPECT_EQ(force_youtube_restrict, safe_search_util::YOUTUBE_RESTRICT_OFF);
156 } 158 }
157 159
158 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) { 160 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) {
159 SupervisedUserPrefStoreFixture fixture(&service_); 161 SupervisedUserPrefStoreFixture fixture(&service_);
160 EXPECT_FALSE(fixture.initialization_completed()); 162 EXPECT_FALSE(fixture.initialization_completed());
161 163
162 service_.SetActive(true); 164 service_.SetActive(true);
163 EXPECT_FALSE(fixture.initialization_completed()); 165 EXPECT_FALSE(fixture.initialization_completed());
164 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 166 EXPECT_EQ(0u, fixture.changed_prefs()->size());
165 167
166 pref_store_->SetInitializationCompleted(); 168 pref_store_->SetInitializationCompleted();
167 EXPECT_TRUE(fixture.initialization_completed()); 169 EXPECT_TRUE(fixture.initialization_completed());
168 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 170 EXPECT_EQ(0u, fixture.changed_prefs()->size());
169 } 171 }
170 172
171 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) { 173 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) {
172 pref_store_->SetInitializationCompleted(); 174 pref_store_->SetInitializationCompleted();
173 service_.SetActive(true); 175 service_.SetActive(true);
174 176
175 SupervisedUserPrefStoreFixture fixture(&service_); 177 SupervisedUserPrefStoreFixture fixture(&service_);
176 EXPECT_TRUE(fixture.initialization_completed()); 178 EXPECT_TRUE(fixture.initialization_completed());
177 EXPECT_EQ(0u, fixture.changed_prefs()->size()); 179 EXPECT_EQ(0u, fixture.changed_prefs()->size());
178 } 180 }
179 181
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698