OLD | NEW |
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 15 matching lines...) Expand all Loading... |
26 #include "modules/indexeddb/IDBRequest.h" | 26 #include "modules/indexeddb/IDBRequest.h" |
27 | 27 |
28 #include <memory> | 28 #include <memory> |
29 | 29 |
30 #include "bindings/core/v8/V8BindingForCore.h" | 30 #include "bindings/core/v8/V8BindingForCore.h" |
31 #include "bindings/core/v8/V8BindingForTesting.h" | 31 #include "bindings/core/v8/V8BindingForTesting.h" |
32 #include "core/dom/DOMException.h" | 32 #include "core/dom/DOMException.h" |
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/IDBDatabaseCallbacks.h" | 37 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
37 #include "modules/indexeddb/IDBKey.h" | 38 #include "modules/indexeddb/IDBKey.h" |
38 #include "modules/indexeddb/IDBOpenDBRequest.h" | 39 #include "modules/indexeddb/IDBOpenDBRequest.h" |
| 40 #include "modules/indexeddb/IDBTransaction.h" |
39 #include "modules/indexeddb/IDBValue.h" | 41 #include "modules/indexeddb/IDBValue.h" |
40 #include "modules/indexeddb/MockWebIDBDatabase.h" | 42 #include "modules/indexeddb/MockWebIDBDatabase.h" |
41 #include "platform/SharedBuffer.h" | 43 #include "platform/SharedBuffer.h" |
42 #include "platform/bindings/ScriptState.h" | 44 #include "platform/bindings/ScriptState.h" |
43 #include "platform/wtf/PassRefPtr.h" | 45 #include "platform/wtf/PassRefPtr.h" |
44 #include "platform/wtf/Vector.h" | 46 #include "platform/wtf/Vector.h" |
45 #include "platform/wtf/dtoa/utils.h" | 47 #include "platform/wtf/dtoa/utils.h" |
46 #include "public/platform/modules/indexeddb/WebIDBCallbacks.h" | 48 #include "public/platform/modules/indexeddb/WebIDBCallbacks.h" |
47 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
48 #include "v8/include/v8.h" | 50 #include "v8/include/v8.h" |
49 | 51 |
50 namespace blink { | 52 namespace blink { |
51 namespace { | 53 namespace { |
52 | 54 |
53 TEST(IDBRequestTest, EventsAfterStopping) { | 55 TEST(IDBRequestTest, EventsAfterStopping) { |
54 V8TestingScope scope; | 56 V8TestingScope scope; |
55 IDBTransaction* transaction = nullptr; | 57 Persistent<IDBDatabaseCallbacks> callbacks = IDBDatabaseCallbacks::Create(); |
| 58 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::Create(); |
| 59 EXPECT_CALL(*backend, Close()).Times(1); |
| 60 IDBDatabase* database = |
| 61 IDBDatabase::Create(scope.GetExecutionContext(), std::move(backend), |
| 62 callbacks, scope.GetIsolate()); |
| 63 HashSet<String> transaction_scope = {"store"}; |
| 64 const int64_t kTransactionId = 1234; |
| 65 IDBTransaction* transaction = IDBTransaction::CreateNonVersionChange( |
| 66 scope.GetScriptState(), kTransactionId, transaction_scope, |
| 67 kWebIDBTransactionModeReadOnly, database); |
56 IDBRequest* request = IDBRequest::Create( | 68 IDBRequest* request = IDBRequest::Create( |
57 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); | 69 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); |
58 EXPECT_EQ(request->readyState(), "pending"); | 70 EXPECT_EQ(request->readyState(), "pending"); |
59 scope.GetExecutionContext()->NotifyContextDestroyed(); | 71 scope.GetExecutionContext()->NotifyContextDestroyed(); |
60 | 72 |
61 // Ensure none of the following raise assertions in stopped state: | 73 // Ensure none of the following raise assertions in stopped state: |
62 request->EnqueueResponse( | 74 request->HandleResponse( |
63 DOMException::Create(kAbortError, "Description goes here.")); | 75 DOMException::Create(kAbortError, "Description goes here.")); |
| 76 request->HandleResponse(nullptr, IDBKey::CreateInvalid(), |
| 77 IDBKey::CreateInvalid(), IDBValue::Create()); |
| 78 request->HandleResponse(IDBKey::CreateInvalid()); |
| 79 request->HandleResponse(IDBValue::Create()); |
| 80 request->HandleResponse(static_cast<int64_t>(0)); |
| 81 request->HandleResponse(); |
| 82 request->HandleResponse(IDBKey::CreateInvalid(), IDBKey::CreateInvalid(), |
| 83 IDBValue::Create()); |
| 84 |
64 request->EnqueueResponse(Vector<String>()); | 85 request->EnqueueResponse(Vector<String>()); |
65 request->EnqueueResponse(nullptr, IDBKey::CreateInvalid(), | |
66 IDBKey::CreateInvalid(), IDBValue::Create()); | |
67 request->EnqueueResponse(IDBKey::CreateInvalid()); | |
68 request->EnqueueResponse(IDBValue::Create()); | |
69 request->EnqueueResponse(static_cast<int64_t>(0)); | |
70 request->EnqueueResponse(); | |
71 request->EnqueueResponse(IDBKey::CreateInvalid(), IDBKey::CreateInvalid(), | |
72 IDBValue::Create()); | |
73 } | 86 } |
74 | 87 |
75 TEST(IDBRequestTest, AbortErrorAfterAbort) { | 88 TEST(IDBRequestTest, AbortErrorAfterAbort) { |
76 V8TestingScope scope; | 89 V8TestingScope scope; |
77 IDBTransaction* transaction = nullptr; | 90 IDBTransaction* transaction = nullptr; |
78 IDBRequest* request = IDBRequest::Create( | 91 IDBRequest* request = IDBRequest::Create( |
79 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); | 92 scope.GetScriptState(), IDBAny::CreateUndefined(), transaction); |
80 EXPECT_EQ(request->readyState(), "pending"); | 93 EXPECT_EQ(request->readyState(), "pending"); |
81 | 94 |
82 // Simulate the IDBTransaction having received OnAbort from back end and | 95 // Simulate the IDBTransaction having received OnAbort from back end and |
83 // aborting the request: | 96 // aborting the request: |
84 request->Abort(); | 97 request->Abort(); |
85 | 98 |
86 // Now simulate the back end having fired an abort error at the request to | 99 // Now simulate the back end having fired an abort error at the request to |
87 // clear up any intermediaries. Ensure an assertion is not raised. | 100 // clear up any intermediaries. Ensure an assertion is not raised. |
88 request->EnqueueResponse( | 101 request->HandleResponse( |
89 DOMException::Create(kAbortError, "Description goes here.")); | 102 DOMException::Create(kAbortError, "Description goes here.")); |
90 | 103 |
91 // Stop the request lest it be GCed and its destructor | 104 // Stop the request lest it be GCed and its destructor |
92 // finds the object in a pending state (and asserts.) | 105 // finds the object in a pending state (and asserts.) |
93 scope.GetExecutionContext()->NotifyContextDestroyed(); | 106 scope.GetExecutionContext()->NotifyContextDestroyed(); |
94 } | 107 } |
95 | 108 |
96 TEST(IDBRequestTest, ConnectionsAfterStopping) { | 109 TEST(IDBRequestTest, ConnectionsAfterStopping) { |
97 V8TestingScope scope; | 110 V8TestingScope scope; |
98 const int64_t kTransactionId = 1234; | 111 const int64_t kTransactionId = 1234; |
(...skipping 23 matching lines...) Expand all Loading... |
122 EXPECT_EQ(request->readyState(), "pending"); | 135 EXPECT_EQ(request->readyState(), "pending"); |
123 std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); | 136 std::unique_ptr<WebIDBCallbacks> callbacks = request->CreateWebCallbacks(); |
124 | 137 |
125 scope.GetExecutionContext()->NotifyContextDestroyed(); | 138 scope.GetExecutionContext()->NotifyContextDestroyed(); |
126 callbacks->OnSuccess(backend.release(), metadata); | 139 callbacks->OnSuccess(backend.release(), metadata); |
127 } | 140 } |
128 } | 141 } |
129 | 142 |
130 } // namespace | 143 } // namespace |
131 } // namespace blink | 144 } // namespace blink |
OLD | NEW |