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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 21 matching lines...) Expand all
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>
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 { 52 class FakeIDBDatabaseCallbacks final : public IDBDatabaseCallbacks {
54 public: 53 public:
55 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba cks(); } 54 static FakeIDBDatabaseCallbacks* create() { return new FakeIDBDatabaseCallba cks(); }
56 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { } 55 void onVersionChange(int64_t oldVersion, int64_t newVersion) override { }
57 void onForcedClose() override { } 56 void onForcedClose() override { }
58 void onAbort(int64_t transactionId, DOMException* error) override { } 57 void onAbort(int64_t transactionId, DOMException* error) override { }
59 void onComplete(int64_t transactionId) override { } 58 void onComplete(int64_t transactionId) override { }
60 private: 59 private:
61 FakeIDBDatabaseCallbacks() { } 60 FakeIDBDatabaseCallbacks() { }
62 }; 61 };
63 62
64 TEST(IDBTransactionTest, EnsureLifetime) 63 TEST(IDBTransactionTest, EnsureLifetime)
65 { 64 {
66 V8TestingScope scope; 65 V8TestingScope scope;
67 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); 66 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create();
68 EXPECT_CALL(*backend, close()) 67 EXPECT_CALL(*backend, close())
69 .Times(1); 68 .Times(1);
70 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), FakeIDBDatabaseCallbacks::create()); 69 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), FakeIDBDatabaseCallbacks::create());
71 70
72 const int64_t transactionId = 1234; 71 const int64_t transactionId = 1234;
73 const HashSet<String> transactionScope = HashSet<String>(); 72 const HashSet<String> transactionScope = HashSet<String>();
74 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et()); 73 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et());
75 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; 74 PersistentHeapHashSet<WeakMember<IDBTransaction>> set;
76 set.add(transaction); 75 set.add(transaction);
77 76
(...skipping 14 matching lines...) Expand all
92 91
93 ThreadHeap::collectAllGarbage(); 92 ThreadHeap::collectAllGarbage();
94 EXPECT_EQ(0u, set.size()); 93 EXPECT_EQ(0u, set.size());
95 } 94 }
96 95
97 TEST(IDBTransactionTest, TransactionFinish) 96 TEST(IDBTransactionTest, TransactionFinish)
98 { 97 {
99 V8TestingScope scope; 98 V8TestingScope scope;
100 const int64_t transactionId = 1234; 99 const int64_t transactionId = 1234;
101 100
102 std::unique_ptr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create(); 101 OwnPtr<MockWebIDBDatabase> backend = MockWebIDBDatabase::create();
103 EXPECT_CALL(*backend, commit(transactionId)) 102 EXPECT_CALL(*backend, commit(transactionId))
104 .Times(1); 103 .Times(1);
105 EXPECT_CALL(*backend, close()) 104 EXPECT_CALL(*backend, close())
106 .Times(1); 105 .Times(1);
107 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), FakeIDBDatabaseCallbacks::create()); 106 Persistent<IDBDatabase> db = IDBDatabase::create(scope.getExecutionContext() , std::move(backend), FakeIDBDatabaseCallbacks::create());
108 107
109 const HashSet<String> transactionScope = HashSet<String>(); 108 const HashSet<String> transactionScope = HashSet<String>();
110 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et()); 109 Persistent<IDBTransaction> transaction = IDBTransaction::create(scope.getScr iptState(), transactionId, transactionScope, WebIDBTransactionModeReadOnly, db.g et());
111 PersistentHeapHashSet<WeakMember<IDBTransaction>> set; 110 PersistentHeapHashSet<WeakMember<IDBTransaction>> set;
112 set.add(transaction); 111 set.add(transaction);
(...skipping 18 matching lines...) Expand all
131 // will not fail if it is, but ASAN would notice the error. 130 // will not fail if it is, but ASAN would notice the error.
132 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted")); 131 db->onAbort(transactionId, DOMException::create(AbortError, "Aborted"));
133 132
134 // onAbort() should have cleared the transaction's reference to the database . 133 // onAbort() should have cleared the transaction's reference to the database .
135 ThreadHeap::collectAllGarbage(); 134 ThreadHeap::collectAllGarbage();
136 EXPECT_EQ(0u, set.size()); 135 EXPECT_EQ(0u, set.size());
137 } 136 }
138 137
139 } // namespace 138 } // namespace
140 } // namespace blink 139 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/indexeddb/IDBTransaction.cpp ('k') | third_party/WebKit/Source/modules/indexeddb/IDBValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698