OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "modules/indexeddb/IDBValueWrapping.h" |
| 6 |
| 7 #include "bindings/core/v8/V8BindingForTesting.h" |
| 8 #include "modules/indexeddb/IDBValue.h" |
| 9 #include "platform/wtf/PtrUtil.h" |
| 10 #include "platform/wtf/RefPtr.h" |
| 11 #include "platform/wtf/Vector.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "v8/include/v8.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 TEST(IDBValueUnwrapperTest, IsWrapped) { |
| 18 V8TestingScope scope; |
| 19 NonThrowableExceptionState non_throwable_exception_state; |
| 20 v8::Local<v8::Value> v8_true = v8::True(scope.GetIsolate()); |
| 21 IDBValueWrapper wrapper(scope.GetIsolate(), v8_true, |
| 22 SerializedScriptValue::SerializeOptions::kSerialize, |
| 23 non_throwable_exception_state); |
| 24 wrapper.WrapIfBiggerThan(0); |
| 25 Vector<RefPtr<BlobDataHandle>> blob_data_handles; |
| 26 wrapper.ExtractBlobDataHandles(&blob_data_handles); |
| 27 Vector<WebBlobInfo>& blob_infos = wrapper.WrappedBlobInfo(); |
| 28 RefPtr<SharedBuffer> wrapped_marker_buffer = wrapper.ExtractWireBytes(); |
| 29 |
| 30 RefPtr<IDBValue> wrapped_value = IDBValue::Create( |
| 31 wrapped_marker_buffer, |
| 32 WTF::MakeUnique<Vector<RefPtr<BlobDataHandle>>>(blob_data_handles), |
| 33 WTF::MakeUnique<Vector<WebBlobInfo>>(blob_infos)); |
| 34 EXPECT_TRUE(IDBValueUnwrapper::IsWrapped(wrapped_value.Get())); |
| 35 |
| 36 Vector<char> wrapped_marker_bytes(wrapped_marker_buffer->size()); |
| 37 wrapped_marker_buffer->GetAsBytes(wrapped_marker_bytes.data(), |
| 38 wrapped_marker_bytes.size()); |
| 39 |
| 40 // IsWrapped() looks at the first 3 bytes in the value's byte array. |
| 41 // Truncating the array to fewer than 3 bytes should cause IsWrapped() to |
| 42 // return false. |
| 43 ASSERT_LT(3U, wrapped_marker_bytes.size()); |
| 44 for (size_t i = 0; i < 3; ++i) { |
| 45 RefPtr<IDBValue> mutant_value = IDBValue::Create( |
| 46 SharedBuffer::Create(wrapped_marker_bytes.data(), i), |
| 47 WTF::MakeUnique<Vector<RefPtr<BlobDataHandle>>>(blob_data_handles), |
| 48 WTF::MakeUnique<Vector<WebBlobInfo>>(blob_infos)); |
| 49 |
| 50 EXPECT_FALSE(IDBValueUnwrapper::IsWrapped(mutant_value.Get())); |
| 51 } |
| 52 |
| 53 // IsWrapped() looks at the first 3 bytes in the value. Flipping any bit in |
| 54 // these 3 bytes should cause IsWrapped() to return false. |
| 55 ASSERT_LT(3U, wrapped_marker_bytes.size()); |
| 56 for (size_t i = 0; i < 3; ++i) { |
| 57 for (int j = 0; j < 8; ++j) { |
| 58 char mask = 1 << j; |
| 59 wrapped_marker_bytes[i] ^= mask; |
| 60 RefPtr<IDBValue> mutant_value = IDBValue::Create( |
| 61 SharedBuffer::Create(wrapped_marker_bytes.data(), |
| 62 wrapped_marker_bytes.size()), |
| 63 WTF::MakeUnique<Vector<RefPtr<BlobDataHandle>>>(blob_data_handles), |
| 64 WTF::MakeUnique<Vector<WebBlobInfo>>(blob_infos)); |
| 65 EXPECT_FALSE(IDBValueUnwrapper::IsWrapped(mutant_value.Get())); |
| 66 |
| 67 wrapped_marker_bytes[i] ^= mask; |
| 68 } |
| 69 } |
| 70 } |
| 71 |
| 72 } // namespace blink |
OLD | NEW |