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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include <cmath> | 8 #include <cmath> |
6 | 9 |
| 10 #include "base/macros.h" |
7 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
8 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
9 #include "base/test/values_test_util.h" | 13 #include "base/test/values_test_util.h" |
10 #include "base/values.h" | 14 #include "base/values.h" |
11 #include "content/child/v8_value_converter_impl.h" | 15 #include "content/child/v8_value_converter_impl.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "v8/include/v8.h" | 17 #include "v8/include/v8.h" |
14 | 18 |
15 namespace content { | 19 namespace content { |
16 | 20 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 value->Get(v8::String::NewFromUtf8(isolate_, key.c_str())) | 77 value->Get(v8::String::NewFromUtf8(isolate_, key.c_str())) |
74 .As<v8::String>(); | 78 .As<v8::String>(); |
75 if (temp.IsEmpty()) { | 79 if (temp.IsEmpty()) { |
76 ADD_FAILURE(); | 80 ADD_FAILURE(); |
77 return std::string(); | 81 return std::string(); |
78 } | 82 } |
79 v8::String::Utf8Value utf8(temp); | 83 v8::String::Utf8Value utf8(temp); |
80 return std::string(*utf8, utf8.length()); | 84 return std::string(*utf8, utf8.length()); |
81 } | 85 } |
82 | 86 |
83 std::string GetString(base::ListValue* value, uint32 index) { | 87 std::string GetString(base::ListValue* value, uint32_t index) { |
84 std::string temp; | 88 std::string temp; |
85 if (!value->GetString(static_cast<size_t>(index), &temp)) { | 89 if (!value->GetString(static_cast<size_t>(index), &temp)) { |
86 ADD_FAILURE(); | 90 ADD_FAILURE(); |
87 return std::string(); | 91 return std::string(); |
88 } | 92 } |
89 return temp; | 93 return temp; |
90 } | 94 } |
91 | 95 |
92 std::string GetString(v8::Local<v8::Array> value, uint32 index) { | 96 std::string GetString(v8::Local<v8::Array> value, uint32_t index) { |
93 v8::Local<v8::String> temp = value->Get(index).As<v8::String>(); | 97 v8::Local<v8::String> temp = value->Get(index).As<v8::String>(); |
94 if (temp.IsEmpty()) { | 98 if (temp.IsEmpty()) { |
95 ADD_FAILURE(); | 99 ADD_FAILURE(); |
96 return std::string(); | 100 return std::string(); |
97 } | 101 } |
98 v8::String::Utf8Value utf8(temp); | 102 v8::String::Utf8Value utf8(temp); |
99 return std::string(*utf8, utf8.length()); | 103 return std::string(*utf8, utf8.length()); |
100 } | 104 } |
101 | 105 |
102 bool IsNull(base::DictionaryValue* value, const std::string& key) { | 106 bool IsNull(base::DictionaryValue* value, const std::string& key) { |
103 base::Value* child = NULL; | 107 base::Value* child = NULL; |
104 if (!value->Get(key, &child)) { | 108 if (!value->Get(key, &child)) { |
105 ADD_FAILURE(); | 109 ADD_FAILURE(); |
106 return false; | 110 return false; |
107 } | 111 } |
108 return child->GetType() == base::Value::TYPE_NULL; | 112 return child->GetType() == base::Value::TYPE_NULL; |
109 } | 113 } |
110 | 114 |
111 bool IsNull(v8::Local<v8::Object> value, const std::string& key) { | 115 bool IsNull(v8::Local<v8::Object> value, const std::string& key) { |
112 v8::Local<v8::Value> child = | 116 v8::Local<v8::Value> child = |
113 value->Get(v8::String::NewFromUtf8(isolate_, key.c_str())); | 117 value->Get(v8::String::NewFromUtf8(isolate_, key.c_str())); |
114 if (child.IsEmpty()) { | 118 if (child.IsEmpty()) { |
115 ADD_FAILURE(); | 119 ADD_FAILURE(); |
116 return false; | 120 return false; |
117 } | 121 } |
118 return child->IsNull(); | 122 return child->IsNull(); |
119 } | 123 } |
120 | 124 |
121 bool IsNull(base::ListValue* value, uint32 index) { | 125 bool IsNull(base::ListValue* value, uint32_t index) { |
122 base::Value* child = NULL; | 126 base::Value* child = NULL; |
123 if (!value->Get(static_cast<size_t>(index), &child)) { | 127 if (!value->Get(static_cast<size_t>(index), &child)) { |
124 ADD_FAILURE(); | 128 ADD_FAILURE(); |
125 return false; | 129 return false; |
126 } | 130 } |
127 return child->GetType() == base::Value::TYPE_NULL; | 131 return child->GetType() == base::Value::TYPE_NULL; |
128 } | 132 } |
129 | 133 |
130 bool IsNull(v8::Local<v8::Array> value, uint32 index) { | 134 bool IsNull(v8::Local<v8::Array> value, uint32_t index) { |
131 v8::Local<v8::Value> child = value->Get(index); | 135 v8::Local<v8::Value> child = value->Get(index); |
132 if (child.IsEmpty()) { | 136 if (child.IsEmpty()) { |
133 ADD_FAILURE(); | 137 ADD_FAILURE(); |
134 return false; | 138 return false; |
135 } | 139 } |
136 return child->IsNull(); | 140 return child->IsNull(); |
137 } | 141 } |
138 | 142 |
139 void TestWeirdType(const V8ValueConverterImpl& converter, | 143 void TestWeirdType(const V8ValueConverterImpl& converter, |
140 v8::Local<v8::Value> val, | 144 v8::Local<v8::Value> val, |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 EXPECT_TRUE( | 870 EXPECT_TRUE( |
867 base::Value::Equals(reference_number_value.get(), number_value.get())); | 871 base::Value::Equals(reference_number_value.get(), number_value.get())); |
868 | 872 |
869 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); | 873 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); |
870 scoped_ptr<base::Value> undefined_value( | 874 scoped_ptr<base::Value> undefined_value( |
871 converter.FromV8Value(undefined, context)); | 875 converter.FromV8Value(undefined, context)); |
872 EXPECT_FALSE(undefined_value); | 876 EXPECT_FALSE(undefined_value); |
873 } | 877 } |
874 | 878 |
875 } // namespace content | 879 } // namespace content |
OLD | NEW |