summaryrefslogtreecommitdiff
path: root/chromium/gin/converter_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/gin/converter_unittest.cc')
-rw-r--r--chromium/gin/converter_unittest.cc59
1 files changed, 52 insertions, 7 deletions
diff --git a/chromium/gin/converter_unittest.cc b/chromium/gin/converter_unittest.cc
index a198f40c666..967ca13423f 100644
--- a/chromium/gin/converter_unittest.cc
+++ b/chromium/gin/converter_unittest.cc
@@ -9,8 +9,11 @@
#include <stdint.h>
#include "base/compiler_specific.h"
+#include "gin/handle.h"
#include "gin/public/isolate_holder.h"
#include "gin/test/v8_test.h"
+#include "gin/wrappable.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "v8/include/v8.h"
@@ -116,16 +119,58 @@ TEST_F(ConverterTest, Vector) {
expected.push_back(0);
expected.push_back(1);
- auto maybe = Converter<std::vector<int>>::ToV8(
- instance_->isolate()->GetCurrentContext(), expected);
- Local<Value> js_value;
- EXPECT_TRUE(maybe.ToLocal(&js_value));
- Local<Array> js_array2 = Local<Array>::Cast(js_value);
- EXPECT_EQ(3u, js_array2->Length());
+ auto js_array =
+ Converter<std::vector<int>>::ToV8(instance_->isolate(), expected)
+ .As<Array>();
+ EXPECT_EQ(3u, js_array->Length());
for (size_t i = 0; i < expected.size(); ++i) {
EXPECT_TRUE(Integer::New(instance_->isolate(), expected[i])
- ->StrictEquals(js_array2->Get(static_cast<int>(i))));
+ ->StrictEquals(js_array->Get(static_cast<int>(i))));
}
}
+TEST_F(ConverterTest, VectorOfVectors) {
+ HandleScope handle_scope(instance_->isolate());
+
+ std::vector<std::vector<int>> vector_of_vectors = {
+ {1, 2, 3}, {4, 5, 6},
+ };
+
+ v8::Local<v8::Value> v8_value =
+ ConvertToV8(instance_->isolate(), vector_of_vectors);
+ std::vector<std::vector<int>> out_value;
+ ASSERT_TRUE(ConvertFromV8(instance_->isolate(), v8_value, &out_value));
+ EXPECT_THAT(out_value, testing::ContainerEq(vector_of_vectors));
+}
+
+namespace {
+
+class MyObject : public Wrappable<MyObject> {
+ public:
+ static WrapperInfo kWrapperInfo;
+
+ static gin::Handle<MyObject> Create(v8::Isolate* isolate) {
+ return CreateHandle(isolate, new MyObject());
+ }
+};
+
+WrapperInfo MyObject::kWrapperInfo = {kEmbedderNativeGin};
+
+} // namespace
+
+TEST_F(ConverterTest, VectorOfWrappables) {
+ v8::Isolate* isolate = instance_->isolate();
+ v8::HandleScope handle_scope(isolate);
+
+ Handle<MyObject> obj = MyObject::Create(isolate);
+ std::vector<MyObject*> vector = {obj.get()};
+ v8::MaybeLocal<v8::Value> maybe = ConvertToV8(isolate, vector);
+ v8::Local<v8::Value> array;
+ ASSERT_TRUE(maybe.ToLocal(&array));
+
+ std::vector<MyObject*> out_value;
+ ASSERT_TRUE(ConvertFromV8(isolate, array, &out_value));
+ EXPECT_THAT(out_value, testing::ContainerEq(vector));
+}
+
} // namespace gin