| 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" |
| 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 Loading... |
| 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 = |
| 121 static_cast<int>(safe_search_util::YouTubeRestrictMode::OFF); |
| 120 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, | 122 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, |
| 121 &force_google_safesearch)); | 123 &force_google_safesearch)); |
| 122 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( | 124 EXPECT_TRUE(fixture.changed_prefs()->GetInteger(prefs::kForceYouTubeRestrict, |
| 123 prefs::kForceYouTubeSafetyMode, &force_youtube_safety_mode)); | 125 &force_youtube_restrict)); |
| 124 EXPECT_TRUE(force_google_safesearch); | 126 EXPECT_TRUE(force_google_safesearch); |
| 125 EXPECT_TRUE(force_youtube_safety_mode); | 127 EXPECT_EQ(force_youtube_restrict, |
| 128 static_cast<int>(safe_search_util::YouTubeRestrictMode::MODERATE)); |
| 126 | 129 |
| 127 // Activating the service again should not change anything. | 130 // Activating the service again should not change anything. |
| 128 fixture.changed_prefs()->Clear(); | 131 fixture.changed_prefs()->Clear(); |
| 129 service_.SetActive(true); | 132 service_.SetActive(true); |
| 130 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 133 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
| 131 | 134 |
| 132 // kSupervisedModeManualHosts can be configured by the custodian. | 135 // kSupervisedModeManualHosts can be configured by the custodian. |
| 133 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); | 136 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
| 134 dict->SetBoolean("example.com", true); | 137 dict->SetBoolean("example.com", true); |
| 135 dict->SetBoolean("moose.org", false); | 138 dict->SetBoolean("moose.org", false); |
| 136 service_.SetLocalSetting(supervised_users::kContentPackManualBehaviorHosts, | 139 service_.SetLocalSetting(supervised_users::kContentPackManualBehaviorHosts, |
| 137 std::unique_ptr<base::Value>(dict->DeepCopy())); | 140 std::unique_ptr<base::Value>(dict->DeepCopy())); |
| 138 EXPECT_EQ(1u, fixture.changed_prefs()->size()); | 141 EXPECT_EQ(1u, fixture.changed_prefs()->size()); |
| 139 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary( | 142 ASSERT_TRUE(fixture.changed_prefs()->GetDictionary( |
| 140 prefs::kSupervisedUserManualHosts, &manual_hosts)); | 143 prefs::kSupervisedUserManualHosts, &manual_hosts)); |
| 141 EXPECT_TRUE(manual_hosts->Equals(dict.get())); | 144 EXPECT_TRUE(manual_hosts->Equals(dict.get())); |
| 142 | 145 |
| 143 // kForceGoogleSafeSearch and kForceYouTubeSafetyMode can be configured by the | 146 // kForceGoogleSafeSearch and kForceYouTubeRestrict can be configured by the |
| 144 // custodian, overriding the hardcoded default. | 147 // custodian, overriding the hardcoded default. |
| 145 fixture.changed_prefs()->Clear(); | 148 fixture.changed_prefs()->Clear(); |
| 146 service_.SetLocalSetting( | 149 service_.SetLocalSetting( |
| 147 supervised_users::kForceSafeSearch, | 150 supervised_users::kForceSafeSearch, |
| 148 std::unique_ptr<base::Value>(new base::FundamentalValue(false))); | 151 std::unique_ptr<base::Value>(new base::FundamentalValue(false))); |
| 149 EXPECT_EQ(1u, fixture.changed_prefs()->size()); | 152 EXPECT_EQ(1u, fixture.changed_prefs()->size()); |
| 150 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, | 153 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceGoogleSafeSearch, |
| 151 &force_google_safesearch)); | 154 &force_google_safesearch)); |
| 152 EXPECT_TRUE(fixture.changed_prefs()->GetBoolean( | 155 EXPECT_TRUE(fixture.changed_prefs()->GetInteger(prefs::kForceYouTubeRestrict, |
| 153 prefs::kForceYouTubeSafetyMode, &force_youtube_safety_mode)); | 156 &force_youtube_restrict)); |
| 154 EXPECT_FALSE(force_youtube_safety_mode); | |
| 155 EXPECT_FALSE(force_google_safesearch); | 157 EXPECT_FALSE(force_google_safesearch); |
| 158 EXPECT_EQ(force_youtube_restrict, |
| 159 static_cast<int>(safe_search_util::YouTubeRestrictMode::OFF)); |
| 156 } | 160 } |
| 157 | 161 |
| 158 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) { | 162 TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) { |
| 159 SupervisedUserPrefStoreFixture fixture(&service_); | 163 SupervisedUserPrefStoreFixture fixture(&service_); |
| 160 EXPECT_FALSE(fixture.initialization_completed()); | 164 EXPECT_FALSE(fixture.initialization_completed()); |
| 161 | 165 |
| 162 service_.SetActive(true); | 166 service_.SetActive(true); |
| 163 EXPECT_FALSE(fixture.initialization_completed()); | 167 EXPECT_FALSE(fixture.initialization_completed()); |
| 164 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 168 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
| 165 | 169 |
| 166 pref_store_->SetInitializationCompleted(); | 170 pref_store_->SetInitializationCompleted(); |
| 167 EXPECT_TRUE(fixture.initialization_completed()); | 171 EXPECT_TRUE(fixture.initialization_completed()); |
| 168 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 172 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
| 169 } | 173 } |
| 170 | 174 |
| 171 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) { | 175 TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) { |
| 172 pref_store_->SetInitializationCompleted(); | 176 pref_store_->SetInitializationCompleted(); |
| 173 service_.SetActive(true); | 177 service_.SetActive(true); |
| 174 | 178 |
| 175 SupervisedUserPrefStoreFixture fixture(&service_); | 179 SupervisedUserPrefStoreFixture fixture(&service_); |
| 176 EXPECT_TRUE(fixture.initialization_completed()); | 180 EXPECT_TRUE(fixture.initialization_completed()); |
| 177 EXPECT_EQ(0u, fixture.changed_prefs()->size()); | 181 EXPECT_EQ(0u, fixture.changed_prefs()->size()); |
| 178 } | 182 } |
| 179 | 183 |
| OLD | NEW |