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

Side by Side Diff: content/browser/indexed_db/indexed_db_database_unittest.cc

Issue 18241003: IndexedDB: Remove IndexedDBCallbacksWrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Include/Forward Declare tidying Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/indexed_db/indexed_db_database.h" 5 #include "content/browser/indexed_db/indexed_db_database.h"
6 6
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "content/browser/indexed_db/indexed_db.h" 13 #include "content/browser/indexed_db/indexed_db.h"
14 #include "content/browser/indexed_db/indexed_db_backing_store.h" 14 #include "content/browser/indexed_db/indexed_db_backing_store.h"
15 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" 15 #include "content/browser/indexed_db/indexed_db_callbacks.h"
16 #include "content/browser/indexed_db/indexed_db_cursor.h" 16 #include "content/browser/indexed_db/indexed_db_cursor.h"
17 #include "content/browser/indexed_db/indexed_db_database.h" 17 #include "content/browser/indexed_db/indexed_db_database.h"
18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h" 18 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
19 #include "content/browser/indexed_db/indexed_db_factory.h" 19 #include "content/browser/indexed_db/indexed_db_factory.h"
20 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" 20 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h"
21 #include "content/browser/indexed_db/indexed_db_transaction.h" 21 #include "content/browser/indexed_db/indexed_db_transaction.h"
22 #include "content/browser/indexed_db/webidbdatabase_impl.h" 22 #include "content/browser/indexed_db/webidbdatabase_impl.h"
23 23
24 namespace content { 24 namespace content {
25 25
26 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { 26 TEST(IndexedDBDatabaseTest, BackingStoreRetention) {
27 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 27 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
28 new IndexedDBFakeBackingStore(); 28 new IndexedDBFakeBackingStore();
29 EXPECT_TRUE(backing_store->HasOneRef()); 29 EXPECT_TRUE(backing_store->HasOneRef());
30 30
31 IndexedDBFactory* factory = 0; 31 IndexedDBFactory* factory = 0;
32 scoped_refptr<IndexedDBDatabase> db = 32 scoped_refptr<IndexedDBDatabase> db =
33 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 33 IndexedDBDatabase::Create(ASCIIToUTF16("db"),
34 backing_store.get(), 34 backing_store.get(),
35 factory, 35 factory,
36 ASCIIToUTF16("uniqueid")); 36 ASCIIToUTF16("uniqueid"));
37 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 37 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
38 db = NULL; 38 db = NULL;
39 EXPECT_TRUE(backing_store->HasOneRef()); // local 39 EXPECT_TRUE(backing_store->HasOneRef()); // local
40 } 40 }
41 41
42 class MockIDBCallbacks : public IndexedDBCallbacksWrapper { 42 class MockIDBCallbacks : public IndexedDBCallbacks {
43 public: 43 public:
44 static scoped_refptr<MockIDBCallbacks> Create() { 44 static scoped_refptr<MockIDBCallbacks> Create() {
45 return make_scoped_refptr(new MockIDBCallbacks()); 45 return make_scoped_refptr(new MockIDBCallbacks());
46 } 46 }
47 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE {} 47 virtual void OnError(const IndexedDBDatabaseError& error) OVERRIDE {}
48 virtual void OnSuccess(const std::vector<string16>& value) OVERRIDE {} 48 virtual void OnSuccess(const std::vector<string16>& value) OVERRIDE {}
49 virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor, 49 virtual void OnSuccess(scoped_refptr<IndexedDBCursor> cursor,
50 const IndexedDBKey& key, 50 const IndexedDBKey& key,
51 const IndexedDBKey& primary_key, 51 const IndexedDBKey& primary_key,
52 std::vector<char>* value) OVERRIDE {} 52 std::vector<char>* value) OVERRIDE {}
(...skipping 12 matching lines...) Expand all
65 const IndexedDBKey& primary_key, 65 const IndexedDBKey& primary_key,
66 std::vector<char>* value) OVERRIDE {} 66 std::vector<char>* value) OVERRIDE {}
67 virtual void OnSuccessWithPrefetch( 67 virtual void OnSuccessWithPrefetch(
68 const std::vector<IndexedDBKey>& keys, 68 const std::vector<IndexedDBKey>& keys,
69 const std::vector<IndexedDBKey>& primary_keys, 69 const std::vector<IndexedDBKey>& primary_keys,
70 const std::vector<std::vector<char> >& values) OVERRIDE {} 70 const std::vector<std::vector<char> >& values) OVERRIDE {}
71 71
72 private: 72 private:
73 virtual ~MockIDBCallbacks() { EXPECT_TRUE(was_success_db_called_); } 73 virtual ~MockIDBCallbacks() { EXPECT_TRUE(was_success_db_called_); }
74 MockIDBCallbacks() 74 MockIDBCallbacks()
75 : IndexedDBCallbacksWrapper(NULL), was_success_db_called_(false) {} 75 : IndexedDBCallbacks(NULL, 0, 0), was_success_db_called_(false) {}
76 bool was_success_db_called_; 76 bool was_success_db_called_;
77 }; 77 };
78 78
79 class FakeIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacks { 79 class FakeIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacks {
80 public: 80 public:
81 static scoped_refptr<FakeIDBDatabaseCallbacks> Create() { 81 static scoped_refptr<FakeIDBDatabaseCallbacks> Create() {
82 return make_scoped_refptr(new FakeIDBDatabaseCallbacks()); 82 return make_scoped_refptr(new FakeIDBDatabaseCallbacks());
83 } 83 }
84 virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {} 84 virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {}
85 virtual void OnForcedClose() OVERRIDE {} 85 virtual void OnForcedClose() OVERRIDE {}
86 virtual void OnAbort(int64 transaction_id, 86 virtual void OnAbort(int64 transaction_id,
87 const IndexedDBDatabaseError& error) OVERRIDE {} 87 const IndexedDBDatabaseError& error) OVERRIDE {}
88 virtual void OnComplete(int64 transaction_id) OVERRIDE {} 88 virtual void OnComplete(int64 transaction_id) OVERRIDE {}
89 89
90 private: 90 private:
91 friend class base::RefCounted<FakeIDBDatabaseCallbacks>; 91 friend class base::RefCounted<FakeIDBDatabaseCallbacks>;
92 virtual ~FakeIDBDatabaseCallbacks() {} 92 virtual ~FakeIDBDatabaseCallbacks() {}
93 FakeIDBDatabaseCallbacks() : IndexedDBDatabaseCallbacks(NULL, 0, 0) {} 93 FakeIDBDatabaseCallbacks() : IndexedDBDatabaseCallbacks(NULL, 0, 0) {}
94 }; 94 };
95 95
96 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) { 96 TEST(IndexedDBDatabaseTest, ConnectionLifecycle) {
97 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 97 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
98 new IndexedDBFakeBackingStore(); 98 new IndexedDBFakeBackingStore();
99 EXPECT_TRUE(backing_store->HasOneRef()); // local 99 EXPECT_TRUE(backing_store->HasOneRef()); // local
100 100
101 IndexedDBFactory* factory = 0; 101 IndexedDBFactory* factory = 0;
102 scoped_refptr<IndexedDBDatabase> db = 102 scoped_refptr<IndexedDBDatabase> db =
103 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 103 IndexedDBDatabase::Create(ASCIIToUTF16("db"),
104 backing_store.get(), 104 backing_store.get(),
105 factory, 105 factory,
106 ASCIIToUTF16("uniqueid")); 106 ASCIIToUTF16("uniqueid"));
107 107
108 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 108 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
109 109
110 scoped_refptr<MockIDBCallbacks> request1 = MockIDBCallbacks::Create(); 110 scoped_refptr<MockIDBCallbacks> request1 = MockIDBCallbacks::Create();
111 scoped_refptr<FakeIDBDatabaseCallbacks> connection1 = 111 scoped_refptr<FakeIDBDatabaseCallbacks> connection1 =
112 FakeIDBDatabaseCallbacks::Create(); 112 FakeIDBDatabaseCallbacks::Create();
113 const int64 transaction_id1 = 1; 113 const int64 transaction_id1 = 1;
114 db->OpenConnection(request1, 114 db->OpenConnection(request1,
115 connection1, 115 connection1,
116 transaction_id1, 116 transaction_id1,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {} 148 virtual void OnVersionChange(int64 old_version, int64 new_version) OVERRIDE {}
149 virtual void OnForcedClose() OVERRIDE {} 149 virtual void OnForcedClose() OVERRIDE {}
150 virtual void OnAbort(int64 transaction_id, 150 virtual void OnAbort(int64 transaction_id,
151 const IndexedDBDatabaseError& error) OVERRIDE { 151 const IndexedDBDatabaseError& error) OVERRIDE {
152 was_abort_called_ = true; 152 was_abort_called_ = true;
153 } 153 }
154 virtual void OnComplete(int64 transaction_id) OVERRIDE {} 154 virtual void OnComplete(int64 transaction_id) OVERRIDE {}
155 155
156 private: 156 private:
157 MockIDBDatabaseCallbacks() 157 MockIDBDatabaseCallbacks()
158 : IndexedDBDatabaseCallbacks(NULL, 0, 0), 158 : IndexedDBDatabaseCallbacks(NULL, 0, 0), was_abort_called_(false) {}
159 was_abort_called_(false) {}
160 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); } 159 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); }
161 bool was_abort_called_; 160 bool was_abort_called_;
162 }; 161 };
163 162
164 TEST(IndexedDBDatabaseTest, ForcedClose) { 163 TEST(IndexedDBDatabaseTest, ForcedClose) {
165 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 164 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
166 new IndexedDBFakeBackingStore(); 165 new IndexedDBFakeBackingStore();
167 EXPECT_TRUE(backing_store->HasOneRef()); 166 EXPECT_TRUE(backing_store->HasOneRef());
168 167
169 IndexedDBFactory* factory = 0; 168 IndexedDBFactory* factory = 0;
170 scoped_refptr<IndexedDBDatabase> backend = 169 scoped_refptr<IndexedDBDatabase> backend =
171 IndexedDBDatabase::Create(ASCIIToUTF16("db"), 170 IndexedDBDatabase::Create(ASCIIToUTF16("db"),
172 backing_store.get(), 171 backing_store.get(),
173 factory, 172 factory,
174 ASCIIToUTF16("uniqueid")); 173 ASCIIToUTF16("uniqueid"));
175 174
176 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 175 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
177 176
178 scoped_refptr<MockIDBDatabaseCallbacks> connection = 177 scoped_refptr<MockIDBDatabaseCallbacks> connection =
179 MockIDBDatabaseCallbacks::Create(); 178 MockIDBDatabaseCallbacks::Create();
180 WebIDBDatabaseImpl web_database(backend, connection); 179 WebIDBDatabaseImpl web_database(backend, connection);
181 180
182 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create(); 181 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create();
183 const int64 upgrade_transaction_id = 3; 182 const int64 upgrade_transaction_id = 3;
184 backend->OpenConnection(request, 183 backend->OpenConnection(request,
185 connection, 184 connection,
186 upgrade_transaction_id, 185 upgrade_transaction_id,
187 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 186 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
188 187
189 const int64 transaction_id = 123; 188 const int64 transaction_id = 123;
190 const std::vector<int64> scope; 189 const std::vector<int64> scope;
191 web_database.createTransaction( 190 web_database.createTransaction(
192 transaction_id, scope, indexed_db::TRANSACTION_READ_ONLY); 191 transaction_id, scope, indexed_db::TRANSACTION_READ_ONLY);
193 192
194 web_database.forceClose(); 193 web_database.forceClose();
195 194
196 EXPECT_TRUE(backing_store->HasOneRef()); // local 195 EXPECT_TRUE(backing_store->HasOneRef()); // local
197 } 196 }
198 197
199 } // namespace content 198 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database.cc ('k') | content/browser/indexed_db/indexed_db_dispatcher_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698