OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <cmath> | 5 #include <cmath> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/test/values_test_util.h" | 9 #include "base/test/values_test_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 virtual void TearDown() { | 65 virtual void TearDown() { |
66 context_.Dispose(context_->GetIsolate()); | 66 context_.Dispose(context_->GetIsolate()); |
67 } | 67 } |
68 | 68 |
69 std::string GetString(base::DictionaryValue* value, const std::string& key) { | 69 std::string GetString(base::DictionaryValue* value, const std::string& key) { |
70 std::string temp; | 70 std::string temp; |
71 if (!value->GetString(key, &temp)) { | 71 if (!value->GetString(key, &temp)) { |
72 ADD_FAILURE(); | 72 ADD_FAILURE(); |
73 return ""; | 73 return std::string(); |
74 } | 74 } |
75 return temp; | 75 return temp; |
76 } | 76 } |
77 | 77 |
78 std::string GetString(v8::Handle<v8::Object> value, const std::string& key) { | 78 std::string GetString(v8::Handle<v8::Object> value, const std::string& key) { |
79 v8::Handle<v8::String> temp = | 79 v8::Handle<v8::String> temp = |
80 value->Get(v8::String::New(key.c_str())).As<v8::String>(); | 80 value->Get(v8::String::New(key.c_str())).As<v8::String>(); |
81 if (temp.IsEmpty()) { | 81 if (temp.IsEmpty()) { |
82 ADD_FAILURE(); | 82 ADD_FAILURE(); |
83 return ""; | 83 return std::string(); |
84 } | 84 } |
85 v8::String::Utf8Value utf8(temp); | 85 v8::String::Utf8Value utf8(temp); |
86 return std::string(*utf8, utf8.length()); | 86 return std::string(*utf8, utf8.length()); |
87 } | 87 } |
88 | 88 |
89 std::string GetString(base::ListValue* value, uint32 index) { | 89 std::string GetString(base::ListValue* value, uint32 index) { |
90 std::string temp; | 90 std::string temp; |
91 if (!value->GetString(static_cast<size_t>(index), &temp)) { | 91 if (!value->GetString(static_cast<size_t>(index), &temp)) { |
92 ADD_FAILURE(); | 92 ADD_FAILURE(); |
93 return ""; | 93 return std::string(); |
94 } | 94 } |
95 return temp; | 95 return temp; |
96 } | 96 } |
97 | 97 |
98 std::string GetString(v8::Handle<v8::Array> value, uint32 index) { | 98 std::string GetString(v8::Handle<v8::Array> value, uint32 index) { |
99 v8::Handle<v8::String> temp = value->Get(index).As<v8::String>(); | 99 v8::Handle<v8::String> temp = value->Get(index).As<v8::String>(); |
100 if (temp.IsEmpty()) { | 100 if (temp.IsEmpty()) { |
101 ADD_FAILURE(); | 101 ADD_FAILURE(); |
102 return ""; | 102 return std::string(); |
103 } | 103 } |
104 v8::String::Utf8Value utf8(temp); | 104 v8::String::Utf8Value utf8(temp); |
105 return std::string(*utf8, utf8.length()); | 105 return std::string(*utf8, utf8.length()); |
106 } | 106 } |
107 | 107 |
108 bool IsNull(base::DictionaryValue* value, const std::string& key) { | 108 bool IsNull(base::DictionaryValue* value, const std::string& key) { |
109 base::Value* child = NULL; | 109 base::Value* child = NULL; |
110 if (!value->Get(key, &child)) { | 110 if (!value->Get(key, &child)) { |
111 ADD_FAILURE(); | 111 ADD_FAILURE(); |
112 return false; | 112 return false; |
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 | 641 |
642 // The actual result. | 642 // The actual result. |
643 scoped_ptr<base::Value> actual_dictionary( | 643 scoped_ptr<base::Value> actual_dictionary( |
644 converter.FromV8Value(recursive_object, context_)); | 644 converter.FromV8Value(recursive_object, context_)); |
645 ASSERT_TRUE(actual_dictionary.get()); | 645 ASSERT_TRUE(actual_dictionary.get()); |
646 | 646 |
647 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get())); | 647 EXPECT_TRUE(expected_dictionary.Equals(actual_dictionary.get())); |
648 } | 648 } |
649 | 649 |
650 } // namespace content | 650 } // namespace content |
OLD | NEW |