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

Side by Side Diff: base/values_unittest.cc

Issue 441008: Many changes to DictionaryValues:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <limits> 5 #include <limits>
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
11 class ValuesTest: public testing::Test { 11 class ValuesTest: public testing::Test {
12 }; 12 };
13 13
14 TEST(ValuesTest, Basic) { 14 TEST(ValuesTest, Basic) {
15 // Test basic dictionary getting/setting 15 // Test basic dictionary getting/setting
16 DictionaryValue settings; 16 DictionaryValue settings;
17 std::wstring homepage = L"http://google.com"; 17 std::wstring homepage = L"http://google.com";
18 ASSERT_FALSE( 18 ASSERT_FALSE(
19 settings.GetString(L"global.homepage", &homepage)); 19 settings.GetString(L"global.homepage", &homepage));
20 ASSERT_EQ(std::wstring(L"http://google.com"), homepage); 20 ASSERT_EQ(std::wstring(L"http://google.com"), homepage);
21 21
22 ASSERT_FALSE(settings.Get(L"global", NULL)); 22 ASSERT_FALSE(settings.Get(L"global", NULL));
23 ASSERT_TRUE(settings.Set(L"global", Value::CreateBooleanValue(true))); 23 settings.Set(L"global", Value::CreateBooleanValue(true));
24 ASSERT_TRUE(settings.Get(L"global", NULL)); 24 ASSERT_TRUE(settings.Get(L"global", NULL));
25 ASSERT_TRUE(settings.SetString(L"global.homepage", L"http://scurvy.com")); 25 settings.SetString(L"global.homepage", L"http://scurvy.com");
26 ASSERT_TRUE(settings.Get(L"global", NULL)); 26 ASSERT_TRUE(settings.Get(L"global", NULL));
27 homepage = L"http://google.com"; 27 homepage = L"http://google.com";
28 ASSERT_TRUE(settings.GetString(L"global.homepage", &homepage)); 28 ASSERT_TRUE(settings.GetString(L"global.homepage", &homepage));
29 ASSERT_EQ(std::wstring(L"http://scurvy.com"), homepage); 29 ASSERT_EQ(std::wstring(L"http://scurvy.com"), homepage);
30 30
31 // Test storing a dictionary in a list. 31 // Test storing a dictionary in a list.
32 ListValue* toolbar_bookmarks; 32 ListValue* toolbar_bookmarks;
33 ASSERT_FALSE( 33 ASSERT_FALSE(
34 settings.GetList(L"global.toolbar.bookmarks", &toolbar_bookmarks)); 34 settings.GetList(L"global.toolbar.bookmarks", &toolbar_bookmarks));
35 35
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 DictionaryValue dict; 278 DictionaryValue dict;
279 dict.Set(key, new DeletionTestValue(&deletion_flag)); 279 dict.Set(key, new DeletionTestValue(&deletion_flag));
280 EXPECT_FALSE(deletion_flag); 280 EXPECT_FALSE(deletion_flag);
281 EXPECT_TRUE(dict.HasKey(key)); 281 EXPECT_TRUE(dict.HasKey(key));
282 EXPECT_TRUE(dict.Remove(key, NULL)); 282 EXPECT_TRUE(dict.Remove(key, NULL));
283 EXPECT_TRUE(deletion_flag); 283 EXPECT_TRUE(deletion_flag);
284 EXPECT_FALSE(dict.HasKey(key)); 284 EXPECT_FALSE(dict.HasKey(key));
285 } 285 }
286 } 286 }
287 287
288 TEST(ValuesTest, DictionaryWithoutPathExpansion) {
289 DictionaryValue dict;
290 dict.Set(L"this.is.expanded", Value::CreateNullValue());
291 dict.SetWithoutPathExpansion(L"this.isnt.expanded", Value::CreateNullValue());
292
293 EXPECT_FALSE(dict.HasKey(L"this.is.expanded"));
294 EXPECT_TRUE(dict.HasKey(L"this"));
295 Value* value1;
296 EXPECT_TRUE(dict.Get(L"this", &value1));
297 DictionaryValue* value2;
298 ASSERT_TRUE(dict.GetDictionaryWithoutPathExpansion(L"this", &value2));
299 EXPECT_EQ(value1, value2);
300 EXPECT_EQ(1U, value2->size());
301
302 EXPECT_TRUE(dict.HasKey(L"this.isnt.expanded"));
303 Value* value3;
304 EXPECT_FALSE(dict.Get(L"this.isnt.expanded", &value3));
305 Value* value4;
306 ASSERT_TRUE(dict.GetWithoutPathExpansion(L"this.isnt.expanded", &value4));
307 EXPECT_EQ(Value::TYPE_NULL, value4->GetType());
308 }
309
288 TEST(ValuesTest, DeepCopy) { 310 TEST(ValuesTest, DeepCopy) {
289 DictionaryValue original_dict; 311 DictionaryValue original_dict;
290 Value* original_null = Value::CreateNullValue(); 312 Value* original_null = Value::CreateNullValue();
291 original_dict.Set(L"null", original_null); 313 original_dict.Set(L"null", original_null);
292 Value* original_bool = Value::CreateBooleanValue(true); 314 Value* original_bool = Value::CreateBooleanValue(true);
293 original_dict.Set(L"bool", original_bool); 315 original_dict.Set(L"bool", original_bool);
294 Value* original_int = Value::CreateIntegerValue(42); 316 Value* original_int = Value::CreateIntegerValue(42);
295 original_dict.Set(L"int", original_int); 317 original_dict.Set(L"int", original_int);
296 Value* original_real = Value::CreateRealValue(3.14); 318 Value* original_real = Value::CreateRealValue(3.14);
297 original_dict.Set(L"real", original_real); 319 original_dict.Set(L"real", original_real);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 dv.Set(L"f", list); 461 dv.Set(L"f", list);
440 462
441 EXPECT_FALSE(dv.Equals(copy)); 463 EXPECT_FALSE(dv.Equals(copy));
442 copy->Set(L"f", list->DeepCopy()); 464 copy->Set(L"f", list->DeepCopy());
443 EXPECT_TRUE(dv.Equals(copy)); 465 EXPECT_TRUE(dv.Equals(copy));
444 466
445 list->Append(Value::CreateBooleanValue(true)); 467 list->Append(Value::CreateBooleanValue(true));
446 EXPECT_FALSE(dv.Equals(copy)); 468 EXPECT_FALSE(dv.Equals(copy));
447 delete copy; 469 delete copy;
448 } 470 }
OLDNEW
« base/values.cc ('K') | « base/values.cc ('k') | chrome/browser/blocked_popup_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698