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

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

Issue 2867693004: Snapshot of all changes to get jumbo in blink and content.
Patch Set: Rebased again Created 3 years, 5 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
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 22 matching lines...) Expand all
33 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
34 #include "core/dom/ExecutionContext.h" 34 #include "core/dom/ExecutionContext.h"
35 #include "core/testing/NullExecutionContext.h" 35 #include "core/testing/NullExecutionContext.h"
36 #include "modules/indexeddb/IDBDatabase.h" 36 #include "modules/indexeddb/IDBDatabase.h"
37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h"
38 #include "modules/indexeddb/IDBKey.h" 38 #include "modules/indexeddb/IDBKey.h"
39 #include "modules/indexeddb/IDBKeyPath.h" 39 #include "modules/indexeddb/IDBKeyPath.h"
40 #include "modules/indexeddb/IDBMetadata.h" 40 #include "modules/indexeddb/IDBMetadata.h"
41 #include "modules/indexeddb/IDBObjectStore.h" 41 #include "modules/indexeddb/IDBObjectStore.h"
42 #include "modules/indexeddb/IDBOpenDBRequest.h" 42 #include "modules/indexeddb/IDBOpenDBRequest.h"
43 #include "modules/indexeddb/IDBTestHelper.h"
43 #include "modules/indexeddb/IDBTransaction.h" 44 #include "modules/indexeddb/IDBTransaction.h"
44 #include "modules/indexeddb/IDBValue.h" 45 #include "modules/indexeddb/IDBValue.h"
45 #include "modules/indexeddb/IDBValueWrapping.h" 46 #include "modules/indexeddb/IDBValueWrapping.h"
46 #include "modules/indexeddb/MockWebIDBDatabase.h" 47 #include "modules/indexeddb/MockWebIDBDatabase.h"
47 #include "platform/SharedBuffer.h" 48 #include "platform/SharedBuffer.h"
48 #include "platform/bindings/ScriptState.h" 49 #include "platform/bindings/ScriptState.h"
49 #include "platform/wtf/RefPtr.h" 50 #include "platform/wtf/RefPtr.h"
50 #include "platform/wtf/Vector.h" 51 #include "platform/wtf/Vector.h"
51 #include "platform/wtf/dtoa/utils.h" 52 #include "platform/wtf/dtoa/utils.h"
52 #include "public/platform/Platform.h" 53 #include "public/platform/Platform.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 93
93 WebURLLoaderMockFactory* url_loader_mock_factory_; 94 WebURLLoaderMockFactory* url_loader_mock_factory_;
94 Persistent<IDBDatabase> db_; 95 Persistent<IDBDatabase> db_;
95 Persistent<IDBTransaction> transaction_; 96 Persistent<IDBTransaction> transaction_;
96 Persistent<IDBObjectStore> store_; 97 Persistent<IDBObjectStore> store_;
97 98
98 static constexpr int64_t kTransactionId = 1234; 99 static constexpr int64_t kTransactionId = 1234;
99 static constexpr int64_t kStoreId = 5678; 100 static constexpr int64_t kStoreId = 5678;
100 }; 101 };
101 102
102 // The created value is an array of true. If create_wrapped_value is true, the
103 // IDBValue's byte array will be wrapped in a Blob, otherwise it will not be.
104 RefPtr<IDBValue> CreateIDBValue(v8::Isolate* isolate,
105 bool create_wrapped_value) {
106 size_t element_count = create_wrapped_value ? 16 : 2;
107 v8::Local<v8::Array> v8_array = v8::Array::New(isolate, element_count);
108 for (size_t i = 0; i < element_count; ++i)
109 v8_array->Set(i, v8::True(isolate));
110
111 NonThrowableExceptionState non_throwable_exception_state;
112 IDBValueWrapper wrapper(isolate, v8_array,
113 SerializedScriptValue::SerializeOptions::kSerialize,
114 non_throwable_exception_state);
115 wrapper.WrapIfBiggerThan(create_wrapped_value ? 0 : 1024 * element_count);
116
117 std::unique_ptr<Vector<RefPtr<BlobDataHandle>>> blob_data_handles =
118 WTF::MakeUnique<Vector<RefPtr<BlobDataHandle>>>();
119 wrapper.ExtractBlobDataHandles(blob_data_handles.get());
120 Vector<WebBlobInfo>& blob_infos = wrapper.WrappedBlobInfo();
121 RefPtr<SharedBuffer> wrapped_marker_buffer = wrapper.ExtractWireBytes();
122 IDBKey* key = IDBKey::CreateNumber(42.0);
123 IDBKeyPath key_path(String("primaryKey"));
124
125 RefPtr<IDBValue> idb_value = IDBValue::Create(
126 std::move(wrapped_marker_buffer), std::move(blob_data_handles),
127 WTF::MakeUnique<Vector<WebBlobInfo>>(blob_infos), key, key_path);
128
129 DCHECK_EQ(create_wrapped_value,
130 IDBValueUnwrapper::IsWrapped(idb_value.Get()));
131 return idb_value;
132 }
133
134 void EnsureIDBCallbacksDontThrow(IDBRequest* request, 103 void EnsureIDBCallbacksDontThrow(IDBRequest* request,
135 ExceptionState& exception_state) { 104 ExceptionState& exception_state) {
136 ASSERT_TRUE(request->transaction()); 105 ASSERT_TRUE(request->transaction());
137 106
138 request->HandleResponse( 107 request->HandleResponse(
139 DOMException::Create(kAbortError, "Description goes here.")); 108 DOMException::Create(kAbortError, "Description goes here."));
140 request->HandleResponse(nullptr, IDBKey::CreateInvalid(), 109 request->HandleResponse(nullptr, IDBKey::CreateInvalid(),
141 IDBKey::CreateInvalid(), IDBValue::Create()); 110 IDBKey::CreateInvalid(), IDBValue::Create());
142 request->HandleResponse(IDBKey::CreateInvalid()); 111 request->HandleResponse(IDBKey::CreateInvalid());
143 request->HandleResponse(IDBValue::Create()); 112 request->HandleResponse(IDBValue::Create());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 BuildTransaction(scope, std::move(backend)); 147 BuildTransaction(scope, std::move(backend));
179 148
180 ASSERT_TRUE(!scope.GetExceptionState().HadException()); 149 ASSERT_TRUE(!scope.GetExceptionState().HadException());
181 ASSERT_TRUE(transaction_); 150 ASSERT_TRUE(transaction_);
182 151
183 IDBRequest* request = 152 IDBRequest* request =
184 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()), 153 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()),
185 transaction_.Get(), IDBRequest::AsyncTraceState()); 154 transaction_.Get(), IDBRequest::AsyncTraceState());
186 ASSERT_TRUE(!scope.GetExceptionState().HadException()); 155 ASSERT_TRUE(!scope.GetExceptionState().HadException());
187 ASSERT_TRUE(request->transaction()); 156 ASSERT_TRUE(request->transaction());
188 request->HandleResponse(CreateIDBValue(scope.GetIsolate(), false)); 157 request->HandleResponse(CreateIDBValueForTesting(scope.GetIsolate(), false));
189 scope.GetExecutionContext()->NotifyContextDestroyed(); 158 scope.GetExecutionContext()->NotifyContextDestroyed();
190 159
191 EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState()); 160 EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState());
192 } 161 }
193 162
194 TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithQueuedResult) { 163 TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithQueuedResult) {
195 V8TestingScope scope; 164 V8TestingScope scope;
196 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); 165 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create();
197 EXPECT_CALL(*backend, Close()).Times(1); 166 EXPECT_CALL(*backend, Close()).Times(1);
198 BuildTransaction(scope, std::move(backend)); 167 BuildTransaction(scope, std::move(backend));
199 168
200 ASSERT_TRUE(!scope.GetExceptionState().HadException()); 169 ASSERT_TRUE(!scope.GetExceptionState().HadException());
201 ASSERT_TRUE(transaction_); 170 ASSERT_TRUE(transaction_);
202 171
203 IDBRequest* request = 172 IDBRequest* request =
204 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()), 173 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()),
205 transaction_.Get(), IDBRequest::AsyncTraceState()); 174 transaction_.Get(), IDBRequest::AsyncTraceState());
206 EXPECT_EQ(request->readyState(), "pending"); 175 EXPECT_EQ(request->readyState(), "pending");
207 ASSERT_TRUE(!scope.GetExceptionState().HadException()); 176 ASSERT_TRUE(!scope.GetExceptionState().HadException());
208 ASSERT_TRUE(request->transaction()); 177 ASSERT_TRUE(request->transaction());
209 request->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); 178 request->HandleResponse(CreateIDBValueForTesting(scope.GetIsolate(), true));
210 scope.GetExecutionContext()->NotifyContextDestroyed(); 179 scope.GetExecutionContext()->NotifyContextDestroyed();
211 180
212 EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState()); 181 EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState());
213 url_loader_mock_factory_->ServeAsynchronousRequests(); 182 url_loader_mock_factory_->ServeAsynchronousRequests();
214 EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState()); 183 EnsureIDBCallbacksDontThrow(request, scope.GetExceptionState());
215 } 184 }
216 185
217 TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithTwoQueuedResults) { 186 TEST_F(IDBRequestTest, EventsAfterEarlyDeathStopWithTwoQueuedResults) {
218 V8TestingScope scope; 187 V8TestingScope scope;
219 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); 188 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create();
220 EXPECT_CALL(*backend, Close()).Times(1); 189 EXPECT_CALL(*backend, Close()).Times(1);
221 BuildTransaction(scope, std::move(backend)); 190 BuildTransaction(scope, std::move(backend));
222 191
223 ASSERT_TRUE(!scope.GetExceptionState().HadException()); 192 ASSERT_TRUE(!scope.GetExceptionState().HadException());
224 ASSERT_TRUE(transaction_); 193 ASSERT_TRUE(transaction_);
225 194
226 IDBRequest* request1 = 195 IDBRequest* request1 =
227 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()), 196 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()),
228 transaction_.Get(), IDBRequest::AsyncTraceState()); 197 transaction_.Get(), IDBRequest::AsyncTraceState());
229 IDBRequest* request2 = 198 IDBRequest* request2 =
230 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()), 199 IDBRequest::Create(scope.GetScriptState(), IDBAny::Create(store_.Get()),
231 transaction_.Get(), IDBRequest::AsyncTraceState()); 200 transaction_.Get(), IDBRequest::AsyncTraceState());
232 EXPECT_EQ(request1->readyState(), "pending"); 201 EXPECT_EQ(request1->readyState(), "pending");
233 EXPECT_EQ(request2->readyState(), "pending"); 202 EXPECT_EQ(request2->readyState(), "pending");
234 ASSERT_TRUE(!scope.GetExceptionState().HadException()); 203 ASSERT_TRUE(!scope.GetExceptionState().HadException());
235 ASSERT_TRUE(request1->transaction()); 204 ASSERT_TRUE(request1->transaction());
236 ASSERT_TRUE(request2->transaction()); 205 ASSERT_TRUE(request2->transaction());
237 request1->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); 206 request1->HandleResponse(CreateIDBValueForTesting(scope.GetIsolate(), true));
238 request2->HandleResponse(CreateIDBValue(scope.GetIsolate(), true)); 207 request2->HandleResponse(CreateIDBValueForTesting(scope.GetIsolate(), true));
239 scope.GetExecutionContext()->NotifyContextDestroyed(); 208 scope.GetExecutionContext()->NotifyContextDestroyed();
240 209
241 EnsureIDBCallbacksDontThrow(request1, scope.GetExceptionState()); 210 EnsureIDBCallbacksDontThrow(request1, scope.GetExceptionState());
242 EnsureIDBCallbacksDontThrow(request2, scope.GetExceptionState()); 211 EnsureIDBCallbacksDontThrow(request2, scope.GetExceptionState());
243 url_loader_mock_factory_->ServeAsynchronousRequests(); 212 url_loader_mock_factory_->ServeAsynchronousRequests();
244 EnsureIDBCallbacksDontThrow(request1, scope.GetExceptionState()); 213 EnsureIDBCallbacksDontThrow(request1, scope.GetExceptionState());
245 EnsureIDBCallbacksDontThrow(request2, scope.GetExceptionState()); 214 EnsureIDBCallbacksDontThrow(request2, scope.GetExceptionState());
246 } 215 }
247 216
248 TEST_F(IDBRequestTest, AbortErrorAfterAbort) { 217 TEST_F(IDBRequestTest, AbortErrorAfterAbort) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 346
378 EXPECT_TRUE(state.IsEmpty()); 347 EXPECT_TRUE(state.IsEmpty());
379 state = std::move(source_state); 348 state = std::move(source_state);
380 EXPECT_EQ(event_name, state.trace_event_name()); 349 EXPECT_EQ(event_name, state.trace_event_name());
381 EXPECT_EQ(id, state.id()); 350 EXPECT_EQ(id, state.id());
382 EXPECT_TRUE(source_state.IsEmpty()); 351 EXPECT_TRUE(source_state.IsEmpty());
383 } 352 }
384 353
385 } // namespace 354 } // namespace
386 } // namespace blink 355 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/fetch/BUILD.gn ('k') | third_party/WebKit/Source/modules/indexeddb/IDBTestHelper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698