Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: test/unittests/value-serializer-unittest.cc

Issue 2696133007: ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag (Closed)
Patch Set: ValueSerializer: Add SetTreatArrayBufferViewsAsHostObjects() flag Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/value-serializer-unittest.cc
diff --git a/test/unittests/value-serializer-unittest.cc b/test/unittests/value-serializer-unittest.cc
index 2a57ab38e5092bf0d7f40b0019436f6cbabbd2e5..1a5fbe3e3c39f6c4184e915fd58b7a2cbb9024d4 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -263,6 +263,13 @@ class ValueSerializerTest : public TestWithIsolate {
.ToLocalChecked();
}
+ Local<Object> NewDummyUint8Array() {
+ static uint8_t data[] = {4, 5, 6};
+ Local<ArrayBuffer> ab =
+ ArrayBuffer::New(isolate(), static_cast<void*>(data), sizeof(data));
+ return Uint8Array::New(ab, 0, sizeof(data));
+ }
+
private:
Local<Context> serialization_context_;
Local<Context> deserialization_context_;
@@ -2537,6 +2544,38 @@ TEST_F(ValueSerializerTestWithHostObject, RoundTripSameObject) {
});
}
+class ValueSerializerTestWithHostArrayBufferView
+ : public ValueSerializerTestWithHostObject {
+ protected:
+ void BeforeEncode(ValueSerializer* serializer) override {
+ ValueSerializerTestWithHostObject::BeforeEncode(serializer);
+ serializer_->SetTreatArrayBufferViewsAsHostObjects(true);
+ }
+};
+
+TEST_F(ValueSerializerTestWithHostArrayBufferView, RoundTripUint8ArrayInput) {
+ EXPECT_CALL(serializer_delegate_, WriteHostObject(isolate(), _))
+ .WillOnce(Invoke([this](Isolate*, Local<Object> object) {
+ EXPECT_TRUE(object->IsUint8Array());
+ WriteExampleHostObjectTag();
+ return Just(true);
+ }));
+ EXPECT_CALL(deserializer_delegate_, ReadHostObject(isolate()))
+ .WillOnce(Invoke([this](Isolate*) {
+ EXPECT_TRUE(ReadExampleHostObjectTag());
+ return NewDummyUint8Array();
+ }));
+ RoundTripTest(
+ "({ a: new Uint8Array([1, 2, 3]), get b() { return this.a; }})",
+ [this](Local<Value> value) {
+ EXPECT_TRUE(
+ EvaluateScriptForResultBool("result.a instanceof Uint8Array"));
+ EXPECT_TRUE(
+ EvaluateScriptForResultBool("result.a.toString() === '4,5,6'"));
+ EXPECT_TRUE(EvaluateScriptForResultBool("result.a === result.b"));
+ });
+}
+
// It's expected that WebAssembly has more exhaustive tests elsewhere; this
// mostly checks that the logic to embed it in structured clone serialization
// works correctly.
« no previous file with comments | « src/value-serializer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698