| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 using content::WebContentsTester; | 30 using content::WebContentsTester; |
| 31 | 31 |
| 32 TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) { | 32 TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) { |
| 33 TestingPrefServiceSimple prefs; | 33 TestingPrefServiceSimple prefs; |
| 34 prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false); | 34 prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false); |
| 35 | 35 |
| 36 // Check to make sure the value is as expected. | 36 // Check to make sure the value is as expected. |
| 37 const PrefService::Preference* pref = | 37 const PrefService::Preference* pref = |
| 38 prefs.FindPreference(prefs::kCloudPrintProxyEnabled); | 38 prefs.FindPreference(prefs::kCloudPrintProxyEnabled); |
| 39 ASSERT_TRUE(pref); | 39 ASSERT_TRUE(pref); |
| 40 const Value* value = pref->GetValue(); | 40 const base::Value* value = pref->GetValue(); |
| 41 ASSERT_TRUE(value); | 41 ASSERT_TRUE(value); |
| 42 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 42 EXPECT_EQ(base::Value::TYPE_BOOLEAN, value->GetType()); |
| 43 bool actual_bool_value = true; | 43 bool actual_bool_value = true; |
| 44 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); | 44 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); |
| 45 EXPECT_FALSE(actual_bool_value); | 45 EXPECT_FALSE(actual_bool_value); |
| 46 | 46 |
| 47 // Change the command line. | 47 // Change the command line. |
| 48 CommandLine cmd_line(CommandLine::NO_PROGRAM); | 48 CommandLine cmd_line(CommandLine::NO_PROGRAM); |
| 49 cmd_line.AppendSwitch(switches::kEnableCloudPrintProxy); | 49 cmd_line.AppendSwitch(switches::kEnableCloudPrintProxy); |
| 50 | 50 |
| 51 // Call UpdateCommandLinePrefStore and check to see if the value has changed. | 51 // Call UpdateCommandLinePrefStore and check to see if the value has changed. |
| 52 prefs.UpdateCommandLinePrefStore(new CommandLinePrefStore(&cmd_line)); | 52 prefs.UpdateCommandLinePrefStore(new CommandLinePrefStore(&cmd_line)); |
| 53 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); | 53 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled); |
| 54 ASSERT_TRUE(pref); | 54 ASSERT_TRUE(pref); |
| 55 value = pref->GetValue(); | 55 value = pref->GetValue(); |
| 56 ASSERT_TRUE(value); | 56 ASSERT_TRUE(value); |
| 57 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType()); | 57 EXPECT_EQ(base::Value::TYPE_BOOLEAN, value->GetType()); |
| 58 actual_bool_value = false; | 58 actual_bool_value = false; |
| 59 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); | 59 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value)); |
| 60 EXPECT_TRUE(actual_bool_value); | 60 EXPECT_TRUE(actual_bool_value); |
| 61 } | 61 } |
| 62 | 62 |
| 63 class ChromePrefServiceUserFilePrefsTest : public testing::Test { | 63 class ChromePrefServiceUserFilePrefsTest : public testing::Test { |
| 64 protected: | 64 protected: |
| 65 virtual void SetUp() { | 65 virtual void SetUp() { |
| 66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 66 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 67 | 67 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 94 ChromeRenderViewHostTestHarness::SetUp(); | 94 ChromeRenderViewHostTestHarness::SetUp(); |
| 95 | 95 |
| 96 // Supply our own profile so we use the correct profile data. The test | 96 // Supply our own profile so we use the correct profile data. The test |
| 97 // harness is not supposed to overwrite a profile if it's already created. | 97 // harness is not supposed to overwrite a profile if it's already created. |
| 98 | 98 |
| 99 // Set some (WebKit) user preferences. | 99 // Set some (WebKit) user preferences. |
| 100 TestingPrefServiceSyncable* pref_services = | 100 TestingPrefServiceSyncable* pref_services = |
| 101 profile()->GetTestingPrefService(); | 101 profile()->GetTestingPrefService(); |
| 102 #if defined(TOOLKIT_GTK) | 102 #if defined(TOOLKIT_GTK) |
| 103 pref_services->SetUserPref(prefs::kUsesSystemTheme, | 103 pref_services->SetUserPref(prefs::kUsesSystemTheme, |
| 104 Value::CreateBooleanValue(false)); | 104 base::Value::CreateBooleanValue(false)); |
| 105 #endif | 105 #endif |
| 106 pref_services->SetUserPref(prefs::kDefaultCharset, | 106 pref_services->SetUserPref(prefs::kDefaultCharset, |
| 107 Value::CreateStringValue("utf8")); | 107 base::Value::CreateStringValue("utf8")); |
| 108 pref_services->SetUserPref(prefs::kWebKitDefaultFontSize, | 108 pref_services->SetUserPref(prefs::kWebKitDefaultFontSize, |
| 109 Value::CreateIntegerValue(20)); | 109 base::Value::CreateIntegerValue(20)); |
| 110 pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable, | 110 pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable, |
| 111 Value::CreateBooleanValue(false)); | 111 base::Value::CreateBooleanValue(false)); |
| 112 pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector, | 112 pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector, |
| 113 Value::CreateBooleanValue(true)); | 113 base::Value::CreateBooleanValue(true)); |
| 114 pref_services->SetUserPref("webkit.webprefs.foo", | 114 pref_services->SetUserPref("webkit.webprefs.foo", |
| 115 Value::CreateStringValue("bar")); | 115 base::Value::CreateStringValue("bar")); |
| 116 } | 116 } |
| 117 }; | 117 }; |
| 118 | 118 |
| 119 // Tests to see that webkit preferences are properly loaded and copied over | 119 // Tests to see that webkit preferences are properly loaded and copied over |
| 120 // to a WebPreferences object. | 120 // to a WebPreferences object. |
| 121 TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) { | 121 TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) { |
| 122 WebPreferences webkit_prefs = | 122 WebPreferences webkit_prefs = |
| 123 WebContentsTester::For(web_contents())->TestGetWebkitPrefs(); | 123 WebContentsTester::For(web_contents())->TestGetWebkitPrefs(); |
| 124 | 124 |
| 125 // These values have been overridden by the profile preferences. | 125 // These values have been overridden by the profile preferences. |
| 126 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding); | 126 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding); |
| 127 EXPECT_EQ(20, webkit_prefs.default_font_size); | 127 EXPECT_EQ(20, webkit_prefs.default_font_size); |
| 128 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable); | 128 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable); |
| 129 EXPECT_TRUE(webkit_prefs.uses_universal_detector); | 129 EXPECT_TRUE(webkit_prefs.uses_universal_detector); |
| 130 | 130 |
| 131 // These should still be the default values. | 131 // These should still be the default values. |
| 132 #if defined(OS_MACOSX) | 132 #if defined(OS_MACOSX) |
| 133 const char kDefaultFont[] = "Times"; | 133 const char kDefaultFont[] = "Times"; |
| 134 #elif defined(OS_CHROMEOS) | 134 #elif defined(OS_CHROMEOS) |
| 135 const char kDefaultFont[] = "Tinos"; | 135 const char kDefaultFont[] = "Tinos"; |
| 136 #else | 136 #else |
| 137 const char kDefaultFont[] = "Times New Roman"; | 137 const char kDefaultFont[] = "Times New Roman"; |
| 138 #endif | 138 #endif |
| 139 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), | 139 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), |
| 140 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); | 140 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); |
| 141 EXPECT_TRUE(webkit_prefs.javascript_enabled); | 141 EXPECT_TRUE(webkit_prefs.javascript_enabled); |
| 142 } | 142 } |
| OLD | NEW |