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

Side by Side Diff: chrome/browser/prefs/chrome_pref_service_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/policy/configuration_policy_pref_store.h" 13 #include "chrome/browser/policy/configuration_policy_pref_store.h"
14 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
15 #include "chrome/browser/prefs/browser_prefs.h" 15 #include "chrome/browser/prefs/browser_prefs.h"
16 #include "chrome/browser/prefs/command_line_pref_store.h" 16 #include "chrome/browser/prefs/command_line_pref_store.h"
17 #include "chrome/browser/prefs/pref_service_mock_builder.h" 17 #include "chrome/browser/prefs/pref_service_mock_builder.h"
18 #include "chrome/browser/prefs/scoped_user_pref_update.h" 18 #include "chrome/browser/prefs/scoped_user_pref_update.h"
19 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/testing_pref_service_syncable.h" 23 #include "chrome/test/base/testing_pref_service_syncable.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "components/user_prefs/pref_registry_syncable.h" 25 #include "components/user_prefs/pref_registry_syncable.h"
26 #include "content/public/test/test_browser_thread.h"
27 #include "content/public/test/web_contents_tester.h" 26 #include "content/public/test/web_contents_tester.h"
28 #include "ui/base/test/data/resource.h" 27 #include "ui/base/test/data/resource.h"
29 #include "webkit/common/webpreferences.h" 28 #include "webkit/common/webpreferences.h"
30 29
31 using content::BrowserThread;
32 using content::WebContentsTester; 30 using content::WebContentsTester;
33 31
34 TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) { 32 TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) {
35 TestingPrefServiceSimple prefs; 33 TestingPrefServiceSimple prefs;
36 prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false); 34 prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false);
37 35
38 // Check to make sure the value is as expected. 36 // Check to make sure the value is as expected.
39 const PrefService::Preference* pref = 37 const PrefService::Preference* pref =
40 prefs.FindPreference(prefs::kCloudPrintProxyEnabled); 38 prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
41 ASSERT_TRUE(pref); 39 ASSERT_TRUE(pref);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 135
138 // Compare to expected output. 136 // Compare to expected output.
139 base::FilePath golden_output_file = 137 base::FilePath golden_output_file =
140 data_dir_.AppendASCII("write.golden.need_empty_value.json"); 138 data_dir_.AppendASCII("write.golden.need_empty_value.json");
141 ASSERT_TRUE(file_util::PathExists(golden_output_file)); 139 ASSERT_TRUE(file_util::PathExists(golden_output_file));
142 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); 140 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
143 } 141 }
144 142
145 class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness { 143 class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness {
146 protected: 144 protected:
147 ChromePrefServiceWebKitPrefs()
148 : ui_thread_(BrowserThread::UI, &message_loop_) {
149 }
150
151 virtual void SetUp() { 145 virtual void SetUp() {
152 ChromeRenderViewHostTestHarness::SetUp(); 146 ChromeRenderViewHostTestHarness::SetUp();
153 147
154 // Supply our own profile so we use the correct profile data. The test 148 // Supply our own profile so we use the correct profile data. The test
155 // harness is not supposed to overwrite a profile if it's already created. 149 // harness is not supposed to overwrite a profile if it's already created.
156 150
157 // Set some (WebKit) user preferences. 151 // Set some (WebKit) user preferences.
158 TestingPrefServiceSyncable* pref_services = 152 TestingPrefServiceSyncable* pref_services =
159 profile()->GetTestingPrefService(); 153 profile()->GetTestingPrefService();
160 #if defined(TOOLKIT_GTK) 154 #if defined(TOOLKIT_GTK)
161 pref_services->SetUserPref(prefs::kUsesSystemTheme, 155 pref_services->SetUserPref(prefs::kUsesSystemTheme,
162 Value::CreateBooleanValue(false)); 156 Value::CreateBooleanValue(false));
163 #endif 157 #endif
164 pref_services->SetUserPref(prefs::kDefaultCharset, 158 pref_services->SetUserPref(prefs::kDefaultCharset,
165 Value::CreateStringValue("utf8")); 159 Value::CreateStringValue("utf8"));
166 pref_services->SetUserPref(prefs::kWebKitDefaultFontSize, 160 pref_services->SetUserPref(prefs::kWebKitDefaultFontSize,
167 Value::CreateIntegerValue(20)); 161 Value::CreateIntegerValue(20));
168 pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable, 162 pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable,
169 Value::CreateBooleanValue(false)); 163 Value::CreateBooleanValue(false));
170 pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector, 164 pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector,
171 Value::CreateBooleanValue(true)); 165 Value::CreateBooleanValue(true));
172 pref_services->SetUserPref("webkit.webprefs.foo", 166 pref_services->SetUserPref("webkit.webprefs.foo",
173 Value::CreateStringValue("bar")); 167 Value::CreateStringValue("bar"));
174 } 168 }
175
176 private:
177 content::TestBrowserThread ui_thread_;
178 }; 169 };
179 170
180 // Tests to see that webkit preferences are properly loaded and copied over 171 // Tests to see that webkit preferences are properly loaded and copied over
181 // to a WebPreferences object. 172 // to a WebPreferences object.
182 TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) { 173 TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) {
183 WebPreferences webkit_prefs = 174 WebPreferences webkit_prefs =
184 WebContentsTester::For(web_contents())->TestGetWebkitPrefs(); 175 WebContentsTester::For(web_contents())->TestGetWebkitPrefs();
185 176
186 // These values have been overridden by the profile preferences. 177 // These values have been overridden by the profile preferences.
187 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding); 178 EXPECT_EQ("UTF-8", webkit_prefs.default_encoding);
188 EXPECT_EQ(20, webkit_prefs.default_font_size); 179 EXPECT_EQ(20, webkit_prefs.default_font_size);
189 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable); 180 EXPECT_FALSE(webkit_prefs.text_areas_are_resizable);
190 EXPECT_TRUE(webkit_prefs.uses_universal_detector); 181 EXPECT_TRUE(webkit_prefs.uses_universal_detector);
191 182
192 // These should still be the default values. 183 // These should still be the default values.
193 #if defined(OS_MACOSX) 184 #if defined(OS_MACOSX)
194 const char kDefaultFont[] = "Times"; 185 const char kDefaultFont[] = "Times";
195 #elif defined(OS_CHROMEOS) 186 #elif defined(OS_CHROMEOS)
196 const char kDefaultFont[] = "Tinos"; 187 const char kDefaultFont[] = "Tinos";
197 #else 188 #else
198 const char kDefaultFont[] = "Times New Roman"; 189 const char kDefaultFont[] = "Times New Roman";
199 #endif 190 #endif
200 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), 191 EXPECT_EQ(ASCIIToUTF16(kDefaultFont),
201 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]); 192 webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
202 EXPECT_TRUE(webkit_prefs.javascript_enabled); 193 EXPECT_TRUE(webkit_prefs.javascript_enabled);
203 } 194 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698