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

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

Issue 23980002: Activity Log: allow searching by day (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #if defined OS_CHROMEOS 53 #if defined OS_CHROMEOS
54 test_user_manager_.reset(); 54 test_user_manager_.reset();
55 #endif 55 #endif
56 base::RunLoop().RunUntilIdle(); 56 base::RunLoop().RunUntilIdle();
57 profile_.reset(NULL); 57 profile_.reset(NULL);
58 base::RunLoop().RunUntilIdle(); 58 base::RunLoop().RunUntilIdle();
59 // Restore the original command line and undo the affects of SetUp(). 59 // Restore the original command line and undo the affects of SetUp().
60 *CommandLine::ForCurrentProcess() = saved_cmdline_; 60 *CommandLine::ForCurrentProcess() = saved_cmdline_;
61 } 61 }
62 62
63 // A helper function to call ReadData on a policy object and wait for the 63 // A wrapper function for CheckReadFilteredData, so that we don't need to
64 // results to be processed. 64 // enter empty string values for parameters we don't care about.
65 void CheckReadData( 65 void CheckReadData(
66 ActivityLogPolicy* policy, 66 ActivityLogPolicy* policy,
67 const std::string& extension_id, 67 const std::string& extension_id,
68 const int day, 68 int day,
69 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { 69 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
70 // Submit a request to the policy to read back some data, and call the 70 CheckReadFilteredData(
71 // checker function when results are available. This will happen on the 71 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker);
72 // database thread.
73 policy->ReadData(
74 extension_id,
75 day,
76 base::Bind(&FullStreamUIPolicyTest::CheckWrapper,
77 checker,
78 base::MessageLoop::current()->QuitClosure()));
79
80 // Set up a timeout that will trigger after 5 seconds; if we haven't
81 // received any results by then assume that the test is broken.
82 base::CancelableClosure timeout(
83 base::Bind(&FullStreamUIPolicyTest::TimeoutCallback));
84 base::MessageLoop::current()->PostDelayedTask(
85 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(5));
86
87 // Wait for results; either the checker or the timeout callbacks should
88 // cause the main loop to exit.
89 base::MessageLoop::current()->Run();
90
91 timeout.Cancel();
92 } 72 }
93 73
94 // A helper function to call ReadFilteredData on a policy object and wait for 74 // A helper function to call ReadFilteredData on a policy object and wait for
95 // the results to be processed. 75 // the results to be processed.
96 void CheckReadFilteredData( 76 void CheckReadFilteredData(
97 ActivityLogPolicy* policy, 77 ActivityLogPolicy* policy,
98 const std::string& extension_id, 78 const std::string& extension_id,
99 const Action::ActionType type, 79 const Action::ActionType type,
100 const std::string& api_name, 80 const std::string& api_name,
101 const std::string& page_url, 81 const std::string& page_url,
102 const std::string& arg_url, 82 const std::string& arg_url,
83 const int days_ago,
103 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { 84 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
104 // Submit a request to the policy to read back some data, and call the 85 // Submit a request to the policy to read back some data, and call the
105 // checker function when results are available. This will happen on the 86 // checker function when results are available. This will happen on the
106 // database thread. 87 // database thread.
107 policy->ReadFilteredData( 88 policy->ReadFilteredData(
108 extension_id, 89 extension_id,
109 type, 90 type,
110 api_name, 91 api_name,
111 page_url, 92 page_url,
112 arg_url, 93 arg_url,
94 days_ago,
113 base::Bind(&FullStreamUIPolicyTest::CheckWrapper, 95 base::Bind(&FullStreamUIPolicyTest::CheckWrapper,
114 checker, 96 checker,
115 base::MessageLoop::current()->QuitClosure())); 97 base::MessageLoop::current()->QuitClosure()));
116 98
117 // Set up a timeout that will trigger after 5 seconds; if we haven't 99 // Set up a timeout that will trigger after 5 seconds; if we haven't
118 // received any results by then assume that the test is broken. 100 // received any results by then assume that the test is broken.
119 base::CancelableClosure timeout( 101 base::CancelableClosure timeout(
120 base::Bind(&FullStreamUIPolicyTest::TimeoutCallback)); 102 base::Bind(&FullStreamUIPolicyTest::TimeoutCallback));
121 base::MessageLoop::current()->PostDelayedTask( 103 base::MessageLoop::current()->PostDelayedTask(
122 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(5)); 104 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(5));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 action_dom->set_page_url(gurl); 316 action_dom->set_page_url(gurl);
335 policy->ProcessAction(action_dom); 317 policy->ProcessAction(action_dom);
336 318
337 CheckReadFilteredData( 319 CheckReadFilteredData(
338 policy, 320 policy,
339 extension->id(), 321 extension->id(),
340 Action::ACTION_API_CALL, 322 Action::ACTION_API_CALL,
341 "tabs.testMethod", 323 "tabs.testMethod",
342 "", 324 "",
343 "", 325 "",
326 -1,
344 base::Bind( 327 base::Bind(
345 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); 328 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1));
346 329
347 CheckReadFilteredData( 330 CheckReadFilteredData(
348 policy, 331 policy,
349 "", 332 "",
350 Action::ACTION_DOM_ACCESS, 333 Action::ACTION_DOM_ACCESS,
351 "", 334 "",
352 "", 335 "",
353 "", 336 "",
337 -1,
354 base::Bind( 338 base::Bind(
355 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); 339 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1));
356 340
357 CheckReadFilteredData( 341 CheckReadFilteredData(
358 policy, 342 policy,
359 "", 343 "",
360 Action::ACTION_DOM_ACCESS, 344 Action::ACTION_DOM_ACCESS,
361 "", 345 "",
362 "http://www.google.com/", 346 "http://www.google.com/",
363 "", 347 "",
348 -1,
364 base::Bind( 349 base::Bind(
365 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); 350 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1));
366 351
367 CheckReadFilteredData( 352 CheckReadFilteredData(
368 policy, 353 policy,
369 "", 354 "",
370 Action::ACTION_DOM_ACCESS, 355 Action::ACTION_DOM_ACCESS,
371 "", 356 "",
372 "http://www.google.com", 357 "http://www.google.com",
373 "", 358 "",
359 -1,
374 base::Bind( 360 base::Bind(
375 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); 361 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1));
376 362
377 CheckReadFilteredData( 363 CheckReadFilteredData(
378 policy, 364 policy,
379 "", 365 "",
380 Action::ACTION_DOM_ACCESS, 366 Action::ACTION_DOM_ACCESS,
381 "", 367 "",
382 "http://www.goo", 368 "http://www.goo",
383 "", 369 "",
370 -1,
384 base::Bind( 371 base::Bind(
385 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1)); 372 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions1));
386 373
387 CheckReadFilteredData( 374 CheckReadFilteredData(
388 policy, 375 policy,
389 extension->id(), 376 extension->id(),
390 Action::ACTION_ANY, 377 Action::ACTION_ANY,
391 "", 378 "",
392 "", 379 "",
393 "", 380 "",
381 -1,
394 base::Bind( 382 base::Bind(
395 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions2)); 383 &FullStreamUIPolicyTest::RetrieveActions_FetchFilteredActions2));
396 384
397 policy->Close(); 385 policy->Close();
398 } 386 }
399 387
400 TEST_F(FullStreamUIPolicyTest, LogWithArguments) { 388 TEST_F(FullStreamUIPolicyTest, LogWithArguments) {
401 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); 389 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
402 scoped_refptr<const Extension> extension = 390 scoped_refptr<const Extension> extension =
403 ExtensionBuilder() 391 ExtensionBuilder()
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 624
637 CheckReadData( 625 CheckReadData(
638 policy, 626 policy,
639 "punky", 627 "punky",
640 0, 628 0,
641 base::Bind(&FullStreamUIPolicyTest::SomeURLsRemoved)); 629 base::Bind(&FullStreamUIPolicyTest::SomeURLsRemoved));
642 policy->Close(); 630 policy->Close();
643 } 631 }
644 632
645 } // namespace extensions 633 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698