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

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

Issue 9251026: Reinitialize LocalState's CommandLinePrefStore after about_flags updates the command line. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/about_flags.h"
11 #include "chrome/browser/policy/configuration_policy_pref_store.h" 12 #include "chrome/browser/policy/configuration_policy_pref_store.h"
12 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 13 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
13 #include "chrome/browser/prefs/browser_prefs.h" 14 #include "chrome/browser/prefs/browser_prefs.h"
14 #include "chrome/browser/prefs/command_line_pref_store.h" 15 #include "chrome/browser/prefs/command_line_pref_store.h"
15 #include "chrome/browser/prefs/pref_change_registrar.h" 16 #include "chrome/browser/prefs/pref_change_registrar.h"
16 #include "chrome/browser/prefs/pref_observer_mock.h" 17 #include "chrome/browser/prefs/pref_observer_mock.h"
17 #include "chrome/browser/prefs/pref_service_mock_builder.h" 18 #include "chrome/browser/prefs/pref_service_mock_builder.h"
18 #include "chrome/browser/prefs/pref_value_store.h" 19 #include "chrome/browser/prefs/pref_value_store.h"
19 #include "chrome/browser/prefs/testing_pref_store.h" 20 #include "chrome/browser/prefs/testing_pref_store.h"
20 #include "chrome/common/chrome_paths.h" 21 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_switches.h" 22 #include "chrome/common/chrome_switches.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
24 #include "chrome/test/base/testing_pref_service.h" 25 #include "chrome/test/base/testing_pref_service.h"
25 #include "chrome/test/base/testing_pref_service.h"
26 #include "chrome/test/base/testing_profile.h" 26 #include "chrome/test/base/testing_profile.h"
27 #include "content/browser/tab_contents/test_tab_contents.h" 27 #include "content/browser/tab_contents/test_tab_contents.h"
28 #include "content/test/test_browser_thread.h" 28 #include "content/test/test_browser_thread.h"
29 #include "testing/gmock/include/gmock/gmock.h" 29 #include "testing/gmock/include/gmock/gmock.h"
30 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
31 #include "ui/base/test/data/resource.h" 31 #include "ui/base/test/data/resource.h"
32 32
33 using content::BrowserThread; 33 using content::BrowserThread;
34 using testing::_; 34 using testing::_;
35 using testing::Mock; 35 using testing::Mock;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 prefs.FindPreference(prefs::kStabilityLaunchCount); 143 prefs.FindPreference(prefs::kStabilityLaunchCount);
144 ASSERT_TRUE(pref); 144 ASSERT_TRUE(pref);
145 const Value* value = pref->GetValue(); 145 const Value* value = pref->GetValue();
146 ASSERT_TRUE(value); 146 ASSERT_TRUE(value);
147 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType()); 147 EXPECT_EQ(Value::TYPE_INTEGER, value->GetType());
148 int actual_int_value = -1; 148 int actual_int_value = -1;
149 EXPECT_TRUE(value->GetAsInteger(&actual_int_value)); 149 EXPECT_TRUE(value->GetAsInteger(&actual_int_value));
150 EXPECT_EQ(kTestValue, actual_int_value); 150 EXPECT_EQ(kTestValue, actual_int_value);
151 } 151 }
152 152
153 TEST(PrefServiceTest, UpdateCommandLinePrefStore) {
154 TestingPrefService prefs;
155 prefs.RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false);
156 const CommandLine::CharType* argv[] = { FILE_PATH_LITERAL("program") };
Nico 2012/01/19 00:39:18 I think the usual pattern is CommandLine command_
Lei Zhang 2012/01/19 01:10:29 Done.
157
158 // Check to make sure the value is as expected.
159 const PrefService::Preference* pref =
160 prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
161 ASSERT_TRUE(pref);
162 const Value* value = pref->GetValue();
163 ASSERT_TRUE(value);
164 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType());
165 bool actual_bool_value = true;
166 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
167 EXPECT_EQ(false, actual_bool_value);
168
169 // Change the command line.
170 CommandLine cmd_line(arraysize(argv), argv);
171 cmd_line.AppendSwitch(switches::kEnableCloudPrintProxy);
172 prefs.RegisterListPref(prefs::kEnabledLabsExperiments);
173 about_flags::ConvertFlagsToSwitches(&prefs, &cmd_line);
174
Nico 2012/01/19 00:39:18 Do you want to check if ConvertFlagsToSwiches() ad
Lei Zhang 2012/01/19 01:10:29 Actually, i don't need about_flags in this test, s
175 // Call UpdateCommandLinePrefStore and check to see if the value has changed.
176 prefs.UpdateCommandLinePrefStore(&cmd_line);
177 pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
178 ASSERT_TRUE(pref);
179 value = pref->GetValue();
180 ASSERT_TRUE(value);
181 EXPECT_EQ(Value::TYPE_BOOLEAN, value->GetType());
182 actual_bool_value = false;
183 EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
184 EXPECT_EQ(true, actual_bool_value);
185 }
186
153 class PrefServiceSetValueTest : public testing::Test { 187 class PrefServiceSetValueTest : public testing::Test {
154 protected: 188 protected:
155 static const char kName[]; 189 static const char kName[];
156 static const char kValue[]; 190 static const char kValue[];
157 191
158 TestingPrefService prefs_; 192 TestingPrefService prefs_;
159 PrefObserverMock observer_; 193 PrefObserverMock observer_;
160 }; 194 };
161 195
162 const char PrefServiceSetValueTest::kName[] = "name"; 196 const char PrefServiceSetValueTest::kName[] = "name";
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 #if defined(OS_MACOSX) 320 #if defined(OS_MACOSX)
287 const char kDefaultFont[] = "Times"; 321 const char kDefaultFont[] = "Times";
288 #elif defined(OS_CHROMEOS) 322 #elif defined(OS_CHROMEOS)
289 const char kDefaultFont[] = "Tinos"; 323 const char kDefaultFont[] = "Tinos";
290 #else 324 #else
291 const char kDefaultFont[] = "Times New Roman"; 325 const char kDefaultFont[] = "Times New Roman";
292 #endif 326 #endif
293 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), webkit_prefs.standard_font_family); 327 EXPECT_EQ(ASCIIToUTF16(kDefaultFont), webkit_prefs.standard_font_family);
294 EXPECT_TRUE(webkit_prefs.javascript_enabled); 328 EXPECT_TRUE(webkit_prefs.javascript_enabled);
295 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698