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

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

Issue 388963002: Get rid of the rest of CreateStringValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad rebase Created 6 years, 5 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) 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/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/prefs/scoped_user_pref_update.h" 6 #include "base/prefs/scoped_user_pref_update.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "chrome/browser/prefs/pref_model_associator.h" 8 #include "chrome/browser/prefs/pref_model_associator.h"
9 #include "chrome/common/pref_names.h" 9 #include "chrome/common/pref_names.h"
10 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 class ListPreferenceMergeTest : public AbstractPreferenceMergeTest { 55 class ListPreferenceMergeTest : public AbstractPreferenceMergeTest {
56 protected: 56 protected:
57 ListPreferenceMergeTest() : 57 ListPreferenceMergeTest() :
58 server_url0_("http://example.com/server0"), 58 server_url0_("http://example.com/server0"),
59 server_url1_("http://example.com/server1"), 59 server_url1_("http://example.com/server1"),
60 local_url0_("http://example.com/local0"), 60 local_url0_("http://example.com/local0"),
61 local_url1_("http://example.com/local1") {} 61 local_url1_("http://example.com/local1") {}
62 62
63 virtual void SetUp() { 63 virtual void SetUp() {
64 AbstractPreferenceMergeTest::SetUp(); 64 AbstractPreferenceMergeTest::SetUp();
65 server_url_list_.Append(base::Value::CreateStringValue(server_url0_)); 65 server_url_list_.Append(new base::StringValue(server_url0_));
66 server_url_list_.Append(base::Value::CreateStringValue(server_url1_)); 66 server_url_list_.Append(new base::StringValue(server_url1_));
67 } 67 }
68 68
69 std::string server_url0_; 69 std::string server_url0_;
70 std::string server_url1_; 70 std::string server_url1_;
71 std::string local_url0_; 71 std::string local_url0_;
72 std::string local_url1_; 72 std::string local_url1_;
73 base::ListValue server_url_list_; 73 base::ListValue server_url_list_;
74 }; 74 };
75 75
76 TEST_F(ListPreferenceMergeTest, NotListOrDictionary) { 76 TEST_F(ListPreferenceMergeTest, NotListOrDictionary) {
77 pref_service_->SetString(prefs::kHomePage, local_url0_); 77 pref_service_->SetString(prefs::kHomePage, local_url0_);
78 const PrefService::Preference* pref = 78 const PrefService::Preference* pref =
79 pref_service_->FindPreference(prefs::kHomePage); 79 pref_service_->FindPreference(prefs::kHomePage);
80 scoped_ptr<base::Value> server_value( 80 scoped_ptr<base::Value> server_value(new base::StringValue(server_url0_));
81 base::Value::CreateStringValue(server_url0_));
82 scoped_ptr<base::Value> merged_value( 81 scoped_ptr<base::Value> merged_value(
83 PrefModelAssociator::MergePreference(pref->name(), 82 PrefModelAssociator::MergePreference(pref->name(),
84 *pref->GetValue(), 83 *pref->GetValue(),
85 *server_value)); 84 *server_value));
86 EXPECT_TRUE(merged_value->Equals(server_value.get())); 85 EXPECT_TRUE(merged_value->Equals(server_value.get()));
87 } 86 }
88 87
89 TEST_F(ListPreferenceMergeTest, LocalEmpty) { 88 TEST_F(ListPreferenceMergeTest, LocalEmpty) {
90 SetPrefToEmpty(prefs::kURLsToRestoreOnStartup); 89 SetPrefToEmpty(prefs::kURLsToRestoreOnStartup);
91 const PrefService::Preference* pref = 90 const PrefService::Preference* pref =
92 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup); 91 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup);
93 scoped_ptr<base::Value> merged_value( 92 scoped_ptr<base::Value> merged_value(
94 PrefModelAssociator::MergePreference(pref->name(), 93 PrefModelAssociator::MergePreference(pref->name(),
95 *pref->GetValue(), 94 *pref->GetValue(),
96 server_url_list_)); 95 server_url_list_));
97 EXPECT_TRUE(merged_value->Equals(&server_url_list_)); 96 EXPECT_TRUE(merged_value->Equals(&server_url_list_));
98 } 97 }
99 98
100 TEST_F(ListPreferenceMergeTest, ServerNull) { 99 TEST_F(ListPreferenceMergeTest, ServerNull) {
101 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue()); 100 scoped_ptr<base::Value> null_value(base::Value::CreateNullValue());
102 { 101 {
103 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup); 102 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup);
104 base::ListValue* local_list_value = update.Get(); 103 base::ListValue* local_list_value = update.Get();
105 local_list_value->Append(base::Value::CreateStringValue(local_url0_)); 104 local_list_value->Append(new base::StringValue(local_url0_));
106 } 105 }
107 106
108 const PrefService::Preference* pref = 107 const PrefService::Preference* pref =
109 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup); 108 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup);
110 scoped_ptr<base::Value> merged_value( 109 scoped_ptr<base::Value> merged_value(
111 PrefModelAssociator::MergePreference(pref->name(), 110 PrefModelAssociator::MergePreference(pref->name(),
112 *pref->GetValue(), 111 *pref->GetValue(),
113 *null_value)); 112 *null_value));
114 const base::ListValue* local_list_value = 113 const base::ListValue* local_list_value =
115 pref_service_->GetList(prefs::kURLsToRestoreOnStartup); 114 pref_service_->GetList(prefs::kURLsToRestoreOnStartup);
116 EXPECT_TRUE(merged_value->Equals(local_list_value)); 115 EXPECT_TRUE(merged_value->Equals(local_list_value));
117 } 116 }
118 117
119 TEST_F(ListPreferenceMergeTest, ServerEmpty) { 118 TEST_F(ListPreferenceMergeTest, ServerEmpty) {
120 scoped_ptr<base::Value> empty_value(new base::ListValue); 119 scoped_ptr<base::Value> empty_value(new base::ListValue);
121 { 120 {
122 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup); 121 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup);
123 base::ListValue* local_list_value = update.Get(); 122 base::ListValue* local_list_value = update.Get();
124 local_list_value->Append(base::Value::CreateStringValue(local_url0_)); 123 local_list_value->Append(new base::StringValue(local_url0_));
125 } 124 }
126 125
127 const PrefService::Preference* pref = 126 const PrefService::Preference* pref =
128 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup); 127 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup);
129 scoped_ptr<base::Value> merged_value( 128 scoped_ptr<base::Value> merged_value(
130 PrefModelAssociator::MergePreference(pref->name(), 129 PrefModelAssociator::MergePreference(pref->name(),
131 *pref->GetValue(), 130 *pref->GetValue(),
132 *empty_value)); 131 *empty_value));
133 const base::ListValue* local_list_value = 132 const base::ListValue* local_list_value =
134 pref_service_->GetList(prefs::kURLsToRestoreOnStartup); 133 pref_service_->GetList(prefs::kURLsToRestoreOnStartup);
135 EXPECT_TRUE(merged_value->Equals(local_list_value)); 134 EXPECT_TRUE(merged_value->Equals(local_list_value));
136 } 135 }
137 136
138 TEST_F(ListPreferenceMergeTest, Merge) { 137 TEST_F(ListPreferenceMergeTest, Merge) {
139 { 138 {
140 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup); 139 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup);
141 base::ListValue* local_list_value = update.Get(); 140 base::ListValue* local_list_value = update.Get();
142 local_list_value->Append(base::Value::CreateStringValue(local_url0_)); 141 local_list_value->Append(new base::StringValue(local_url0_));
143 local_list_value->Append(base::Value::CreateStringValue(local_url1_)); 142 local_list_value->Append(new base::StringValue(local_url1_));
144 } 143 }
145 144
146 const PrefService::Preference* pref = 145 const PrefService::Preference* pref =
147 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup); 146 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup);
148 scoped_ptr<base::Value> merged_value( 147 scoped_ptr<base::Value> merged_value(
149 PrefModelAssociator::MergePreference(pref->name(), 148 PrefModelAssociator::MergePreference(pref->name(),
150 *pref->GetValue(), 149 *pref->GetValue(),
151 server_url_list_)); 150 server_url_list_));
152 151
153 base::ListValue expected; 152 base::ListValue expected;
154 expected.Append(base::Value::CreateStringValue(server_url0_)); 153 expected.Append(new base::StringValue(server_url0_));
155 expected.Append(base::Value::CreateStringValue(server_url1_)); 154 expected.Append(new base::StringValue(server_url1_));
156 expected.Append(base::Value::CreateStringValue(local_url0_)); 155 expected.Append(new base::StringValue(local_url0_));
157 expected.Append(base::Value::CreateStringValue(local_url1_)); 156 expected.Append(new base::StringValue(local_url1_));
158 EXPECT_TRUE(merged_value->Equals(&expected)); 157 EXPECT_TRUE(merged_value->Equals(&expected));
159 } 158 }
160 159
161 TEST_F(ListPreferenceMergeTest, Duplicates) { 160 TEST_F(ListPreferenceMergeTest, Duplicates) {
162 { 161 {
163 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup); 162 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup);
164 base::ListValue* local_list_value = update.Get(); 163 base::ListValue* local_list_value = update.Get();
165 local_list_value->Append(base::Value::CreateStringValue(local_url0_)); 164 local_list_value->Append(new base::StringValue(local_url0_));
166 local_list_value->Append(base::Value::CreateStringValue(server_url0_)); 165 local_list_value->Append(new base::StringValue(server_url0_));
167 local_list_value->Append(base::Value::CreateStringValue(server_url1_)); 166 local_list_value->Append(new base::StringValue(server_url1_));
168 } 167 }
169 168
170 const PrefService::Preference* pref = 169 const PrefService::Preference* pref =
171 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup); 170 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup);
172 scoped_ptr<base::Value> merged_value( 171 scoped_ptr<base::Value> merged_value(
173 PrefModelAssociator::MergePreference(pref->name(), 172 PrefModelAssociator::MergePreference(pref->name(),
174 *pref->GetValue(), 173 *pref->GetValue(),
175 server_url_list_)); 174 server_url_list_));
176 175
177 base::ListValue expected; 176 base::ListValue expected;
178 expected.Append(base::Value::CreateStringValue(server_url0_)); 177 expected.Append(new base::StringValue(server_url0_));
179 expected.Append(base::Value::CreateStringValue(server_url1_)); 178 expected.Append(new base::StringValue(server_url1_));
180 expected.Append(base::Value::CreateStringValue(local_url0_)); 179 expected.Append(new base::StringValue(local_url0_));
181 EXPECT_TRUE(merged_value->Equals(&expected)); 180 EXPECT_TRUE(merged_value->Equals(&expected));
182 } 181 }
183 182
184 TEST_F(ListPreferenceMergeTest, Equals) { 183 TEST_F(ListPreferenceMergeTest, Equals) {
185 { 184 {
186 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup); 185 ListPrefUpdate update(pref_service_, prefs::kURLsToRestoreOnStartup);
187 base::ListValue* local_list_value = update.Get(); 186 base::ListValue* local_list_value = update.Get();
188 local_list_value->Append(base::Value::CreateStringValue(server_url0_)); 187 local_list_value->Append(new base::StringValue(server_url0_));
189 local_list_value->Append(base::Value::CreateStringValue(server_url1_)); 188 local_list_value->Append(new base::StringValue(server_url1_));
190 } 189 }
191 190
192 scoped_ptr<base::Value> original(server_url_list_.DeepCopy()); 191 scoped_ptr<base::Value> original(server_url_list_.DeepCopy());
193 const PrefService::Preference* pref = 192 const PrefService::Preference* pref =
194 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup); 193 pref_service_->FindPreference(prefs::kURLsToRestoreOnStartup);
195 scoped_ptr<base::Value> merged_value( 194 scoped_ptr<base::Value> merged_value(
196 PrefModelAssociator::MergePreference(pref->name(), 195 PrefModelAssociator::MergePreference(pref->name(),
197 *pref->GetValue(), 196 *pref->GetValue(),
198 server_url_list_)); 197 server_url_list_));
199 EXPECT_TRUE(merged_value->Equals(original.get())); 198 EXPECT_TRUE(merged_value->Equals(original.get()));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 protected: 361 protected:
363 IndividualPreferenceMergeTest() : 362 IndividualPreferenceMergeTest() :
364 url0_("http://example.com/server0"), 363 url0_("http://example.com/server0"),
365 url1_("http://example.com/server1"), 364 url1_("http://example.com/server1"),
366 expression0_("expression0"), 365 expression0_("expression0"),
367 expression1_("expression1"), 366 expression1_("expression1"),
368 content_type0_("content_type0") {} 367 content_type0_("content_type0") {}
369 368
370 virtual void SetUp() { 369 virtual void SetUp() {
371 AbstractPreferenceMergeTest::SetUp(); 370 AbstractPreferenceMergeTest::SetUp();
372 server_url_list_.Append(base::Value::CreateStringValue(url0_)); 371 server_url_list_.Append(new base::StringValue(url0_));
373 SetContentPattern(&server_patterns_, expression0_, content_type0_, 1); 372 SetContentPattern(&server_patterns_, expression0_, content_type0_, 1);
374 } 373 }
375 374
376 bool MergeListPreference(const char* pref) { 375 bool MergeListPreference(const char* pref) {
377 { 376 {
378 ListPrefUpdate update(pref_service_, pref); 377 ListPrefUpdate update(pref_service_, pref);
379 base::ListValue* local_list_value = update.Get(); 378 base::ListValue* local_list_value = update.Get();
380 local_list_value->Append(base::Value::CreateStringValue(url1_)); 379 local_list_value->Append(new base::StringValue(url1_));
381 } 380 }
382 381
383 scoped_ptr<base::Value> merged_value(PrefModelAssociator::MergePreference( 382 scoped_ptr<base::Value> merged_value(PrefModelAssociator::MergePreference(
384 pref, 383 pref,
385 *pref_service_->GetUserPrefValue(pref), 384 *pref_service_->GetUserPrefValue(pref),
386 server_url_list_)); 385 server_url_list_));
387 386
388 base::ListValue expected; 387 base::ListValue expected;
389 expected.Append(base::Value::CreateStringValue(url0_)); 388 expected.Append(new base::StringValue(url0_));
390 expected.Append(base::Value::CreateStringValue(url1_)); 389 expected.Append(new base::StringValue(url1_));
391 return merged_value->Equals(&expected); 390 return merged_value->Equals(&expected);
392 } 391 }
393 392
394 bool MergeDictionaryPreference(const char* pref) { 393 bool MergeDictionaryPreference(const char* pref) {
395 { 394 {
396 DictionaryPrefUpdate update(pref_service_, pref); 395 DictionaryPrefUpdate update(pref_service_, pref);
397 base::DictionaryValue* local_dict_value = update.Get(); 396 base::DictionaryValue* local_dict_value = update.Get();
398 SetContentPattern(local_dict_value, expression1_, content_type0_, 1); 397 SetContentPattern(local_dict_value, expression1_, content_type0_, 1);
399 } 398 }
400 399
(...skipping 13 matching lines...) Expand all
414 std::string expression0_; 413 std::string expression0_;
415 std::string expression1_; 414 std::string expression1_;
416 std::string content_type0_; 415 std::string content_type0_;
417 base::ListValue server_url_list_; 416 base::ListValue server_url_list_;
418 base::DictionaryValue server_patterns_; 417 base::DictionaryValue server_patterns_;
419 }; 418 };
420 419
421 TEST_F(IndividualPreferenceMergeTest, URLsToRestoreOnStartup) { 420 TEST_F(IndividualPreferenceMergeTest, URLsToRestoreOnStartup) {
422 EXPECT_TRUE(MergeListPreference(prefs::kURLsToRestoreOnStartup)); 421 EXPECT_TRUE(MergeListPreference(prefs::kURLsToRestoreOnStartup));
423 } 422 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_hash_filter_unittest.cc ('k') | chrome/browser/prefs/proxy_policy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698