Move render_view_context_menu.* and related files out of tab_contents.
[chromium-blink-merge.git] / chrome / test / ui / javascript_test_util.cc
blobe643a5d081b4cc9e8e6900d16da996479de9465d
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());
24 if (!root.get())
25 return false;
27 EXPECT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
28 if (!root->IsType(base::Value::TYPE_DICTIONARY))
29 return false;
31 base::DictionaryValue* dict = static_cast<base::DictionaryValue*>(root.get());
33 for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
34 double double_result;
35 std::string result;
36 if (it.value().GetAsString(&result)) {
37 } else if (it.value().GetAsDouble(&double_result)) {
38 result = base::DoubleToString(double_result);
39 } else {
40 NOTREACHED() << "Value type not supported!";
41 return false;
43 results->insert(std::make_pair(it.key(), result));
46 return true;