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

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

Issue 134693005: Revert of IndexedDBFactory now ForceCloses databases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/test/test_simple_task_runner.h" 7 #include "base/test/test_simple_task_runner.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "content/browser/browser_thread_impl.h" 9 #include "content/browser/browser_thread_impl.h"
10 #include "content/browser/indexed_db/indexed_db_connection.h" 10 #include "content/browser/indexed_db/indexed_db_connection.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 // Make sure we wait until the destructor has run. 111 // Make sure we wait until the destructor has run.
112 message_loop_.RunUntilIdle(); 112 message_loop_.RunUntilIdle();
113 113
114 // No data was cleared because of SetForceKeepSessionState. 114 // No data was cleared because of SetForceKeepSessionState.
115 EXPECT_TRUE(base::DirectoryExists(normal_path)); 115 EXPECT_TRUE(base::DirectoryExists(normal_path));
116 EXPECT_TRUE(base::DirectoryExists(session_only_path)); 116 EXPECT_TRUE(base::DirectoryExists(session_only_path));
117 } 117 }
118 118
119 class ForceCloseDBCallbacks : public IndexedDBCallbacks { 119 class MockConnection : public IndexedDBConnection {
120 public: 120 public:
121 ForceCloseDBCallbacks(scoped_refptr<IndexedDBContextImpl> idb_context, 121 explicit MockConnection(bool expect_force_close)
122 const GURL& origin_url) 122 : IndexedDBConnection(NULL, NULL),
123 : IndexedDBCallbacks(NULL, 0, 0), 123 expect_force_close_(expect_force_close),
124 idb_context_(idb_context), 124 force_close_called_(false) {}
125 origin_url_(origin_url),
126 connection_(NULL) {}
127 125
128 virtual void OnSuccess() OVERRIDE {} 126 virtual ~MockConnection() {
129 virtual void OnSuccess(const std::vector<base::string16>&) OVERRIDE {} 127 EXPECT_TRUE(force_close_called_ == expect_force_close_);
130 virtual void OnSuccess(scoped_ptr<IndexedDBConnection> connection,
131 const IndexedDBDatabaseMetadata& metadata) OVERRIDE {
132 connection_ = connection.release();
133 idb_context_->ConnectionOpened(origin_url_, connection_);
134 } 128 }
135 129
136 IndexedDBConnection* connection() { return connection_; } 130 virtual void ForceClose() OVERRIDE {
131 ASSERT_TRUE(expect_force_close_);
132 force_close_called_ = true;
133 }
137 134
138 protected: 135 virtual bool IsConnected() OVERRIDE {
139 virtual ~ForceCloseDBCallbacks() {} 136 return !force_close_called_;
137 }
140 138
141 private: 139 private:
142 scoped_refptr<IndexedDBContextImpl> idb_context_; 140 bool expect_force_close_;
143 GURL origin_url_; 141 bool force_close_called_;
144 IndexedDBConnection* connection_;
145 DISALLOW_COPY_AND_ASSIGN(ForceCloseDBCallbacks);
146 }; 142 };
147 143
148 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) { 144 TEST_F(IndexedDBTest, ForceCloseOpenDatabasesOnDelete) {
149 base::ScopedTempDir temp_dir; 145 base::ScopedTempDir temp_dir;
150 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 146 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
151 147
152 scoped_refptr<MockIndexedDBDatabaseCallbacks> open_db_callbacks(
153 new MockIndexedDBDatabaseCallbacks());
154 scoped_refptr<MockIndexedDBDatabaseCallbacks> closed_db_callbacks(
155 new MockIndexedDBDatabaseCallbacks());
156
157 base::FilePath test_path; 148 base::FilePath test_path;
158 149
159 // Create the scope which will ensure we run the destructor of the context. 150 // Create the scope which will ensure we run the destructor of the context.
160 { 151 {
161 TestBrowserContext browser_context; 152 TestBrowserContext browser_context;
162 153
163 const GURL kTestOrigin("http://test/"); 154 const GURL kTestOrigin("http://test/");
164 155
165 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 156 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl(
166 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 157 temp_dir.path(), special_storage_policy_, NULL, task_runner_);
167 158
168 scoped_refptr<ForceCloseDBCallbacks> open_callbacks =
169 new ForceCloseDBCallbacks(idb_context, kTestOrigin);
170
171 scoped_refptr<ForceCloseDBCallbacks> closed_callbacks =
172 new ForceCloseDBCallbacks(idb_context, kTestOrigin);
173
174 IndexedDBFactory* factory = idb_context->GetIDBFactory();
175
176 test_path = idb_context->GetFilePathForTesting( 159 test_path = idb_context->GetFilePathForTesting(
177 webkit_database::GetIdentifierFromOrigin(kTestOrigin)); 160 webkit_database::GetIdentifierFromOrigin(kTestOrigin));
161 ASSERT_TRUE(base::CreateDirectory(test_path));
178 162
179 factory->Open(base::ASCIIToUTF16("opendb"), 163 const bool kExpectForceClose = true;
180 0,
181 0,
182 open_callbacks,
183 open_db_callbacks,
184 kTestOrigin,
185 idb_context->data_path());
186 factory->Open(base::ASCIIToUTF16("closeddb"),
187 0,
188 0,
189 closed_callbacks,
190 closed_db_callbacks,
191 kTestOrigin,
192 idb_context->data_path());
193 164
194 closed_callbacks->connection()->Close(); 165 MockConnection connection1(kExpectForceClose);
166 idb_context->TaskRunner()->PostTask(
167 FROM_HERE,
168 base::Bind(&IndexedDBContextImpl::ConnectionOpened,
169 idb_context,
170 kTestOrigin,
171 &connection1));
172
173 MockConnection connection2(!kExpectForceClose);
174 idb_context->TaskRunner()->PostTask(
175 FROM_HERE,
176 base::Bind(&IndexedDBContextImpl::ConnectionOpened,
177 idb_context,
178 kTestOrigin,
179 &connection2));
180 idb_context->TaskRunner()->PostTask(
181 FROM_HERE,
182 base::Bind(&IndexedDBContextImpl::ConnectionClosed,
183 idb_context,
184 kTestOrigin,
185 &connection2));
195 186
196 idb_context->TaskRunner()->PostTask( 187 idb_context->TaskRunner()->PostTask(
197 FROM_HERE, 188 FROM_HERE,
198 base::Bind( 189 base::Bind(
199 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin)); 190 &IndexedDBContextImpl::DeleteForOrigin, idb_context, kTestOrigin));
200 FlushIndexedDBTaskRunner(); 191 FlushIndexedDBTaskRunner();
201 message_loop_.RunUntilIdle(); 192 message_loop_.RunUntilIdle();
202 } 193 }
203 194
204 // Make sure we wait until the destructor has run. 195 // Make sure we wait until the destructor has run.
205 message_loop_.RunUntilIdle(); 196 message_loop_.RunUntilIdle();
206 197
207 EXPECT_TRUE(open_db_callbacks->forced_close_called());
208 EXPECT_FALSE(closed_db_callbacks->forced_close_called());
209 EXPECT_FALSE(base::DirectoryExists(test_path)); 198 EXPECT_FALSE(base::DirectoryExists(test_path));
210 } 199 }
211 200
212 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) { 201 TEST_F(IndexedDBTest, DeleteFailsIfDirectoryLocked) {
213 base::ScopedTempDir temp_dir; 202 base::ScopedTempDir temp_dir;
214 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 203 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
215 const GURL kTestOrigin("http://test/"); 204 const GURL kTestOrigin("http://test/");
216 205
217 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl( 206 scoped_refptr<IndexedDBContextImpl> idb_context = new IndexedDBContextImpl(
218 temp_dir.path(), special_storage_policy_, NULL, task_runner_); 207 temp_dir.path(), special_storage_policy_, NULL, task_runner_);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin)); 254 EXPECT_TRUE(factory->IsBackingStoreOpen(kTestOrigin));
266 255
267 // Simulate the write failure. 256 // Simulate the write failure.
268 callbacks->connection()->database()->TransactionCommitFailed(); 257 callbacks->connection()->database()->TransactionCommitFailed();
269 258
270 EXPECT_TRUE(db_callbacks->forced_close_called()); 259 EXPECT_TRUE(db_callbacks->forced_close_called());
271 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin)); 260 EXPECT_FALSE(factory->IsBackingStoreOpen(kTestOrigin));
272 } 261 }
273 262
274 } // namespace content 263 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698