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

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

Issue 2320213004: Port IndexedDB open() and database callbacks to Mojo. (Closed)
Patch Set: Make DatabaseClient an associated interface. Created 4 years, 3 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "modules/indexeddb/IDBTransaction.h" 31 #include "modules/indexeddb/IDBTransaction.h"
32 32
33 #include "bindings/core/v8/V8BindingForTesting.h" 33 #include "bindings/core/v8/V8BindingForTesting.h"
34 #include "core/dom/DOMException.h" 34 #include "core/dom/DOMException.h"
35 #include "core/dom/Document.h" 35 #include "core/dom/Document.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "modules/indexeddb/IDBDatabase.h" 37 #include "modules/indexeddb/IDBDatabase.h"
38 #include "modules/indexeddb/IDBDatabaseCallbacks.h"
39 #include "modules/indexeddb/MockWebIDBDatabase.h" 38 #include "modules/indexeddb/MockWebIDBDatabase.h"
40 #include "platform/SharedBuffer.h" 39 #include "platform/SharedBuffer.h"
41 #include "testing/gtest/include/gtest/gtest.h" 40 #include "testing/gtest/include/gtest/gtest.h"
42 #include <memory> 41 #include <memory>
43 #include <v8.h> 42 #include <v8.h>
44 43
45 namespace blink { 44 namespace blink {
46 namespace { 45 namespace {
47 46
48 void deactivateNewTransactions(v8::Isolate* isolate) 47 void deactivateNewTransactions(v8::Isolate* isolate)
49 { 48 {
50 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); 49 V8PerIsolateData::from(isolate)->runEndOfScopeTasks();
51 } 50 }
52 51
53 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks {
54 public:
55 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba cks(); }
56 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { }
57 void onForcedClose() override { }
58 void onAbort(int64_t transactionId, DOMException* error) override { }
59 void onComplete(int64_t transactionId) override { }
60 private:
61 FakeIDBDatabaseCallbacks() { }
62 };
63
64 TEST(IDBTransactionTest, EnsureLifetime) 52 TEST(IDBTransactionTest, EnsureLifetime)
65 { 53 {
66 V8TestingScope scope; 54 V8TestingScope scope;
67 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); 55 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create();
68 EXPECT_CALL(*backend, close()) 56 EXPECT_CALL(*backend, close())
69 .Times(1); 57 .Times(1);
70 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), FakeIDBDatabaseCallbacks::create()); 58 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), nullptr);
71 59
72 const int64_t transactionId = 1234; 60 const int64_t transactionId = 1234;
73 const HashSet<String> transactionScope = HashSet<String>(); 61 const HashSet<String> transactionScope = HashSet<String>();
74 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et()); 62 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et());
75 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; 63 PersistentHeapHashSet<WeakMember<IDBTransaction>> set;
76 set.add(transaction); 64 set.add(transaction);
77 65
78 ThreadState::current()-> collectAllGarbage(); 66 ThreadState::current()-> collectAllGarbage();
79 EXPECT_EQ(1u, set.size()); 67 EXPECT_EQ(1u, set.size());
80 68
(...skipping 16 matching lines...) Expand all
97 TEST(IDBTransactionTest, TransactionFinish) 85 TEST(IDBTransactionTest, TransactionFinish)
98 { 86 {
99 V8TestingScope scope; 87 V8TestingScope scope;
100 const int64_t transactionId = 1234; 88 const int64_t transactionId = 1234;
101 89
102 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); 90 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create();
103 EXPECT_CALL(*backend, commit(transactionId)) 91 EXPECT_CALL(*backend, commit(transactionId))
104 .Times(1); 92 .Times(1);
105 EXPECT_CALL(*backend, close()) 93 EXPECT_CALL(*backend, close())
106 .Times(1); 94 .Times(1);
107 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), FakeIDBDatabaseCallbacks::create()); 95 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), nullptr);
108 96
109 const HashSet<String> transactionScope = HashSet<String>(); 97 const HashSet<String> transactionScope = HashSet<String>();
110 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et()); 98 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et());
111 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; 99 PersistentHeapHashSet<WeakMember<IDBTransaction>> set;
112 set.add(transaction); 100 set.add(transaction);
113 101
114 ThreadState::current()-> collectAllGarbage(); 102 ThreadState::current()-> collectAllGarbage();
115 EXPECT_EQ(1u, set.size()); 103 EXPECT_EQ(1u, set.size());
116 104
117 deactivateNewTransactions(scope.isolate()); 105 deactivateNewTransactions(scope.isolate());
118 106
119 ThreadState::current()-> collectAllGarbage(); 107 ThreadState::current()-> collectAllGarbage();
120 EXPECT_EQ(1u, set.size()); 108 EXPECT_EQ(1u, set.size());
121 109
122 transaction.clear(); 110 transaction.clear();
123 111
124 ThreadState::current()-> collectAllGarbage(); 112 ThreadState::current()-> collectAllGarbage();
125 EXPECT_EQ(1u, set.size()); 113 EXPECT_EQ(1u, set.size());
126 114
127 // Stop the context, so events don't get queued (which would keep the transa ction alive). 115 // Stop the context, so events don't get queued (which would keep the transa ction alive).
128 scope.getExecutionContext()->stopActiveDOMObjects(); 116 scope.getExecutionContext()->stopActiveDOMObjects();
129 117
130 // Fire an abort to make sure this doesn't free the transaction during use. The test 118 // Fire an abort to make sure this doesn't free the transaction during use. The test
131 // will not fail if it is, but ASAN would notice the error. 119 // will not fail if it is, but ASAN would notice the error.
132 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); 120 auto errorInfo = indexed_db::mojom::blink::ErrorInfo::New();
121 errorInfo->code = AbortError;
122 errorInfo->message = "Aborted";
123 db->OnTransactionAborted(transactionId, std::move(errorInfo));
133 124
134 // onAbort() should have cleared the transaction's reference to the database . 125 // onAbort() should have cleared the transaction's reference to the database .
135 ThreadState::current()-> collectAllGarbage(); 126 ThreadState::current()-> collectAllGarbage();
136 EXPECT_EQ(0u, set.size()); 127 EXPECT_EQ(0u, set.size());
137 } 128 }
138 129
139 } // namespace 130 } // namespace
140 } // namespace blink 131 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698