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

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

Issue 21646004: Compressed activity log database storage (Closed) Base URL: http://git.chromium.org/chromium/src.git@refactor-cleanups
Patch Set: Delete a debugging log message Created 7 years, 4 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 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 "base/cancelable_callback.h" 5 #include "base/cancelable_callback.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/test/simple_test_clock.h" 10 #include "base/test/simple_test_clock.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 extension->id(), 240 extension->id(),
241 0, 241 0,
242 base::Bind(&FullStreamUIPolicyTest::Arguments_Present)); 242 base::Bind(&FullStreamUIPolicyTest::Arguments_Present));
243 policy->Close(); 243 policy->Close();
244 } 244 }
245 245
246 TEST_F(FullStreamUIPolicyTest, GetTodaysActions) { 246 TEST_F(FullStreamUIPolicyTest, GetTodaysActions) {
247 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); 247 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
248 248
249 // Use a mock clock to ensure that events are not recorded on the wrong day 249 // Use a mock clock to ensure that events are not recorded on the wrong day
250 // when the test is run close to local midnight. 250 // when the test is run close to local midnight. Note: Ownership is passed
251 base::SimpleTestClock mock_clock; 251 // to the policy, but we still keep a pointer locally. The policy will take
252 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 252 // care of destruction; this is safe since the policy outlives all our
253 base::TimeDelta::FromHours(12)); 253 // accesses to the mock clock.
254 policy->SetClockForTesting(&mock_clock); 254 base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
255 mock_clock->SetNow(base::Time::Now().LocalMidnight() +
256 base::TimeDelta::FromHours(12));
257 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
255 258
256 // Record some actions 259 // Record some actions
257 scoped_refptr<Action> action = 260 scoped_refptr<Action> action =
258 new Action("punky", 261 new Action("punky",
259 mock_clock.Now() - base::TimeDelta::FromMinutes(40), 262 mock_clock->Now() - base::TimeDelta::FromMinutes(40),
260 Action::ACTION_API_CALL, 263 Action::ACTION_API_CALL,
261 "brewster"); 264 "brewster");
262 action->mutable_args()->AppendString("woof"); 265 action->mutable_args()->AppendString("woof");
263 policy->ProcessAction(action); 266 policy->ProcessAction(action);
264 267
265 action = 268 action =
266 new Action("punky", mock_clock.Now(), Action::ACTION_DOM_ACCESS, "lets"); 269 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
267 action->mutable_args()->AppendString("vamoose"); 270 action->mutable_args()->AppendString("vamoose");
268 action->set_page_url(GURL("http://www.google.com")); 271 action->set_page_url(GURL("http://www.google.com"));
269 policy->ProcessAction(action); 272 policy->ProcessAction(action);
270 273
271 action = new Action( 274 action = new Action(
272 "scoobydoo", mock_clock.Now(), Action::ACTION_DOM_ACCESS, "lets"); 275 "scoobydoo", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
273 action->mutable_args()->AppendString("vamoose"); 276 action->mutable_args()->AppendString("vamoose");
274 action->set_page_url(GURL("http://www.google.com")); 277 action->set_page_url(GURL("http://www.google.com"));
275 policy->ProcessAction(action); 278 policy->ProcessAction(action);
276 279
277 CheckReadData( 280 CheckReadData(
278 policy, 281 policy,
279 "punky", 282 "punky",
280 0, 283 0,
281 base::Bind(&FullStreamUIPolicyTest::Arguments_GetTodaysActions)); 284 base::Bind(&FullStreamUIPolicyTest::Arguments_GetTodaysActions));
282 policy->Close(); 285 policy->Close();
283 } 286 }
284 287
285 // Check that we can read back less recent actions in the db. 288 // Check that we can read back less recent actions in the db.
286 TEST_F(FullStreamUIPolicyTest, GetOlderActions) { 289 TEST_F(FullStreamUIPolicyTest, GetOlderActions) {
287 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); 290 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
288 291
289 // Use a mock clock to ensure that events are not recorded on the wrong day 292 // Use a mock clock to ensure that events are not recorded on the wrong day
290 // when the test is run close to local midnight. 293 // when the test is run close to local midnight.
291 base::SimpleTestClock mock_clock; 294 base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
292 mock_clock.SetNow(base::Time::Now().LocalMidnight() + 295 mock_clock->SetNow(base::Time::Now().LocalMidnight() +
293 base::TimeDelta::FromHours(12)); 296 base::TimeDelta::FromHours(12));
294 policy->SetClockForTesting(&mock_clock); 297 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
295 298
296 // Record some actions 299 // Record some actions
297 scoped_refptr<Action> action = 300 scoped_refptr<Action> action =
298 new Action("punky", 301 new Action("punky",
299 mock_clock.Now() - base::TimeDelta::FromDays(3) - 302 mock_clock->Now() - base::TimeDelta::FromDays(3) -
300 base::TimeDelta::FromMinutes(40), 303 base::TimeDelta::FromMinutes(40),
301 Action::ACTION_API_CALL, 304 Action::ACTION_API_CALL,
302 "brewster"); 305 "brewster");
303 action->mutable_args()->AppendString("woof"); 306 action->mutable_args()->AppendString("woof");
304 policy->ProcessAction(action); 307 policy->ProcessAction(action);
305 308
306 action = new Action("punky", 309 action = new Action("punky",
307 mock_clock.Now() - base::TimeDelta::FromDays(3), 310 mock_clock->Now() - base::TimeDelta::FromDays(3),
308 Action::ACTION_DOM_ACCESS, 311 Action::ACTION_DOM_ACCESS,
309 "lets"); 312 "lets");
310 action->mutable_args()->AppendString("vamoose"); 313 action->mutable_args()->AppendString("vamoose");
311 action->set_page_url(GURL("http://www.google.com")); 314 action->set_page_url(GURL("http://www.google.com"));
312 policy->ProcessAction(action); 315 policy->ProcessAction(action);
313 316
314 action = new Action("punky", 317 action = new Action("punky",
315 mock_clock.Now(), 318 mock_clock->Now(),
316 Action::ACTION_DOM_ACCESS, 319 Action::ACTION_DOM_ACCESS,
317 "lets"); 320 "lets");
318 action->mutable_args()->AppendString("too new"); 321 action->mutable_args()->AppendString("too new");
319 action->set_page_url(GURL("http://www.google.com")); 322 action->set_page_url(GURL("http://www.google.com"));
320 policy->ProcessAction(action); 323 policy->ProcessAction(action);
321 324
322 action = new Action("punky", 325 action = new Action("punky",
323 mock_clock.Now() - base::TimeDelta::FromDays(7), 326 mock_clock->Now() - base::TimeDelta::FromDays(7),
324 Action::ACTION_DOM_ACCESS, 327 Action::ACTION_DOM_ACCESS,
325 "lets"); 328 "lets");
326 action->mutable_args()->AppendString("too old"); 329 action->mutable_args()->AppendString("too old");
327 action->set_page_url(GURL("http://www.google.com")); 330 action->set_page_url(GURL("http://www.google.com"));
328 policy->ProcessAction(action); 331 policy->ProcessAction(action);
329 332
330 CheckReadData( 333 CheckReadData(
331 policy, 334 policy,
332 "punky", 335 "punky",
333 3, 336 3,
334 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions)); 337 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions));
335 policy->Close(); 338 policy->Close();
336 } 339 }
337 340
338 } // namespace extensions 341 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698