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

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

Issue 16756004: Revert 205059 "We were seeing ActivityLog memory leaks and assor..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 6 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // Check that the database is initialized properly. 70 // Check that the database is initialized properly.
71 TEST_F(ActivityDatabaseTest, Init) { 71 TEST_F(ActivityDatabaseTest, Init) {
72 base::ScopedTempDir temp_dir; 72 base::ScopedTempDir temp_dir;
73 base::FilePath db_file; 73 base::FilePath db_file;
74 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 74 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
75 db_file = temp_dir.path().AppendASCII("ActivityInit.db"); 75 db_file = temp_dir.path().AppendASCII("ActivityInit.db");
76 file_util::Delete(db_file, false); 76 file_util::Delete(db_file, false);
77 77
78 ActivityDatabase* activity_db = new ActivityDatabase(); 78 ActivityDatabase* activity_db = new ActivityDatabase();
79 activity_db->Init(db_file); 79 activity_db->Init(db_file);
80 ASSERT_TRUE(activity_db->is_db_valid()); 80 ASSERT_TRUE(activity_db->initialized());
81 activity_db->Close(); 81 activity_db->Close();
82 82
83 sql::Connection db; 83 sql::Connection db;
84 ASSERT_TRUE(db.Open(db_file)); 84 ASSERT_TRUE(db.Open(db_file));
85 ASSERT_TRUE(db.DoesTableExist(DOMAction::kTableName)); 85 ASSERT_TRUE(db.DoesTableExist(DOMAction::kTableName));
86 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName)); 86 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName));
87 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName)); 87 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName));
88 db.Close(); 88 db.Close();
89 } 89 }
90 90
91 // Check that API actions are recorded in the db. 91 // Check that API actions are recorded in the db.
92 TEST_F(ActivityDatabaseTest, RecordAPIAction) { 92 TEST_F(ActivityDatabaseTest, RecordAPIAction) {
93 base::ScopedTempDir temp_dir; 93 base::ScopedTempDir temp_dir;
94 base::FilePath db_file; 94 base::FilePath db_file;
95 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 95 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
96 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 96 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
97 file_util::Delete(db_file, false); 97 file_util::Delete(db_file, false);
98 98
99 ActivityDatabase* activity_db = new ActivityDatabase(); 99 ActivityDatabase* activity_db = new ActivityDatabase();
100 activity_db->Init(db_file); 100 activity_db->Init(db_file);
101 activity_db->SetBatchModeForTesting(false); 101 activity_db->SetBatchModeForTesting(false);
102 ASSERT_TRUE(activity_db->is_db_valid()); 102 ASSERT_TRUE(activity_db->initialized());
103 scoped_refptr<APIAction> action = new APIAction( 103 scoped_refptr<APIAction> action = new APIAction(
104 "punky", 104 "punky",
105 base::Time::Now(), 105 base::Time::Now(),
106 APIAction::CALL, 106 APIAction::CALL,
107 "brewster", 107 "brewster",
108 "woof", 108 "woof",
109 "extra"); 109 "extra");
110 activity_db->RecordAction(action); 110 activity_db->RecordAction(action);
111 activity_db->Close(); 111 activity_db->Close();
112 112
(...skipping 14 matching lines...) Expand all
127 // Check that blocked actions are recorded in the db. 127 // Check that blocked actions are recorded in the db.
128 TEST_F(ActivityDatabaseTest, RecordBlockedAction) { 128 TEST_F(ActivityDatabaseTest, RecordBlockedAction) {
129 base::ScopedTempDir temp_dir; 129 base::ScopedTempDir temp_dir;
130 base::FilePath db_file; 130 base::FilePath db_file;
131 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 131 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
132 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 132 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
133 file_util::Delete(db_file, false); 133 file_util::Delete(db_file, false);
134 134
135 ActivityDatabase* activity_db = new ActivityDatabase(); 135 ActivityDatabase* activity_db = new ActivityDatabase();
136 activity_db->Init(db_file); 136 activity_db->Init(db_file);
137 ASSERT_TRUE(activity_db->is_db_valid()); 137 ASSERT_TRUE(activity_db->initialized());
138 scoped_refptr<BlockedAction> action = new BlockedAction( 138 scoped_refptr<BlockedAction> action = new BlockedAction(
139 "punky", 139 "punky",
140 base::Time::Now(), 140 base::Time::Now(),
141 "do.evilThings", 141 "do.evilThings",
142 "1, 2", 142 "1, 2",
143 BlockedAction::ACCESS_DENIED, 143 BlockedAction::ACCESS_DENIED,
144 "extra"); 144 "extra");
145 activity_db->RecordAction(action); 145 activity_db->RecordAction(action);
146 activity_db->Close(); 146 activity_db->Close();
147 147
(...skipping 22 matching lines...) Expand all
170 170
171 // Use a mock clock to ensure that events are not recorded on the wrong day 171 // Use a mock clock to ensure that events are not recorded on the wrong day
172 // when the test is run close to local midnight. 172 // when the test is run close to local midnight.
173 base::SimpleTestClock mock_clock; 173 base::SimpleTestClock mock_clock;
174 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 174 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
175 base::TimeDelta::FromHours(12)); 175 base::TimeDelta::FromHours(12));
176 176
177 // Record some actions 177 // Record some actions
178 ActivityDatabase* activity_db = new ActivityDatabase(); 178 ActivityDatabase* activity_db = new ActivityDatabase();
179 activity_db->Init(db_file); 179 activity_db->Init(db_file);
180 ASSERT_TRUE(activity_db->is_db_valid()); 180 ASSERT_TRUE(activity_db->initialized());
181 scoped_refptr<APIAction> api_action = new APIAction( 181 scoped_refptr<APIAction> api_action = new APIAction(
182 "punky", 182 "punky",
183 mock_clock.Now() - base::TimeDelta::FromMinutes(40), 183 mock_clock.Now() - base::TimeDelta::FromMinutes(40),
184 APIAction::CALL, 184 APIAction::CALL,
185 "brewster", 185 "brewster",
186 "woof", 186 "woof",
187 "extra"); 187 "extra");
188 scoped_refptr<DOMAction> dom_action = new DOMAction( 188 scoped_refptr<DOMAction> dom_action = new DOMAction(
189 "punky", 189 "punky",
190 mock_clock.Now(), 190 mock_clock.Now(),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 230
231 // Use a mock clock to ensure that events are not recorded on the wrong day 231 // Use a mock clock to ensure that events are not recorded on the wrong day
232 // when the test is run close to local midnight. 232 // when the test is run close to local midnight.
233 base::SimpleTestClock mock_clock; 233 base::SimpleTestClock mock_clock;
234 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 234 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
235 base::TimeDelta::FromHours(12)); 235 base::TimeDelta::FromHours(12));
236 236
237 // Record some actions 237 // Record some actions
238 ActivityDatabase* activity_db = new ActivityDatabase(); 238 ActivityDatabase* activity_db = new ActivityDatabase();
239 activity_db->Init(db_file); 239 activity_db->Init(db_file);
240 ASSERT_TRUE(activity_db->is_db_valid()); 240 ASSERT_TRUE(activity_db->initialized());
241 scoped_refptr<APIAction> api_action = new APIAction( 241 scoped_refptr<APIAction> api_action = new APIAction(
242 "punky", 242 "punky",
243 mock_clock.Now() - base::TimeDelta::FromDays(3) 243 mock_clock.Now() - base::TimeDelta::FromDays(3)
244 - base::TimeDelta::FromMinutes(40), 244 - base::TimeDelta::FromMinutes(40),
245 APIAction::CALL, 245 APIAction::CALL,
246 "brewster", 246 "brewster",
247 "woof", 247 "woof",
248 "extra"); 248 "extra");
249 scoped_refptr<DOMAction> dom_action = new DOMAction( 249 scoped_refptr<DOMAction> dom_action = new DOMAction(
250 "punky", 250 "punky",
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // when the test is run close to local midnight. 302 // when the test is run close to local midnight.
303 base::SimpleTestClock mock_clock; 303 base::SimpleTestClock mock_clock;
304 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 304 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
305 base::TimeDelta::FromHours(12)); 305 base::TimeDelta::FromHours(12));
306 306
307 // Record some actions 307 // Record some actions
308 ActivityDatabase* activity_db = new ActivityDatabase(); 308 ActivityDatabase* activity_db = new ActivityDatabase();
309 activity_db->Init(db_file); 309 activity_db->Init(db_file);
310 activity_db->SetBatchModeForTesting(false); 310 activity_db->SetBatchModeForTesting(false);
311 activity_db->SetClockForTesting(&mock_clock); 311 activity_db->SetClockForTesting(&mock_clock);
312 ASSERT_TRUE(activity_db->is_db_valid()); 312 ASSERT_TRUE(activity_db->initialized());
313 scoped_refptr<APIAction> api_action = new APIAction( 313 scoped_refptr<APIAction> api_action = new APIAction(
314 "punky", 314 "punky",
315 mock_clock.Now() - base::TimeDelta::FromMinutes(40), 315 mock_clock.Now() - base::TimeDelta::FromMinutes(40),
316 APIAction::CALL, 316 APIAction::CALL,
317 "brewster", 317 "brewster",
318 "woof", 318 "woof",
319 "extra"); 319 "extra");
320 activity_db->RecordAction(api_action); 320 activity_db->RecordAction(api_action);
321 321
322 scoped_ptr<std::vector<scoped_refptr<Action> > > actions = 322 scoped_ptr<std::vector<scoped_refptr<Action> > > actions =
(...skipping 13 matching lines...) Expand all
336 // timing and skip ahead in time. 336 // timing and skip ahead in time.
337 base::SimpleTestClock mock_clock; 337 base::SimpleTestClock mock_clock;
338 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 338 mock_clock.SetNow(base::Time::Now().LocalMidnight() +
339 base::TimeDelta::FromHours(11)); 339 base::TimeDelta::FromHours(11));
340 340
341 // Record some actions 341 // Record some actions
342 ActivityDatabase* activity_db = new ActivityDatabase(); 342 ActivityDatabase* activity_db = new ActivityDatabase();
343 activity_db->Init(db_file); 343 activity_db->Init(db_file);
344 activity_db->SetBatchModeForTesting(true); 344 activity_db->SetBatchModeForTesting(true);
345 activity_db->SetClockForTesting(&mock_clock); 345 activity_db->SetClockForTesting(&mock_clock);
346 ASSERT_TRUE(activity_db->is_db_valid()); 346 ASSERT_TRUE(activity_db->initialized());
347 scoped_refptr<APIAction> api_action = new APIAction( 347 scoped_refptr<APIAction> api_action = new APIAction(
348 "punky", 348 "punky",
349 mock_clock.Now() - base::TimeDelta::FromMinutes(40), 349 mock_clock.Now() - base::TimeDelta::FromMinutes(40),
350 APIAction::CALL, 350 APIAction::CALL,
351 "brewster", 351 "brewster",
352 "woof", 352 "woof",
353 "extra"); 353 "extra");
354 activity_db->RecordAction(api_action); 354 activity_db->RecordAction(api_action);
355 355
356 scoped_ptr<std::vector<scoped_refptr<Action> > > actions_before = 356 scoped_ptr<std::vector<scoped_refptr<Action> > > actions_before =
(...skipping 24 matching lines...) Expand all
381 "punky", 381 "punky",
382 base::Time::Now(), 382 base::Time::Now(),
383 APIAction::CALL, 383 APIAction::CALL,
384 "brewster", 384 "brewster",
385 "woooof", 385 "woooof",
386 "extra"); 386 "extra");
387 activity_db->RecordAction(action); 387 activity_db->RecordAction(action);
388 activity_db->Close(); 388 activity_db->Close();
389 } 389 }
390 390
391 } // namespace extensions 391 } // namespace
392 392
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698