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

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

Issue 2570433005: Disallow passing a SharedArrayBuffer in the transfer list. (Closed)
Patch Set: TransferSharedArrayBuffer -> GetSharedArrayBufferId Created 4 years 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 1dabd2a17a78f411a5af3e3dad3ce57418ddc20d..9d76cb70519a52b26c70fef34c04e2244fbca154 100644
--- a/test/unittests/value-serializer-unittest.cc
+++ b/test/unittests/value-serializer-unittest.cc
@@ -19,6 +19,7 @@ namespace {
using ::testing::_;
using ::testing::Invoke;
+using ::testing::Return;
class ValueSerializerTest : public TestWithIsolate {
protected:
@@ -129,15 +130,22 @@ class ValueSerializerTest : public TestWithIsolate {
encoded_data_functor(buffer);
}
- template <typename MessageFunctor>
- void InvalidEncodeTest(const char* source, const MessageFunctor& functor) {
+ template <typename InputFunctor, typename MessageFunctor>
+ void InvalidEncodeTest(const InputFunctor& input_functor,
+ const MessageFunctor& functor) {
Context::Scope scope(serialization_context());
TryCatch try_catch(isolate());
- Local<Value> input_value = EvaluateScriptForInput(source);
+ Local<Value> input_value = input_functor();
ASSERT_TRUE(DoEncode(input_value).IsNothing());
functor(try_catch.Message());
}
+ template <typename MessageFunctor>
+ void InvalidEncodeTest(const char* source, const MessageFunctor& functor) {
+ InvalidEncodeTest(
+ [this, source]() { return EvaluateScriptForInput(source); }, functor);
+ }
+
void InvalidEncodeTest(const char* source) {
InvalidEncodeTest(source, [](Local<Message>) {});
}
@@ -2042,7 +2050,8 @@ class ValueSerializerTestWithSharedArrayBufferTransfer
protected:
static const size_t kTestByteLength = 4;
- ValueSerializerTestWithSharedArrayBufferTransfer() {
+ ValueSerializerTestWithSharedArrayBufferTransfer()
+ : serializer_delegate_(this) {
const uint8_t data[kTestByteLength] = {0x00, 0x01, 0x80, 0xff};
memcpy(data_, data, kTestByteLength);
{
@@ -2060,10 +2069,6 @@ class ValueSerializerTestWithSharedArrayBufferTransfer
const Local<SharedArrayBuffer>& input_buffer() { return input_buffer_; }
const Local<SharedArrayBuffer>& output_buffer() { return output_buffer_; }
- void BeforeEncode(ValueSerializer* serializer) override {
- serializer->TransferSharedArrayBuffer(0, input_buffer_);
- }
-
void BeforeDecode(ValueDeserializer* deserializer) override {
deserializer->TransferSharedArrayBuffer(0, output_buffer_);
}
@@ -2080,6 +2085,39 @@ class ValueSerializerTestWithSharedArrayBufferTransfer
flag_was_enabled_ = false;
}
+ protected:
+// GMock doesn't use the "override" keyword.
+#if __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Winconsistent-missing-override"
+#endif
+
+ class SerializerDelegate : public ValueSerializer::Delegate {
+ public:
+ explicit SerializerDelegate(
+ ValueSerializerTestWithSharedArrayBufferTransfer* test)
+ : test_(test) {}
+ MOCK_METHOD2(GetSharedArrayBufferId,
+ Maybe<uint32_t>(Isolate* isolate,
+ Local<SharedArrayBuffer> shared_array_buffer));
+ void ThrowDataCloneError(Local<String> message) override {
+ test_->isolate()->ThrowException(Exception::Error(message));
+ }
+
+ private:
+ ValueSerializerTestWithSharedArrayBufferTransfer* test_;
+ };
+
+#if __clang__
+#pragma clang diagnostic pop
+#endif
+
+ ValueSerializer::Delegate* GetSerializerDelegate() override {
+ return &serializer_delegate_;
+ }
+
+ SerializerDelegate serializer_delegate_;
+
private:
static bool flag_was_enabled_;
uint8_t data_[kTestByteLength];
@@ -2092,6 +2130,10 @@ bool ValueSerializerTestWithSharedArrayBufferTransfer::flag_was_enabled_ =
TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer,
RoundTripSharedArrayBufferTransfer) {
+ EXPECT_CALL(serializer_delegate_,
+ GetSharedArrayBufferId(isolate(), input_buffer()))
+ .WillRepeatedly(Return(Just(0U)));
+
RoundTripTest([this]() { return input_buffer(); },
[this](Local<Value> value) {
ASSERT_TRUE(value->IsSharedArrayBuffer());
@@ -2123,12 +2165,6 @@ TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer,
});
}
-TEST_F(ValueSerializerTestWithSharedArrayBufferTransfer,
- SharedArrayBufferMustBeTransferred) {
- // A SharedArrayBuffer which was not marked for transfer should fail encoding.
- InvalidEncodeTest("new SharedArrayBuffer(32)");
-}
-
TEST_F(ValueSerializerTest, UnsupportedHostObject) {
InvalidEncodeTest("new ExampleHostObject()");
InvalidEncodeTest("({ a: new ExampleHostObject() })");
« 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