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 "content/child/v8_value_converter_impl.h" | 5 #include "content/child/v8_value_converter_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 1090 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1101 | 1101 |
1102 v8::Local<v8::Array> array(v8::Array::New(isolate_)); | 1102 v8::Local<v8::Array> array(v8::Array::New(isolate_)); |
1103 std::unique_ptr<base::Value> array_value( | 1103 std::unique_ptr<base::Value> array_value( |
1104 converter.FromV8Value(array, context)); | 1104 converter.FromV8Value(array, context)); |
1105 ASSERT_TRUE(array_value); | 1105 ASSERT_TRUE(array_value); |
1106 std::unique_ptr<base::Value> reference_array_value( | 1106 std::unique_ptr<base::Value> reference_array_value( |
1107 base::test::ParseJson("[]")); | 1107 base::test::ParseJson("[]")); |
1108 EXPECT_TRUE( | 1108 EXPECT_TRUE( |
1109 base::Value::Equals(reference_array_value.get(), array_value.get())); | 1109 base::Value::Equals(reference_array_value.get(), array_value.get())); |
1110 | 1110 |
1111 // Not testing ArrayBuffers as V8ValueConverter uses blink helpers and | 1111 const char kExampleData[] = {1, 2, 3, 4, 5}; |
1112 // this requires having blink to be initialized. | 1112 v8::Local<v8::ArrayBuffer> array_buffer( |
| 1113 v8::ArrayBuffer::New(isolate_, sizeof(kExampleData))); |
| 1114 memcpy(array_buffer->GetContents().Data(), kExampleData, |
| 1115 sizeof(kExampleData)); |
| 1116 std::unique_ptr<base::Value> binary_value( |
| 1117 converter.FromV8Value(array_buffer, context)); |
| 1118 ASSERT_TRUE(binary_value); |
| 1119 std::unique_ptr<base::Value> reference_binary_value( |
| 1120 base::BinaryValue::CreateWithCopiedBuffer(kExampleData, |
| 1121 sizeof(kExampleData))); |
| 1122 EXPECT_TRUE( |
| 1123 base::Value::Equals(reference_binary_value.get(), binary_value.get())); |
| 1124 |
| 1125 v8::Local<v8::ArrayBufferView> array_buffer_view( |
| 1126 v8::Uint8Array::New(array_buffer, 1, 3)); |
| 1127 std::unique_ptr<base::Value> binary_view_value( |
| 1128 converter.FromV8Value(array_buffer_view, context)); |
| 1129 ASSERT_TRUE(binary_view_value); |
| 1130 std::unique_ptr<base::Value> reference_binary_view_value( |
| 1131 base::BinaryValue::CreateWithCopiedBuffer(&kExampleData[1], 3)); |
| 1132 EXPECT_TRUE(base::Value::Equals(reference_binary_view_value.get(), |
| 1133 binary_view_value.get())); |
1113 | 1134 |
1114 v8::Local<v8::Number> number(v8::Number::New(isolate_, 0.0)); | 1135 v8::Local<v8::Number> number(v8::Number::New(isolate_, 0.0)); |
1115 std::unique_ptr<base::Value> number_value( | 1136 std::unique_ptr<base::Value> number_value( |
1116 converter.FromV8Value(number, context)); | 1137 converter.FromV8Value(number, context)); |
1117 ASSERT_TRUE(number_value); | 1138 ASSERT_TRUE(number_value); |
1118 std::unique_ptr<base::Value> reference_number_value( | 1139 std::unique_ptr<base::Value> reference_number_value( |
1119 base::test::ParseJson("0")); | 1140 base::test::ParseJson("0")); |
1120 EXPECT_TRUE( | 1141 EXPECT_TRUE( |
1121 base::Value::Equals(reference_number_value.get(), number_value.get())); | 1142 base::Value::Equals(reference_number_value.get(), number_value.get())); |
1122 | 1143 |
1123 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); | 1144 v8::Local<v8::Primitive> undefined(v8::Undefined(isolate_)); |
1124 std::unique_ptr<base::Value> undefined_value( | 1145 std::unique_ptr<base::Value> undefined_value( |
1125 converter.FromV8Value(undefined, context)); | 1146 converter.FromV8Value(undefined, context)); |
1126 EXPECT_FALSE(undefined_value); | 1147 EXPECT_FALSE(undefined_value); |
1127 } | 1148 } |
1128 | 1149 |
1129 } // namespace content | 1150 } // namespace content |
OLD | NEW |