OLD | NEW |
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 21 matching lines...) Expand all Loading... |
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" | 38 #include "modules/indexeddb/IDBDatabaseCallbacks.h" |
39 #include "modules/indexeddb/MockWebIDBDatabase.h" | 39 #include "modules/indexeddb/MockWebIDBDatabase.h" |
40 #include "platform/SharedBuffer.h" | 40 #include "platform/SharedBuffer.h" |
41 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include <memory> |
42 #include <v8.h> | 43 #include <v8.h> |
43 | 44 |
44 namespace blink { | 45 namespace blink { |
45 namespace { | 46 namespace { |
46 | 47 |
47 void deactivateNewTransactions(v8::Isolate* isolate) | 48 void deactivateNewTransactions(v8::Isolate* isolate) |
48 { | 49 { |
49 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); | 50 V8PerIsolateData::from(isolate)->runEndOfScopeTasks(); |
50 } | 51 } |
51 | 52 |
52 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { | 53 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks { |
53 public: | 54 public: |
54 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } | 55 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba
cks(); } |
55 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } | 56 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } |
56 void onForcedClose() override { } | 57 void onForcedClose() override { } |
57 void onAbort(int64_t transactionId, DOMException* error) override { } | 58 void onAbort(int64_t transactionId, DOMException* error) override { } |
58 void onComplete(int64_t transactionId) override { } | 59 void onComplete(int64_t transactionId) override { } |
59 private: | 60 private: |
60 FakeIDBDatabaseCallbacks() { } | 61 FakeIDBDatabaseCallbacks() { } |
61 }; | 62 }; |
62 | 63 |
63 TEST(IDBTransactionTest, EnsureLifetime) | 64 TEST(IDBTransactionTest, EnsureLifetime) |
64 { | 65 { |
65 V8TestingScope scope; | 66 V8TestingScope scope; |
66 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 67 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
67 EXPECT_CALL(*backend, close()) | 68 EXPECT_CALL(*backend, close()) |
68 .Times(1); | 69 .Times(1); |
69 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); | 70 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); |
70 | 71 |
71 const int64_t transactionId = 1234; | 72 const int64_t transactionId = 1234; |
72 const HashSet<String> transactionScope = HashSet<String>(); | 73 const HashSet<String> transactionScope = HashSet<String>(); |
73 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); | 74 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); |
74 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 75 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
75 set.add(transaction); | 76 set.add(transaction); |
76 | 77 |
(...skipping 14 matching lines...) Expand all Loading... |
91 | 92 |
92 ThreadHeap::collectAllGarbage(); | 93 ThreadHeap::collectAllGarbage(); |
93 EXPECT_EQ(0u, set.size()); | 94 EXPECT_EQ(0u, set.size()); |
94 } | 95 } |
95 | 96 |
96 TEST(IDBTransactionTest, TransactionFinish) | 97 TEST(IDBTransactionTest, TransactionFinish) |
97 { | 98 { |
98 V8TestingScope scope; | 99 V8TestingScope scope; |
99 const int64_t transactionId = 1234; | 100 const int64_t transactionId = 1234; |
100 | 101 |
101 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); | 102 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); |
102 EXPECT_CALL(*backend, commit(transactionId)) | 103 EXPECT_CALL(*backend, commit(transactionId)) |
103 .Times(1); | 104 .Times(1); |
104 EXPECT_CALL(*backend, close()) | 105 EXPECT_CALL(*backend, close()) |
105 .Times(1); | 106 .Times(1); |
106 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); | 107 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext()
, std::move(backend), FakeIDBDatabaseCallbacks::create()); |
107 | 108 |
108 const HashSet<String> transactionScope = HashSet<String>(); | 109 const HashSet<String> transactionScope = HashSet<String>(); |
109 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); | 110 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr
iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g
et()); |
110 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; | 111 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; |
111 set.add(transaction); | 112 set.add(transaction); |
(...skipping 18 matching lines...) Expand all Loading... |
130 // will not fail if it is, but ASAN would notice the error. | 131 // will not fail if it is, but ASAN would notice the error. |
131 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); | 132 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); |
132 | 133 |
133 // onAbort() should have cleared the transaction's reference to the database
. | 134 // onAbort() should have cleared the transaction's reference to the database
. |
134 ThreadHeap::collectAllGarbage(); | 135 ThreadHeap::collectAllGarbage(); |
135 EXPECT_EQ(0u, set.size()); | 136 EXPECT_EQ(0u, set.size()); |
136 } | 137 } |
137 | 138 |
138 } // namespace | 139 } // namespace |
139 } // namespace blink | 140 } // namespace blink |
OLD | NEW |