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

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

Issue 198223002: Added IndexedDBPendingConnection to group up a bunch of parameters that get (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge out Created 6 years, 9 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 "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "content/browser/indexed_db/indexed_db.h" 11 #include "content/browser/indexed_db/indexed_db.h"
12 #include "content/browser/indexed_db/indexed_db_backing_store.h" 12 #include "content/browser/indexed_db/indexed_db_backing_store.h"
13 #include "content/browser/indexed_db/indexed_db_callbacks.h" 13 #include "content/browser/indexed_db/indexed_db_callbacks.h"
14 #include "content/browser/indexed_db/indexed_db_connection.h" 14 #include "content/browser/indexed_db/indexed_db_connection.h"
15 #include "content/browser/indexed_db/indexed_db_cursor.h" 15 #include "content/browser/indexed_db/indexed_db_cursor.h"
16 #include "content/browser/indexed_db/indexed_db_database.h" 16 #include "content/browser/indexed_db/indexed_db_database.h"
17 #include "content/browser/indexed_db/indexed_db_factory.h" 17 #include "content/browser/indexed_db/indexed_db_factory.h"
18 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h" 18 #include "content/browser/indexed_db/indexed_db_fake_backing_store.h"
19 #include "content/browser/indexed_db/indexed_db_transaction.h" 19 #include "content/browser/indexed_db/indexed_db_transaction.h"
20 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h" 20 #include "content/browser/indexed_db/mock_indexed_db_callbacks.h"
21 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h" 21 #include "content/browser/indexed_db/mock_indexed_db_database_callbacks.h"
22 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
23 23
24 using base::ASCIIToUTF16; 24 using base::ASCIIToUTF16;
25 25
26 namespace {
27 const int FAKE_CHILD_PROCESS_ID = 0;
28 }
29
26 namespace content { 30 namespace content {
27 31
28 TEST(IndexedDBDatabaseTest, BackingStoreRetention) { 32 TEST(IndexedDBDatabaseTest, BackingStoreRetention) {
29 scoped_refptr<IndexedDBFakeBackingStore> backing_store = 33 scoped_refptr<IndexedDBFakeBackingStore> backing_store =
30 new IndexedDBFakeBackingStore(); 34 new IndexedDBFakeBackingStore();
31 EXPECT_TRUE(backing_store->HasOneRef()); 35 EXPECT_TRUE(backing_store->HasOneRef());
32 36
33 IndexedDBFactory* factory = 0; 37 IndexedDBFactory* factory = 0;
34 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create( 38 scoped_refptr<IndexedDBDatabase> db = IndexedDBDatabase::Create(
35 ASCIIToUTF16("db"), 39 ASCIIToUTF16("db"),
(...skipping 16 matching lines...) Expand all
52 backing_store, 56 backing_store,
53 factory, 57 factory,
54 IndexedDBDatabase::Identifier()); 58 IndexedDBDatabase::Identifier());
55 59
56 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 60 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
57 61
58 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 62 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
59 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 63 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
60 new MockIndexedDBDatabaseCallbacks()); 64 new MockIndexedDBDatabaseCallbacks());
61 const int64 transaction_id1 = 1; 65 const int64 transaction_id1 = 1;
62 db->OpenConnection(request1, 66 IndexedDBPendingConnection connection1(
63 callbacks1, 67 request1,
64 transaction_id1, 68 callbacks1,
65 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 69 FAKE_CHILD_PROCESS_ID,
70 transaction_id1,
71 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
72 db->OpenConnection(connection1);
66 73
67 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0 74 EXPECT_FALSE(backing_store->HasOneRef()); // db, connection count > 0
68 75
69 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks()); 76 scoped_refptr<MockIndexedDBCallbacks> request2(new MockIndexedDBCallbacks());
70 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2( 77 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks2(
71 new MockIndexedDBDatabaseCallbacks()); 78 new MockIndexedDBDatabaseCallbacks());
72 const int64 transaction_id2 = 2; 79 const int64 transaction_id2 = 2;
73 db->OpenConnection(request2, 80 IndexedDBPendingConnection connection2(
74 callbacks2, 81 request2,
75 transaction_id2, 82 callbacks2,
76 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 83 FAKE_CHILD_PROCESS_ID,
84 transaction_id2,
85 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
86 db->OpenConnection(connection2);
77 87
78 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 88 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
79 89
80 request1->connection()->ForceClose(); 90 request1->connection()->ForceClose();
81 EXPECT_FALSE(request1->connection()->IsConnected()); 91 EXPECT_FALSE(request1->connection()->IsConnected());
82 92
83 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection 93 EXPECT_FALSE(backing_store->HasOneRef()); // local and connection
84 94
85 request2->connection()->ForceClose(); 95 request2->connection()->ForceClose();
86 EXPECT_FALSE(request2->connection()->IsConnected()); 96 EXPECT_FALSE(request2->connection()->IsConnected());
(...skipping 15 matching lines...) Expand all
102 backing_store, 112 backing_store,
103 factory, 113 factory,
104 IndexedDBDatabase::Identifier()); 114 IndexedDBDatabase::Identifier());
105 115
106 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 116 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
107 117
108 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks( 118 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks(
109 new MockIndexedDBDatabaseCallbacks()); 119 new MockIndexedDBDatabaseCallbacks());
110 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks()); 120 scoped_refptr<MockIndexedDBCallbacks> request(new MockIndexedDBCallbacks());
111 const int64 upgrade_transaction_id = 3; 121 const int64 upgrade_transaction_id = 3;
112 database->OpenConnection(request, 122 IndexedDBPendingConnection connection(
113 callbacks, 123 request,
114 upgrade_transaction_id, 124 callbacks,
115 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 125 FAKE_CHILD_PROCESS_ID,
126 upgrade_transaction_id,
127 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
128 database->OpenConnection(connection);
116 EXPECT_EQ(database, request->connection()->database()); 129 EXPECT_EQ(database, request->connection()->database());
117 130
118 const int64 transaction_id = 123; 131 const int64 transaction_id = 123;
119 const std::vector<int64> scope; 132 const std::vector<int64> scope;
120 database->CreateTransaction(transaction_id, 133 database->CreateTransaction(transaction_id,
121 request->connection(), 134 request->connection(),
122 scope, 135 scope,
123 indexed_db::TRANSACTION_READ_ONLY); 136 indexed_db::TRANSACTION_READ_ONLY);
124 137
125 request->connection()->ForceClose(); 138 request->connection()->ForceClose();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 backing_store, 173 backing_store,
161 factory, 174 factory,
162 IndexedDBDatabase::Identifier()); 175 IndexedDBDatabase::Identifier());
163 176
164 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 177 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
165 178
166 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks()); 179 scoped_refptr<MockIndexedDBCallbacks> request1(new MockIndexedDBCallbacks());
167 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1( 180 scoped_refptr<MockIndexedDBDatabaseCallbacks> callbacks1(
168 new MockIndexedDBDatabaseCallbacks()); 181 new MockIndexedDBDatabaseCallbacks());
169 const int64 transaction_id1 = 1; 182 const int64 transaction_id1 = 1;
170 db->OpenConnection(request1, 183 IndexedDBPendingConnection connection(
171 callbacks1, 184 request1,
172 transaction_id1, 185 callbacks1,
173 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION); 186 FAKE_CHILD_PROCESS_ID,
187 transaction_id1,
188 IndexedDBDatabaseMetadata::DEFAULT_INT_VERSION);
189 db->OpenConnection(connection);
174 190
175 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 191 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
176 192
177 scoped_refptr<MockDeleteCallbacks> request2(new MockDeleteCallbacks()); 193 scoped_refptr<MockDeleteCallbacks> request2(new MockDeleteCallbacks());
178 db->DeleteDatabase(request2); 194 db->DeleteDatabase(request2);
179 195
180 EXPECT_TRUE(request2->blocked_called()); 196 EXPECT_TRUE(request2->blocked_called());
181 EXPECT_FALSE(backing_store->HasOneRef()); // local and db 197 EXPECT_FALSE(backing_store->HasOneRef()); // local and db
182 198
183 db->Close(request1->connection(), true /* forced */); 199 db->Close(request1->connection(), true /* forced */);
184 200
185 EXPECT_FALSE(db->backing_store()); 201 EXPECT_FALSE(db->backing_store());
186 EXPECT_TRUE(backing_store->HasOneRef()); // local 202 EXPECT_TRUE(backing_store->HasOneRef()); // local
187 } 203 }
188 204
189 } // namespace content 205 } // 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.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698