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

Side by Side Diff: chrome/browser/policy/configuration_policy_pref_store_unittest.cc

Issue 8395044: Disable the Developer Tools when Javascript is disabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed unit_tests, added some more tests Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "chrome/browser/policy/configuration_policy_pref_store.h" 7 #include "chrome/browser/policy/configuration_policy_pref_store.h"
8 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 8 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
9 #include "chrome/browser/prefs/incognito_mode_prefs.h" 9 #include "chrome/browser/prefs/incognito_mode_prefs.h"
10 #include "chrome/browser/prefs/proxy_config_dictionary.h" 10 #include "chrome/browser/prefs/proxy_config_dictionary.h"
11 #include "chrome/common/content_settings.h"
11 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
12 #include "chrome/common/pref_store_observer_mock.h" 13 #include "chrome/common/pref_store_observer_mock.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 using testing::_; 17 using testing::_;
17 using testing::Mock; 18 using testing::Mock;
18 19
19 namespace policy { 20 namespace policy {
20 21
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 TypeAndName(kPolicyMetricsReportingEnabled, 198 TypeAndName(kPolicyMetricsReportingEnabled,
198 prefs::kMetricsReportingEnabled), 199 prefs::kMetricsReportingEnabled),
199 TypeAndName(kPolicyPasswordManagerEnabled, 200 TypeAndName(kPolicyPasswordManagerEnabled,
200 prefs::kPasswordManagerEnabled), 201 prefs::kPasswordManagerEnabled),
201 TypeAndName(kPolicyPasswordManagerAllowShowPasswords, 202 TypeAndName(kPolicyPasswordManagerAllowShowPasswords,
202 prefs::kPasswordManagerAllowShowPasswords), 203 prefs::kPasswordManagerAllowShowPasswords),
203 TypeAndName(kPolicyShowHomeButton, 204 TypeAndName(kPolicyShowHomeButton,
204 prefs::kShowHomeButton), 205 prefs::kShowHomeButton),
205 TypeAndName(kPolicyPrintingEnabled, 206 TypeAndName(kPolicyPrintingEnabled,
206 prefs::kPrintingEnabled), 207 prefs::kPrintingEnabled),
207 TypeAndName(kPolicyJavascriptEnabled,
208 prefs::kWebKitJavascriptEnabled),
209 TypeAndName(kPolicyRemoteAccessHostFirewallTraversal, 208 TypeAndName(kPolicyRemoteAccessHostFirewallTraversal,
210 prefs::kRemoteAccessHostFirewallTraversal), 209 prefs::kRemoteAccessHostFirewallTraversal),
211 TypeAndName(kPolicyCloudPrintProxyEnabled, 210 TypeAndName(kPolicyCloudPrintProxyEnabled,
212 prefs::kCloudPrintProxyEnabled), 211 prefs::kCloudPrintProxyEnabled),
213 TypeAndName(kPolicyCloudPrintSubmitEnabled, 212 TypeAndName(kPolicyCloudPrintSubmitEnabled,
214 prefs::kCloudPrintSubmitEnabled), 213 prefs::kCloudPrintSubmitEnabled),
215 TypeAndName(kPolicySavingBrowserHistoryDisabled, 214 TypeAndName(kPolicySavingBrowserHistoryDisabled,
216 prefs::kSavingBrowserHistoryDisabled), 215 prefs::kSavingBrowserHistoryDisabled),
217 TypeAndName(kPolicySavingBrowserHistoryDisabled, 216 TypeAndName(kPolicySavingBrowserHistoryDisabled,
218 prefs::kSavingBrowserHistoryDisabled), 217 prefs::kSavingBrowserHistoryDisabled),
(...skipping 27 matching lines...) Expand all
246 prefs::kAllowCrossOriginAuthPrompt), 245 prefs::kAllowCrossOriginAuthPrompt),
247 TypeAndName(kPolicyImportBookmarks, 246 TypeAndName(kPolicyImportBookmarks,
248 prefs::kImportBookmarks), 247 prefs::kImportBookmarks),
249 TypeAndName(kPolicyImportHistory, 248 TypeAndName(kPolicyImportHistory,
250 prefs::kImportHistory), 249 prefs::kImportHistory),
251 TypeAndName(kPolicyImportHomepage, 250 TypeAndName(kPolicyImportHomepage,
252 prefs::kImportHomepage), 251 prefs::kImportHomepage),
253 TypeAndName(kPolicyImportSearchEngine, 252 TypeAndName(kPolicyImportSearchEngine,
254 prefs::kImportSearchEngine), 253 prefs::kImportSearchEngine),
255 TypeAndName(kPolicyImportSavedPasswords, 254 TypeAndName(kPolicyImportSavedPasswords,
256 prefs::kImportSavedPasswords))); 255 prefs::kImportSavedPasswords),
256 TypeAndName(kPolicyDeveloperToolsDisabled,
257 prefs::kDevToolsDisabled)));
257 258
258 #if defined(OS_CHROMEOS) 259 #if defined(OS_CHROMEOS)
259 INSTANTIATE_TEST_CASE_P( 260 INSTANTIATE_TEST_CASE_P(
260 CrosConfigurationPolicyPrefStoreBooleanTestInstance, 261 CrosConfigurationPolicyPrefStoreBooleanTestInstance,
261 ConfigurationPolicyPrefStoreBooleanTest, 262 ConfigurationPolicyPrefStoreBooleanTest,
262 testing::Values( 263 testing::Values(
263 TypeAndName(kPolicyChromeOsLockOnIdleSuspend, 264 TypeAndName(kPolicyChromeOsLockOnIdleSuspend,
264 prefs::kEnableScreenLock))); 265 prefs::kEnableScreenLock)));
265 #endif // defined(OS_CHROMEOS) 266 #endif // defined(OS_CHROMEOS)
266 267
(...skipping 14 matching lines...) Expand all
281 const Value* value = NULL; 282 const Value* value = NULL;
282 EXPECT_EQ(PrefStore::READ_OK, 283 EXPECT_EQ(PrefStore::READ_OK,
283 store_->GetValue(GetParam().pref_name(), &value)); 284 store_->GetValue(GetParam().pref_name(), &value));
284 EXPECT_TRUE(base::FundamentalValue(2).Equals(value)); 285 EXPECT_TRUE(base::FundamentalValue(2).Equals(value));
285 } 286 }
286 287
287 INSTANTIATE_TEST_CASE_P( 288 INSTANTIATE_TEST_CASE_P(
288 ConfigurationPolicyPrefStoreIntegerTestInstance, 289 ConfigurationPolicyPrefStoreIntegerTestInstance,
289 ConfigurationPolicyPrefStoreIntegerTest, 290 ConfigurationPolicyPrefStoreIntegerTest,
290 testing::Values( 291 testing::Values(
292 TypeAndName(kPolicyDefaultCookiesSetting,
293 prefs::kManagedDefaultCookiesSetting),
294 TypeAndName(kPolicyDefaultImagesSetting,
295 prefs::kManagedDefaultImagesSetting),
296 TypeAndName(kPolicyDefaultPluginsSetting,
297 prefs::kManagedDefaultPluginsSetting),
298 TypeAndName(kPolicyDefaultPopupsSetting,
299 prefs::kManagedDefaultPopupsSetting),
300 TypeAndName(kPolicyDefaultNotificationsSetting,
301 prefs::kManagedDefaultNotificationsSetting),
302 TypeAndName(kPolicyDefaultGeolocationSetting,
303 prefs::kManagedDefaultGeolocationSetting),
Mattias Nissler (ping if slow) 2011/11/03 18:42:02 Why did you remove all these?
Joao da Silva 2011/11/03 20:46:55 What do you mean? I'm adding these now since they
291 TypeAndName(kPolicyRestoreOnStartup, 304 TypeAndName(kPolicyRestoreOnStartup,
292 prefs::kRestoreOnStartup), 305 prefs::kRestoreOnStartup),
293 TypeAndName(kPolicyPolicyRefreshRate, 306 TypeAndName(kPolicyPolicyRefreshRate,
294 prefs::kUserPolicyRefreshRate), 307 prefs::kUserPolicyRefreshRate),
295 TypeAndName(kPolicyMaxConnectionsPerProxy, 308 TypeAndName(kPolicyMaxConnectionsPerProxy,
296 prefs::kMaxConnectionsPerProxy))); 309 prefs::kMaxConnectionsPerProxy)));
297 310
298 // Test cases for the proxy policy settings. 311 // Test cases for the proxy policy settings.
299 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test { 312 class ConfigurationPolicyPrefStoreProxyTest : public testing::Test {
300 protected: 313 protected:
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 EXPECT_FALSE(prompt_for_download); 908 EXPECT_FALSE(prompt_for_download);
896 } 909 }
897 910
898 // Test cases for the Autofill policy setting. 911 // Test cases for the Autofill policy setting.
899 class ConfigurationPolicyPrefStoreAutofillTest 912 class ConfigurationPolicyPrefStoreAutofillTest
900 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> { 913 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
901 }; 914 };
902 915
903 TEST_F(ConfigurationPolicyPrefStoreAutofillTest, Default) { 916 TEST_F(ConfigurationPolicyPrefStoreAutofillTest, Default) {
904 EXPECT_EQ(PrefStore::READ_NO_VALUE, 917 EXPECT_EQ(PrefStore::READ_NO_VALUE,
905 store_->GetValue(prefs::kSyncManaged, NULL)); 918 store_->GetValue(prefs::kAutofillEnabled, NULL));
Mattias Nissler (ping if slow) 2011/11/03 18:42:02 good catches!
Joao da Silva 2011/11/03 20:46:55 Hopefully the test still passes!
906 } 919 }
907 920
908 TEST_F(ConfigurationPolicyPrefStoreAutofillTest, Enabled) { 921 TEST_F(ConfigurationPolicyPrefStoreAutofillTest, Enabled) {
909 provider_.AddPolicy(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true)); 922 provider_.AddPolicy(kPolicyAutoFillEnabled, Value::CreateBooleanValue(true));
910 store_->OnUpdatePolicy(); 923 store_->OnUpdatePolicy();
911 // Enabling Autofill should not set the pref. 924 // Enabling Autofill should not set the pref.
912 EXPECT_EQ(PrefStore::READ_NO_VALUE, 925 EXPECT_EQ(PrefStore::READ_NO_VALUE,
913 store_->GetValue(prefs::kSyncManaged, NULL)); 926 store_->GetValue(prefs::kAutofillEnabled, NULL));
914 } 927 }
915 928
916 TEST_F(ConfigurationPolicyPrefStoreAutofillTest, Disabled) { 929 TEST_F(ConfigurationPolicyPrefStoreAutofillTest, Disabled) {
917 provider_.AddPolicy(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false)); 930 provider_.AddPolicy(kPolicyAutoFillEnabled, Value::CreateBooleanValue(false));
918 store_->OnUpdatePolicy(); 931 store_->OnUpdatePolicy();
919 // Disabling Autofill should switch the pref to managed. 932 // Disabling Autofill should switch the pref to managed.
920 const Value* value = NULL; 933 const Value* value = NULL;
921 EXPECT_EQ(PrefStore::READ_OK, 934 EXPECT_EQ(PrefStore::READ_OK,
922 store_->GetValue(prefs::kAutofillEnabled, &value)); 935 store_->GetValue(prefs::kAutofillEnabled, &value));
923 ASSERT_TRUE(value); 936 ASSERT_TRUE(value);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 EXPECT_CALL(observer_, OnInitializationCompleted(true)).Times(1); 987 EXPECT_CALL(observer_, OnInitializationCompleted(true)).Times(1);
975 988
976 provider_.SetInitializationComplete(true); 989 provider_.SetInitializationComplete(true);
977 EXPECT_FALSE(store_->IsInitializationComplete()); 990 EXPECT_FALSE(store_->IsInitializationComplete());
978 991
979 store_->OnUpdatePolicy(); 992 store_->OnUpdatePolicy();
980 Mock::VerifyAndClearExpectations(&observer_); 993 Mock::VerifyAndClearExpectations(&observer_);
981 EXPECT_TRUE(store_->IsInitializationComplete()); 994 EXPECT_TRUE(store_->IsInitializationComplete());
982 } 995 }
983 996
997 // Tests for policies that don't quite fit the previous patterns.
998 class ConfigurationPolicyPrefStoreOthersTest
999 : public ConfigurationPolicyPrefStoreTestBase<testing::Test> {
1000 };
1001
1002 TEST_F(ConfigurationPolicyPrefStoreOthersTest, JavascriptEnabled) {
1003 // This is a boolean policy, but affects an integer preference.
1004 EXPECT_EQ(PrefStore::READ_NO_VALUE,
1005 store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL));
1006 provider_.AddPolicy(kPolicyJavascriptEnabled,
1007 Value::CreateBooleanValue(true));
1008 store_->OnUpdatePolicy();
1009 EXPECT_EQ(PrefStore::READ_NO_VALUE,
1010 store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL));
1011 provider_.AddPolicy(kPolicyJavascriptEnabled,
1012 Value::CreateBooleanValue(false));
1013 store_->OnUpdatePolicy();
1014 const Value* value = NULL;
1015 EXPECT_EQ(PrefStore::READ_OK,
1016 store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, &value));
1017 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK).Equals(value));
1018 }
1019
1020 TEST_F(ConfigurationPolicyPrefStoreOthersTest, JavascriptEnabledOverrides) {
1021 EXPECT_EQ(PrefStore::READ_NO_VALUE,
1022 store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, NULL));
1023 provider_.AddPolicy(kPolicyDefaultJavaScriptSetting,
1024 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW));
1025 store_->OnUpdatePolicy();
1026 const Value* value = NULL;
1027 EXPECT_EQ(PrefStore::READ_OK,
1028 store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, &value));
1029 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_ALLOW).Equals(value));
1030 // JavascriptEnabled overrides DefaultJavaScriptSetting.
1031 provider_.AddPolicy(kPolicyJavascriptEnabled,
1032 Value::CreateBooleanValue(false));
1033 store_->OnUpdatePolicy();
1034 EXPECT_EQ(PrefStore::READ_OK,
1035 store_->GetValue(prefs::kManagedDefaultJavaScriptSetting, &value));
1036 EXPECT_TRUE(base::FundamentalValue(CONTENT_SETTING_BLOCK).Equals(value));
1037 }
1038
984 } // namespace policy 1039 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698