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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBValueWrappingTest.cpp

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Fixed Windows compilation. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
jsbell 2017/05/25 18:49:42 nit: 2017
pwnall 2017/05/25 20:01:11 Done. Thank you for catching!
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()));
jsbell 2017/05/25 18:49:42 All of the IsWrapped tests are either TRUE because
pwnall 2017/05/25 20:01:10 Yes, I need more tests. I prioritized these tests
66
67 wrapped_marker_bytes[i] ^= mask;
68 }
69 }
70 }
71
72 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698