| OLD | NEW |
| 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 "chrome/test/ui/javascript_test_util.h" | 5 #include "chrome/test/ui/javascript_test_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_number_conversions.h" | |
| 10 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 11 #include "base/values.h" | 10 #include "base/values.h" |
| 12 #include "content/common/json_value_serializer.h" | 11 #include "content/common/json_value_serializer.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 13 |
| 15 bool JsonDictionaryToMap(const std::string& json, | 14 bool JsonDictionaryToMap(const std::string& json, |
| 16 std::map<std::string, std::string>* results) { | 15 std::map<std::string, std::string>* results) { |
| 17 DCHECK(results != NULL); | 16 DCHECK(results != NULL); |
| 18 JSONStringValueSerializer deserializer(json); | 17 JSONStringValueSerializer deserializer(json); |
| 19 scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL)); | 18 scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL)); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 32 | 31 |
| 33 for (DictionaryValue::key_iterator it = dict->begin_keys(); | 32 for (DictionaryValue::key_iterator it = dict->begin_keys(); |
| 34 it != dict->end_keys(); ++it) { | 33 it != dict->end_keys(); ++it) { |
| 35 Value* value = NULL; | 34 Value* value = NULL; |
| 36 bool succeeded = dict->GetWithoutPathExpansion(*it, &value); | 35 bool succeeded = dict->GetWithoutPathExpansion(*it, &value); |
| 37 | 36 |
| 38 EXPECT_TRUE(succeeded); | 37 EXPECT_TRUE(succeeded); |
| 39 if (!succeeded) | 38 if (!succeeded) |
| 40 continue; | 39 continue; |
| 41 | 40 |
| 42 const std::string& key(*it); | 41 EXPECT_TRUE(value->IsType(Value::TYPE_STRING)); |
| 43 std::string result; | 42 if (value->IsType(Value::TYPE_STRING)) { |
| 43 const std::string& key(*it); |
| 44 | 44 |
| 45 switch (value->GetType()) { | 45 std::string result; |
| 46 case Value::TYPE_STRING: | 46 succeeded = value->GetAsString(&result); |
| 47 succeeded = value->GetAsString(&result); | 47 EXPECT_TRUE(succeeded); |
| 48 break; | 48 |
| 49 case Value::TYPE_DOUBLE: { | 49 if (succeeded) |
| 50 double double_result; | 50 results->insert(std::make_pair(key, result)); |
| 51 succeeded = value->GetAsDouble(&double_result); | |
| 52 if (succeeded) | |
| 53 result = base::DoubleToString(double_result); | |
| 54 break; | |
| 55 } | |
| 56 default: | |
| 57 NOTREACHED() << "Value type not supported!"; | |
| 58 return false; | |
| 59 } | 51 } |
| 60 | |
| 61 EXPECT_TRUE(succeeded); | |
| 62 if (succeeded) | |
| 63 results->insert(std::make_pair(key, result)); | |
| 64 } | 52 } |
| 65 | 53 |
| 66 return true; | 54 return true; |
| 67 } | 55 } |
| OLD | NEW |