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

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

Issue 16950028: Move file_util::Delete to the base namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 (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 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 }; 69 };
70 70
71 71
72 // Check that the database is initialized properly. 72 // Check that the database is initialized properly.
73 TEST_F(ActivityDatabaseTest, Init) { 73 TEST_F(ActivityDatabaseTest, Init) {
74 base::ScopedTempDir temp_dir; 74 base::ScopedTempDir temp_dir;
75 base::FilePath db_file; 75 base::FilePath db_file;
76 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 76 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
77 db_file = temp_dir.path().AppendASCII("ActivityInit.db"); 77 db_file = temp_dir.path().AppendASCII("ActivityInit.db");
78 file_util::Delete(db_file, false); 78 base::Delete(db_file, false);
79 79
80 ActivityDatabase* activity_db = new ActivityDatabase(); 80 ActivityDatabase* activity_db = new ActivityDatabase();
81 activity_db->Init(db_file); 81 activity_db->Init(db_file);
82 ASSERT_TRUE(activity_db->is_db_valid()); 82 ASSERT_TRUE(activity_db->is_db_valid());
83 activity_db->Close(); 83 activity_db->Close();
84 84
85 sql::Connection db; 85 sql::Connection db;
86 ASSERT_TRUE(db.Open(db_file)); 86 ASSERT_TRUE(db.Open(db_file));
87 ASSERT_TRUE(db.DoesTableExist(DOMAction::kTableName)); 87 ASSERT_TRUE(db.DoesTableExist(DOMAction::kTableName));
88 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName)); 88 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName));
89 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName)); 89 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName));
90 db.Close(); 90 db.Close();
91 } 91 }
92 92
93 // Check that API actions are recorded in the db. 93 // Check that API actions are recorded in the db.
94 TEST_F(ActivityDatabaseTest, RecordAPIAction) { 94 TEST_F(ActivityDatabaseTest, RecordAPIAction) {
95 base::ScopedTempDir temp_dir; 95 base::ScopedTempDir temp_dir;
96 base::FilePath db_file; 96 base::FilePath db_file;
97 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 97 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
98 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 98 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
99 file_util::Delete(db_file, false); 99 base::Delete(db_file, false);
100 100
101 ActivityDatabase* activity_db = new ActivityDatabase(); 101 ActivityDatabase* activity_db = new ActivityDatabase();
102 activity_db->Init(db_file); 102 activity_db->Init(db_file);
103 activity_db->SetBatchModeForTesting(false); 103 activity_db->SetBatchModeForTesting(false);
104 ASSERT_TRUE(activity_db->is_db_valid()); 104 ASSERT_TRUE(activity_db->is_db_valid());
105 scoped_refptr<APIAction> action = new APIAction( 105 scoped_refptr<APIAction> action = new APIAction(
106 "punky", 106 "punky",
107 base::Time::Now(), 107 base::Time::Now(),
108 APIAction::CALL, 108 APIAction::CALL,
109 "brewster", 109 "brewster",
(...skipping 15 matching lines...) Expand all
125 ASSERT_EQ("brewster", statement.ColumnString(3)); 125 ASSERT_EQ("brewster", statement.ColumnString(3));
126 ASSERT_EQ("woof", statement.ColumnString(4)); 126 ASSERT_EQ("woof", statement.ColumnString(4));
127 } 127 }
128 128
129 // Check that DOM actions are recorded in the db. 129 // Check that DOM actions are recorded in the db.
130 TEST_F(ActivityDatabaseTest, RecordDOMAction) { 130 TEST_F(ActivityDatabaseTest, RecordDOMAction) {
131 base::ScopedTempDir temp_dir; 131 base::ScopedTempDir temp_dir;
132 base::FilePath db_file; 132 base::FilePath db_file;
133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 133 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
134 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 134 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
135 file_util::Delete(db_file, false); 135 base::Delete(db_file, false);
136 136
137 ActivityDatabase* activity_db = new ActivityDatabase(); 137 ActivityDatabase* activity_db = new ActivityDatabase();
138 activity_db->Init(db_file); 138 activity_db->Init(db_file);
139 activity_db->SetBatchModeForTesting(false); 139 activity_db->SetBatchModeForTesting(false);
140 ASSERT_TRUE(activity_db->is_db_valid()); 140 ASSERT_TRUE(activity_db->is_db_valid());
141 scoped_refptr<DOMAction> action = new DOMAction( 141 scoped_refptr<DOMAction> action = new DOMAction(
142 "punky", 142 "punky",
143 base::Time::Now(), 143 base::Time::Now(),
144 DomActionType::MODIFIED, 144 DomActionType::MODIFIED,
145 GURL("http://www.google.com/foo?bar"), 145 GURL("http://www.google.com/foo?bar"),
(...skipping 24 matching lines...) Expand all
170 ASSERT_EQ("vamoose", statement.ColumnString(7)); 170 ASSERT_EQ("vamoose", statement.ColumnString(7));
171 ASSERT_EQ("extra", statement.ColumnString(8)); 171 ASSERT_EQ("extra", statement.ColumnString(8));
172 } 172 }
173 173
174 // Check that blocked actions are recorded in the db. 174 // Check that blocked actions are recorded in the db.
175 TEST_F(ActivityDatabaseTest, RecordBlockedAction) { 175 TEST_F(ActivityDatabaseTest, RecordBlockedAction) {
176 base::ScopedTempDir temp_dir; 176 base::ScopedTempDir temp_dir;
177 base::FilePath db_file; 177 base::FilePath db_file;
178 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 178 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
179 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 179 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
180 file_util::Delete(db_file, false); 180 base::Delete(db_file, false);
181 181
182 ActivityDatabase* activity_db = new ActivityDatabase(); 182 ActivityDatabase* activity_db = new ActivityDatabase();
183 activity_db->Init(db_file); 183 activity_db->Init(db_file);
184 ASSERT_TRUE(activity_db->is_db_valid()); 184 ASSERT_TRUE(activity_db->is_db_valid());
185 scoped_refptr<BlockedAction> action = new BlockedAction( 185 scoped_refptr<BlockedAction> action = new BlockedAction(
186 "punky", 186 "punky",
187 base::Time::Now(), 187 base::Time::Now(),
188 "do.evilThings", 188 "do.evilThings",
189 "1, 2", 189 "1, 2",
190 BlockedAction::ACCESS_DENIED, 190 BlockedAction::ACCESS_DENIED,
(...skipping 15 matching lines...) Expand all
206 ASSERT_EQ(1, statement.ColumnInt(4)); 206 ASSERT_EQ(1, statement.ColumnInt(4));
207 ASSERT_EQ("extra", statement.ColumnString(5)); 207 ASSERT_EQ("extra", statement.ColumnString(5));
208 } 208 }
209 209
210 // Check that we can read back recent actions in the db. 210 // Check that we can read back recent actions in the db.
211 TEST_F(ActivityDatabaseTest, GetTodaysActions) { 211 TEST_F(ActivityDatabaseTest, GetTodaysActions) {
212 base::ScopedTempDir temp_dir; 212 base::ScopedTempDir temp_dir;
213 base::FilePath db_file; 213 base::FilePath db_file;
214 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 214 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
215 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 215 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
216 file_util::Delete(db_file, false); 216 base::Delete(db_file, false);
217 217
218 // Use a mock clock to ensure that events are not recorded on the wrong day 218 // Use a mock clock to ensure that events are not recorded on the wrong day
219 // when the test is run close to local midnight. 219 // when the test is run close to local midnight.
220 base::SimpleTestClock mock_clock; 220 base::SimpleTestClock mock_clock;
221 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 221 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
222 base::TimeDelta::FromHours(12)); 222 base::TimeDelta::FromHours(12));
223 223
224 // Record some actions 224 // Record some actions
225 ActivityDatabase* activity_db = new ActivityDatabase(); 225 ActivityDatabase* activity_db = new ActivityDatabase();
226 activity_db->Init(db_file); 226 activity_db->Init(db_file);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 266
267 activity_db->Close(); 267 activity_db->Close();
268 } 268 }
269 269
270 // Check that we can read back recent actions in the db. 270 // Check that we can read back recent actions in the db.
271 TEST_F(ActivityDatabaseTest, GetOlderActions) { 271 TEST_F(ActivityDatabaseTest, GetOlderActions) {
272 base::ScopedTempDir temp_dir; 272 base::ScopedTempDir temp_dir;
273 base::FilePath db_file; 273 base::FilePath db_file;
274 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 274 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
275 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 275 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
276 file_util::Delete(db_file, false); 276 base::Delete(db_file, false);
277 277
278 // Use a mock clock to ensure that events are not recorded on the wrong day 278 // Use a mock clock to ensure that events are not recorded on the wrong day
279 // when the test is run close to local midnight. 279 // when the test is run close to local midnight.
280 base::SimpleTestClock mock_clock; 280 base::SimpleTestClock mock_clock;
281 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 281 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
282 base::TimeDelta::FromHours(12)); 282 base::TimeDelta::FromHours(12));
283 283
284 // Record some actions 284 // Record some actions
285 ActivityDatabase* activity_db = new ActivityDatabase(); 285 ActivityDatabase* activity_db = new ActivityDatabase();
286 activity_db->Init(db_file); 286 activity_db->Init(db_file);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); 336 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug());
337 337
338 activity_db->Close(); 338 activity_db->Close();
339 } 339 }
340 340
341 TEST_F(ActivityDatabaseTest, BatchModeOff) { 341 TEST_F(ActivityDatabaseTest, BatchModeOff) {
342 base::ScopedTempDir temp_dir; 342 base::ScopedTempDir temp_dir;
343 base::FilePath db_file; 343 base::FilePath db_file;
344 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 344 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
345 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 345 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
346 file_util::Delete(db_file, false); 346 base::Delete(db_file, false);
347 347
348 // Use a mock clock to ensure that events are not recorded on the wrong day 348 // Use a mock clock to ensure that events are not recorded on the wrong day
349 // when the test is run close to local midnight. 349 // when the test is run close to local midnight.
350 base::SimpleTestClock mock_clock; 350 base::SimpleTestClock mock_clock;
351 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 351 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
352 base::TimeDelta::FromHours(12)); 352 base::TimeDelta::FromHours(12));
353 353
354 // Record some actions 354 // Record some actions
355 ActivityDatabase* activity_db = new ActivityDatabase(); 355 ActivityDatabase* activity_db = new ActivityDatabase();
356 activity_db->Init(db_file); 356 activity_db->Init(db_file);
(...skipping 13 matching lines...) Expand all
370 activity_db->GetActions("punky", 0); 370 activity_db->GetActions("punky", 0);
371 ASSERT_EQ(1, static_cast<int>(actions->size())); 371 ASSERT_EQ(1, static_cast<int>(actions->size()));
372 activity_db->Close(); 372 activity_db->Close();
373 } 373 }
374 374
375 TEST_F(ActivityDatabaseTest, BatchModeOn) { 375 TEST_F(ActivityDatabaseTest, BatchModeOn) {
376 base::ScopedTempDir temp_dir; 376 base::ScopedTempDir temp_dir;
377 base::FilePath db_file; 377 base::FilePath db_file;
378 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 378 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
379 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 379 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
380 file_util::Delete(db_file, false); 380 base::Delete(db_file, false);
381 381
382 // Use a mock clock to set the time, and a special timer to control the 382 // Use a mock clock to set the time, and a special timer to control the
383 // timing and skip ahead in time. 383 // timing and skip ahead in time.
384 base::SimpleTestClock mock_clock; 384 base::SimpleTestClock mock_clock;
385 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 385 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
386 base::TimeDelta::FromHours(11)); 386 base::TimeDelta::FromHours(11));
387 387
388 // Record some actions 388 // Record some actions
389 ActivityDatabase* activity_db = new ActivityDatabase(); 389 ActivityDatabase* activity_db = new ActivityDatabase();
390 activity_db->Init(db_file); 390 activity_db->Init(db_file);
(...skipping 23 matching lines...) Expand all
414 414
415 activity_db->Close(); 415 activity_db->Close();
416 } 416 }
417 417
418 // Check that nothing explodes if the DB isn't initialized. 418 // Check that nothing explodes if the DB isn't initialized.
419 TEST_F(ActivityDatabaseTest, InitFailure) { 419 TEST_F(ActivityDatabaseTest, InitFailure) {
420 base::ScopedTempDir temp_dir; 420 base::ScopedTempDir temp_dir;
421 base::FilePath db_file; 421 base::FilePath db_file;
422 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 422 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
423 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 423 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
424 file_util::Delete(db_file, false); 424 base::Delete(db_file, false);
425 425
426 ActivityDatabase* activity_db = new ActivityDatabase(); 426 ActivityDatabase* activity_db = new ActivityDatabase();
427 scoped_refptr<APIAction> action = new APIAction( 427 scoped_refptr<APIAction> action = new APIAction(
428 "punky", 428 "punky",
429 base::Time::Now(), 429 base::Time::Now(),
430 APIAction::CALL, 430 APIAction::CALL,
431 "brewster", 431 "brewster",
432 "woooof", 432 "woooof",
433 "extra"); 433 "extra");
434 activity_db->RecordAction(action); 434 activity_db->RecordAction(action);
435 activity_db->Close(); 435 activity_db->Close();
436 } 436 }
437 437
438 } // namespace extensions 438 } // namespace extensions
439 439
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698