Chromium Code Reviews| Index: third_party/WebKit/Source/modules/indexeddb/IDBRequestTest.cpp |
| diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBRequestTest.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBRequestTest.cpp |
| index 2cc605b92be177cc53feff78606da72fe3ffb058..fe9fa19039835d0a305541b0e6d42d089f577e24 100644 |
| --- a/third_party/WebKit/Source/modules/indexeddb/IDBRequestTest.cpp |
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBRequestTest.cpp |
| @@ -33,9 +33,11 @@ |
| #include "core/dom/ExceptionCode.h" |
| #include "core/dom/ExecutionContext.h" |
| #include "core/testing/NullExecutionContext.h" |
| +#include "modules/indexeddb/IDBDatabase.h" |
| #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
| #include "modules/indexeddb/IDBKey.h" |
| #include "modules/indexeddb/IDBOpenDBRequest.h" |
| +#include "modules/indexeddb/IDBTransaction.h" |
| #include "modules/indexeddb/IDBValue.h" |
| #include "modules/indexeddb/MockWebIDBDatabase.h" |
| #include "platform/SharedBuffer.h" |
| @@ -52,24 +54,42 @@ namespace { |
| TEST(IDBRequestTest, EventsAfterStopping) { |
| V8TestingScope scope; |
| - IDBTransaction* transaction = nullptr; |
| + Persistent<IDBDatabaseCallbacks> callbacks = IDBDatabaseCallbacks::Create(); |
| + std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); |
| + EXPECT_CALL(*backend, Close()).Times(1); |
| + IDBDatabase* database = |
| + IDBDatabase::Create(scope.GetExecutionContext(), std::move(backend), |
| + callbacks, scope.GetIsolate()); |
| + |
| + HashSet<String> transaction_scope = {"store"}; |
| + const int64_t kTransactionId = 1234; |
| + IDBTransaction* transaction = IDBTransaction::CreateNonVersionChange( |
| + scope.GetScriptState(), kTransactionId, transaction_scope, |
| + kWebIDBTransactionModeReadOnly, database); |
| + ASSERT_TRUE(!scope.GetExceptionState().HadException()); |
| + ASSERT_TRUE(transaction); |
| + |
| IDBRequest* request = IDBRequest::Create( |
| scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); |
| EXPECT_EQ(request->readyState(), "pending"); |
| + ASSERT_TRUE(!scope.GetExceptionState().HadException()); |
| + ASSERT_TRUE(request->transaction()); |
| scope.GetExecutionContext()->NotifyContextDestroyed(); |
|
jsbell
2017/05/22 21:54:19
We should have a similar unit test where the conte
dmurph
2017/05/23 18:16:39
+1
pwnall
2017/05/25 13:27:11
Acknowledged.
pwnall
2017/05/25 13:27:11
Done.
I wrote these tests for IDBRequest and IDBTr
|
| // Ensure none of the following raise assertions in stopped state: |
| - request->EnqueueResponse( |
| + ASSERT_TRUE(request->transaction()); |
| + request->HandleResponse( |
| DOMException::Create(kAbortError, "Description goes here.")); |
| + request->HandleResponse(nullptr, IDBKey::CreateInvalid(), |
| + IDBKey::CreateInvalid(), IDBValue::Create()); |
| + request->HandleResponse(IDBKey::CreateInvalid()); |
| + request->HandleResponse(IDBValue::Create()); |
| + request->HandleResponse(static_cast<int64_t>(0)); |
| + request->HandleResponse(); |
| + request->HandleResponse(IDBKey::CreateInvalid(), IDBKey::CreateInvalid(), |
| + IDBValue::Create()); |
| + |
| request->EnqueueResponse(Vector<String>()); |
| - request->EnqueueResponse(nullptr, IDBKey::CreateInvalid(), |
| - IDBKey::CreateInvalid(), IDBValue::Create()); |
| - request->EnqueueResponse(IDBKey::CreateInvalid()); |
| - request->EnqueueResponse(IDBValue::Create()); |
| - request->EnqueueResponse(static_cast<int64_t>(0)); |
| - request->EnqueueResponse(); |
| - request->EnqueueResponse(IDBKey::CreateInvalid(), IDBKey::CreateInvalid(), |
| - IDBValue::Create()); |
| } |
|
dmurph
2017/05/23 18:16:39
Can we add testing for the case where we fail to c
pwnall
2017/05/25 13:27:11
Ack.
Future work? According to [1-9], the transact
dmurph
2017/05/25 17:28:06
Acknowledged.
|
| TEST(IDBRequestTest, AbortErrorAfterAbort) { |
| @@ -85,7 +105,7 @@ TEST(IDBRequestTest, AbortErrorAfterAbort) { |
| // Now simulate the back end having fired an abort error at the request to |
| // clear up any intermediaries. Ensure an assertion is not raised. |
| - request->EnqueueResponse( |
| + request->HandleResponse( |
| DOMException::Create(kAbortError, "Description goes here.")); |
| // Stop the request lest it be GCed and its destructor |