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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_database_unittest.cc

Issue 1064523002: [sql] Clients should use sql::Connection::Delete(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Drop unnecessary change. Created 5 years, 8 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 // 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 ActivityDatabaseTestPolicy* db_delegate_; 168 ActivityDatabaseTestPolicy* db_delegate_;
169 }; 169 };
170 170
171 // Check that the database is initialized properly. 171 // Check that the database is initialized properly.
172 TEST_F(ActivityDatabaseTest, Init) { 172 TEST_F(ActivityDatabaseTest, Init) {
173 base::ScopedTempDir temp_dir; 173 base::ScopedTempDir temp_dir;
174 base::FilePath db_file; 174 base::FilePath db_file;
175 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 175 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
176 db_file = temp_dir.path().AppendASCII("ActivityInit.db"); 176 db_file = temp_dir.path().AppendASCII("ActivityInit.db");
177 base::DeleteFile(db_file, false); 177 sql::Connection::Delete(db_file);
178 178
179 ActivityDatabase* activity_db = OpenDatabase(db_file); 179 ActivityDatabase* activity_db = OpenDatabase(db_file);
180 activity_db->Close(); 180 activity_db->Close();
181 181
182 sql::Connection db; 182 sql::Connection db;
183 ASSERT_TRUE(db.Open(db_file)); 183 ASSERT_TRUE(db.Open(db_file));
184 ASSERT_TRUE(db.DoesTableExist(ActivityDatabaseTestPolicy::kTableName)); 184 ASSERT_TRUE(db.DoesTableExist(ActivityDatabaseTestPolicy::kTableName));
185 db.Close(); 185 db.Close();
186 } 186 }
187 187
188 // Check that actions are recorded in the db. 188 // Check that actions are recorded in the db.
189 TEST_F(ActivityDatabaseTest, RecordAction) { 189 TEST_F(ActivityDatabaseTest, RecordAction) {
190 base::ScopedTempDir temp_dir; 190 base::ScopedTempDir temp_dir;
191 base::FilePath db_file; 191 base::FilePath db_file;
192 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 192 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
193 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 193 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
194 base::DeleteFile(db_file, false); 194 sql::Connection::Delete(db_file);
195 195
196 ActivityDatabase* activity_db = OpenDatabase(db_file); 196 ActivityDatabase* activity_db = OpenDatabase(db_file);
197 activity_db->SetBatchModeForTesting(false); 197 activity_db->SetBatchModeForTesting(false);
198 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster"); 198 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster");
199 Record(activity_db, action); 199 Record(activity_db, action);
200 activity_db->Close(); 200 activity_db->Close();
201 201
202 sql::Connection db; 202 sql::Connection db;
203 ASSERT_TRUE(db.Open(db_file)); 203 ASSERT_TRUE(db.Open(db_file));
204 204
205 ASSERT_EQ(1, CountActions(&db, "brewster")); 205 ASSERT_EQ(1, CountActions(&db, "brewster"));
206 } 206 }
207 207
208 TEST_F(ActivityDatabaseTest, BatchModeOff) { 208 TEST_F(ActivityDatabaseTest, BatchModeOff) {
209 base::ScopedTempDir temp_dir; 209 base::ScopedTempDir temp_dir;
210 base::FilePath db_file; 210 base::FilePath db_file;
211 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 211 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
212 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 212 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
213 base::DeleteFile(db_file, false); 213 sql::Connection::Delete(db_file);
214 214
215 // Record some actions 215 // Record some actions
216 ActivityDatabase* activity_db = OpenDatabase(db_file); 216 ActivityDatabase* activity_db = OpenDatabase(db_file);
217 activity_db->SetBatchModeForTesting(false); 217 activity_db->SetBatchModeForTesting(false);
218 218
219 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster"); 219 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster");
220 Record(activity_db, action); 220 Record(activity_db, action);
221 ASSERT_EQ(1, CountActions(&activity_db->db_, "brewster")); 221 ASSERT_EQ(1, CountActions(&activity_db->db_, "brewster"));
222 222
223 activity_db->Close(); 223 activity_db->Close();
224 } 224 }
225 225
226 TEST_F(ActivityDatabaseTest, BatchModeOn) { 226 TEST_F(ActivityDatabaseTest, BatchModeOn) {
227 base::ScopedTempDir temp_dir; 227 base::ScopedTempDir temp_dir;
228 base::FilePath db_file; 228 base::FilePath db_file;
229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 229 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
230 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 230 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
231 base::DeleteFile(db_file, false); 231 sql::Connection::Delete(db_file);
232 232
233 // Record some actions 233 // Record some actions
234 ActivityDatabase* activity_db = OpenDatabase(db_file); 234 ActivityDatabase* activity_db = OpenDatabase(db_file);
235 activity_db->SetBatchModeForTesting(true); 235 activity_db->SetBatchModeForTesting(true);
236 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster"); 236 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster");
237 Record(activity_db, action); 237 Record(activity_db, action);
238 ASSERT_EQ(0, CountActions(&activity_db->db_, "brewster")); 238 ASSERT_EQ(0, CountActions(&activity_db->db_, "brewster"));
239 239
240 // Artificially trigger and then stop the timer. 240 // Artificially trigger and then stop the timer.
241 activity_db->SetTimerForTesting(0); 241 activity_db->SetTimerForTesting(0);
242 base::MessageLoop::current()->RunUntilIdle(); 242 base::MessageLoop::current()->RunUntilIdle();
243 ASSERT_EQ(1, CountActions(&activity_db->db_, "brewster")); 243 ASSERT_EQ(1, CountActions(&activity_db->db_, "brewster"));
244 244
245 activity_db->Close(); 245 activity_db->Close();
246 } 246 }
247 247
248 TEST_F(ActivityDatabaseTest, BatchModeFlush) { 248 TEST_F(ActivityDatabaseTest, BatchModeFlush) {
249 base::ScopedTempDir temp_dir; 249 base::ScopedTempDir temp_dir;
250 base::FilePath db_file; 250 base::FilePath db_file;
251 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 251 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
252 db_file = temp_dir.path().AppendASCII("ActivityFlush.db"); 252 db_file = temp_dir.path().AppendASCII("ActivityFlush.db");
253 base::DeleteFile(db_file, false); 253 sql::Connection::Delete(db_file);
254 254
255 // Record some actions 255 // Record some actions
256 ActivityDatabase* activity_db = OpenDatabase(db_file); 256 ActivityDatabase* activity_db = OpenDatabase(db_file);
257 activity_db->SetBatchModeForTesting(true); 257 activity_db->SetBatchModeForTesting(true);
258 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster"); 258 scoped_refptr<Action> action = CreateAction(base::Time::Now(), "brewster");
259 Record(activity_db, action); 259 Record(activity_db, action);
260 ASSERT_EQ(0, CountActions(&activity_db->db_, "brewster")); 260 ASSERT_EQ(0, CountActions(&activity_db->db_, "brewster"));
261 261
262 // Request an immediate database flush. 262 // Request an immediate database flush.
263 activity_db->AdviseFlush(ActivityDatabase::kFlushImmediately); 263 activity_db->AdviseFlush(ActivityDatabase::kFlushImmediately);
264 ASSERT_EQ(1, CountActions(&activity_db->db_, "brewster")); 264 ASSERT_EQ(1, CountActions(&activity_db->db_, "brewster"));
265 265
266 activity_db->Close(); 266 activity_db->Close();
267 } 267 }
268 268
269 // Check that nothing explodes if the DB isn't initialized. 269 // Check that nothing explodes if the DB isn't initialized.
270 TEST_F(ActivityDatabaseTest, InitFailure) { 270 TEST_F(ActivityDatabaseTest, InitFailure) {
271 base::ScopedTempDir temp_dir; 271 base::ScopedTempDir temp_dir;
272 base::FilePath db_file; 272 base::FilePath db_file;
273 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 273 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
274 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 274 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
275 base::DeleteFile(db_file, false); 275 sql::Connection::Delete(db_file);
276 276
277 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); 277 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy();
278 ActivityDatabase* activity_db = new ActivityDatabase(delegate); 278 ActivityDatabase* activity_db = new ActivityDatabase(delegate);
279 scoped_refptr<Action> action = new Action( 279 scoped_refptr<Action> action = new Action(
280 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); 280 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster");
281 action->mutable_args()->AppendString("woof"); 281 action->mutable_args()->AppendString("woof");
282 delegate->Record(activity_db, action); 282 delegate->Record(activity_db, action);
283 activity_db->Close(); 283 activity_db->Close();
284 } 284 }
285 285
286 } // namespace extensions 286 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/diagnostics/sqlite_diagnostics.cc ('k') | components/password_manager/core/browser/login_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698