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

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

Issue 18224002: IndexedDB: Eliminate IndexedDBDatabaseCallbacksWrapper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Include fix for win 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"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 : IndexedDBCallbacksWrapper(NULL), 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 IndexedDBDatabaseCallbacksWrapper { 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() : IndexedDBDatabaseCallbacksWrapper(NULL) {} 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"),
(...skipping 29 matching lines...) Expand all
133 133
134 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 134 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
135 135
136 db->Close(connection2); 136 db->Close(connection2);
137 EXPECT_TRUE(backing_store->HasOneRef()); 137 EXPECT_TRUE(backing_store->HasOneRef());
138 EXPECT_FALSE(db->BackingStore().get()); 138 EXPECT_FALSE(db->BackingStore().get());
139 139
140 db = NULL; 140 db = NULL;
141 } 141 }
142 142
143 class MockIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacksWrapper { 143 class MockIDBDatabaseCallbacks : public IndexedDBDatabaseCallbacks {
144 public: 144 public:
145 static scoped_refptr<MockIDBDatabaseCallbacks> Create() { 145 static scoped_refptr<MockIDBDatabaseCallbacks> Create() {
146 return make_scoped_refptr(new MockIDBDatabaseCallbacks()); 146 return make_scoped_refptr(new MockIDBDatabaseCallbacks());
147 } 147 }
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 : IndexedDBDatabaseCallbacksWrapper(NULL), was_abort_called_(false) {} 158 : IndexedDBDatabaseCallbacks(NULL, 0, 0),
159 was_abort_called_(false) {}
159 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); } 160 virtual ~MockIDBDatabaseCallbacks() { EXPECT_TRUE(was_abort_called_); }
160 bool was_abort_called_; 161 bool was_abort_called_;
161 }; 162 };
162 163
163 TEST(IndexedDBDatabaseTest, ForcedClose) { 164 TEST(IndexedDBDatabaseTest, ForcedClose) {
164 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 165 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
165 new IndexedDBFakeBackingStore(); 166 new IndexedDBFakeBackingStore();
166 EXPECT_TRUE(backing_store->HasOneRef()); 167 EXPECT_TRUE(backing_store->HasOneRef());
167 168
168 IndexedDBFactory* factory = 0; 169 IndexedDBFactory* factory = 0;
(...skipping 12 matching lines...) Expand all
181 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create(); 182 scoped_refptr<MockIDBCallbacks> request = MockIDBCallbacks::Create();
182 const int64 upgrade_transaction_id = 3; 183 const int64 upgrade_transaction_id = 3;
183 backend->OpenConnection(request, 184 backend->OpenConnection(request,
184 connection, 185 connection,
185 upgrade_transaction_id, 186 upgrade_transaction_id,
186 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 187 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
187 188
188 const int64 transaction_id = 123; 189 const int64 transaction_id = 123;
189 const std::vector<int64> scope; 190 const std::vector<int64> scope;
190 web_database.createTransaction( 191 web_database.createTransaction(
191 transaction_id, 0, scope, indexed_db::TRANSACTION_READ_ONLY); 192 transaction_id, scope, indexed_db::TRANSACTION_READ_ONLY);
192 193
193 web_database.forceClose(); 194 web_database.forceClose();
194 195
195 EXPECT_TRUE(backing_store->HasOneRef()); // local 196 EXPECT_TRUE(backing_store->HasOneRef()); // local
196 } 197 }
197 198
198 } // namespace content 199 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698