Fix DictionaryValue::Equals() to also detect differences in key names.

BUG=52419
TEST=unit tests in values_unittest.cc

Review URL: http://codereview.chromium.org/3163020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56536 0039d316-1c4b-4281-b951-d872f2087c98


CrOS-Libchrome-Original-Commit: dc1f2440d6c1773491b472e7595822b207052ac9
diff --git a/base/values.cc b/base/values.cc
index 926202e..ce73cb1 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -331,7 +331,8 @@
   while (lhs_it != end_keys() && rhs_it != other_dict->end_keys()) {
     Value* lhs;
     Value* rhs;
-    if (!GetWithoutPathExpansion(*lhs_it, &lhs) ||
+    if (*lhs_it != *rhs_it ||
+        !GetWithoutPathExpansion(*lhs_it, &lhs) ||
         !other_dict->GetWithoutPathExpansion(*rhs_it, &rhs) ||
         !lhs->Equals(rhs)) {
       return false;
diff --git a/base/values_unittest.cc b/base/values_unittest.cc
index a36c588..c1fb018 100644
--- a/base/values_unittest.cc
+++ b/base/values_unittest.cc
@@ -484,21 +484,28 @@
   dv.SetString("d2", ASCIIToUTF16("http://google.com"));
   dv.Set("e", Value::CreateNullValue());
 
-  DictionaryValue* copy = static_cast<DictionaryValue*>(dv.DeepCopy());
-  EXPECT_TRUE(dv.Equals(copy));
+  scoped_ptr<DictionaryValue> copy;
+  copy.reset(static_cast<DictionaryValue*>(dv.DeepCopy()));
+  EXPECT_TRUE(dv.Equals(copy.get()));
 
   ListValue* list = new ListValue;
   list->Append(Value::CreateNullValue());
   list->Append(new DictionaryValue);
   dv.Set("f", list);
 
-  EXPECT_FALSE(dv.Equals(copy));
+  EXPECT_FALSE(dv.Equals(copy.get()));
   copy->Set("f", list->DeepCopy());
-  EXPECT_TRUE(dv.Equals(copy));
+  EXPECT_TRUE(dv.Equals(copy.get()));
 
   list->Append(Value::CreateBooleanValue(true));
-  EXPECT_FALSE(dv.Equals(copy));
-  delete copy;
+  EXPECT_FALSE(dv.Equals(copy.get()));
+
+  // Check if Equals detects differences in only the keys.
+  copy.reset(static_cast<DictionaryValue*>(dv.DeepCopy()));
+  EXPECT_TRUE(dv.Equals(copy.get()));
+  copy->Remove("a", NULL);
+  copy->SetBoolean("aa", false);
+  EXPECT_FALSE(dv.Equals(copy.get()));
 }
 
 TEST_F(ValuesTest, RemoveEmptyChildren) {