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
3 // found in the LICENSE file.
5 #include "chrome/test/ui/javascript_test_util.h"
7 #include "base/json/json_string_value_serializer.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 bool JsonDictionaryToMap(const std::string
& json
,
16 std::map
<std::string
, std::string
>* results
) {
17 DCHECK(results
!= NULL
);
18 JSONStringValueSerializer
deserializer(json
);
19 scoped_ptr
<base::Value
> root(deserializer
.Deserialize(NULL
, NULL
));
21 // Note that we don't use ASSERT_TRUE here (and in some other places) as it
22 // doesn't work inside a function with a return type other than void.
23 EXPECT_TRUE(root
.get());
27 EXPECT_TRUE(root
->IsType(base::Value::TYPE_DICTIONARY
));
28 if (!root
->IsType(base::Value::TYPE_DICTIONARY
))
31 base::DictionaryValue
* dict
= static_cast<base::DictionaryValue
*>(root
.get());
33 for (base::DictionaryValue::Iterator
it(*dict
); !it
.IsAtEnd(); it
.Advance()) {
36 if (it
.value().GetAsString(&result
)) {
37 } else if (it
.value().GetAsDouble(&double_result
)) {
38 result
= base::DoubleToString(double_result
);
40 NOTREACHED() << "Value type not supported!";
43 results
->insert(std::make_pair(it
.key(), result
));