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

Side by Side Diff: chrome/browser/extensions/activity_log/counting_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/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // Wait for the task queue for the specified thread to empty. 63 // Wait for the task queue for the specified thread to empty.
64 void WaitOnThread(const content::BrowserThread::ID& thread) { 64 void WaitOnThread(const content::BrowserThread::ID& thread) {
65 BrowserThread::PostTaskAndReply( 65 BrowserThread::PostTaskAndReply(
66 thread, 66 thread,
67 FROM_HERE, 67 FROM_HERE,
68 base::Bind(&base::DoNothing), 68 base::Bind(&base::DoNothing),
69 base::MessageLoop::current()->QuitClosure()); 69 base::MessageLoop::current()->QuitClosure());
70 base::MessageLoop::current()->Run(); 70 base::MessageLoop::current()->Run();
71 } 71 }
72 72
73 // A helper function to call ReadData on a policy object and wait for the 73 // A wrapper function for CheckReadFilteredData, so that we don't need to
74 // results to be processed. 74 // enter empty string values for parameters we don't care about.
75 void CheckReadData( 75 void CheckReadData(
76 ActivityLogPolicy* policy, 76 ActivityLogPolicy* policy,
77 const std::string& extension_id, 77 const std::string& extension_id,
78 int day, 78 int day,
79 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { 79 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
80 // Submit a request to the policy to read back some data, and call the 80 CheckReadFilteredData(
81 // checker function when results are available. This will happen on the 81 policy, extension_id, Action::ACTION_ANY, "", "", "", day, checker);
82 // database thread.
83 policy->ReadData(
84 extension_id,
85 day,
86 base::Bind(&CountingPolicyTest::CheckWrapper,
87 checker,
88 base::MessageLoop::current()->QuitClosure()));
89
90 // Set up a timeout that will trigger after 5 seconds; if we haven't
91 // received any results by then assume that the test is broken.
92 base::CancelableClosure timeout(
93 base::Bind(&CountingPolicyTest::TimeoutCallback));
94 base::MessageLoop::current()->PostDelayedTask(
95 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(5));
96
97 // Wait for results; either the checker or the timeout callbacks should
98 // cause the main loop to exit.
99 base::MessageLoop::current()->Run();
100
101 timeout.Cancel();
102 } 82 }
103 83
104 // A helper function to call ReadFilteredData on a policy object and wait for 84 // A helper function to call ReadFilteredData on a policy object and wait for
105 // the results to be processed. 85 // the results to be processed.
106 void CheckReadFilteredData( 86 void CheckReadFilteredData(
107 ActivityLogPolicy* policy, 87 ActivityLogPolicy* policy,
108 const std::string& extension_id, 88 const std::string& extension_id,
109 const Action::ActionType type, 89 const Action::ActionType type,
110 const std::string& api_name, 90 const std::string& api_name,
111 const std::string& page_url, 91 const std::string& page_url,
112 const std::string& arg_url, 92 const std::string& arg_url,
93 int day,
113 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) { 94 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
114 // Submit a request to the policy to read back some data, and call the 95 // Submit a request to the policy to read back some data, and call the
115 // checker function when results are available. This will happen on the 96 // checker function when results are available. This will happen on the
116 // database thread. 97 // database thread.
117 policy->ReadFilteredData( 98 policy->ReadFilteredData(
118 extension_id, 99 extension_id,
119 type, 100 type,
120 api_name, 101 api_name,
121 page_url, 102 page_url,
122 arg_url, 103 arg_url,
104 day,
123 base::Bind(&CountingPolicyTest::CheckWrapper, 105 base::Bind(&CountingPolicyTest::CheckWrapper,
124 checker, 106 checker,
125 base::MessageLoop::current()->QuitClosure())); 107 base::MessageLoop::current()->QuitClosure()));
126 108
127 // Set up a timeout that will trigger after 5 seconds; if we haven't 109 // Set up a timeout that will trigger after 5 seconds; if we haven't
128 // received any results by then assume that the test is broken. 110 // received any results by then assume that the test is broken.
129 base::CancelableClosure timeout( 111 base::CancelableClosure timeout(
130 base::Bind(&CountingPolicyTest::TimeoutCallback)); 112 base::Bind(&CountingPolicyTest::TimeoutCallback));
131 base::MessageLoop::current()->PostDelayedTask( 113 base::MessageLoop::current()->PostDelayedTask(
132 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(5)); 114 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(5));
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 action_dom->set_page_url(gurl); 483 action_dom->set_page_url(gurl);
502 policy->ProcessAction(action_dom); 484 policy->ProcessAction(action_dom);
503 485
504 CheckReadFilteredData( 486 CheckReadFilteredData(
505 policy, 487 policy,
506 extension->id(), 488 extension->id(),
507 Action::ACTION_API_CALL, 489 Action::ACTION_API_CALL,
508 "tabs.testMethod", 490 "tabs.testMethod",
509 "", 491 "",
510 "", 492 "",
493 -1,
511 base::Bind( 494 base::Bind(
512 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1)); 495 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1));
513 496
514 CheckReadFilteredData( 497 CheckReadFilteredData(
515 policy, 498 policy,
516 "", 499 "",
517 Action::ACTION_DOM_ACCESS, 500 Action::ACTION_DOM_ACCESS,
518 "", 501 "",
519 "", 502 "",
520 "", 503 "",
504 -1,
521 base::Bind( 505 base::Bind(
522 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1)); 506 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1));
523 507
524 CheckReadFilteredData( 508 CheckReadFilteredData(
525 policy, 509 policy,
526 "", 510 "",
527 Action::ACTION_DOM_ACCESS, 511 Action::ACTION_DOM_ACCESS,
528 "", 512 "",
529 "http://www.google.com/", 513 "http://www.google.com/",
530 "", 514 "",
515 -1,
531 base::Bind( 516 base::Bind(
532 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1)); 517 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1));
533 518
534 CheckReadFilteredData( 519 CheckReadFilteredData(
535 policy, 520 policy,
536 "", 521 "",
537 Action::ACTION_DOM_ACCESS, 522 Action::ACTION_DOM_ACCESS,
538 "", 523 "",
539 "http://www.google.com", 524 "http://www.google.com",
540 "", 525 "",
526 -1,
541 base::Bind( 527 base::Bind(
542 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1)); 528 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1));
543 529
544 CheckReadFilteredData( 530 CheckReadFilteredData(
545 policy, 531 policy,
546 "", 532 "",
547 Action::ACTION_DOM_ACCESS, 533 Action::ACTION_DOM_ACCESS,
548 "", 534 "",
549 "http://www.goo", 535 "http://www.goo",
550 "", 536 "",
537 -1,
551 base::Bind( 538 base::Bind(
552 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1)); 539 &CountingPolicyTest::RetrieveActions_FetchFilteredActions1));
553 540
554 CheckReadFilteredData( 541 CheckReadFilteredData(
555 policy, 542 policy,
556 extension->id(), 543 extension->id(),
557 Action::ACTION_ANY, 544 Action::ACTION_ANY,
558 "", 545 "",
559 "", 546 "",
560 "", 547 "",
548 -1,
561 base::Bind( 549 base::Bind(
562 &CountingPolicyTest::RetrieveActions_FetchFilteredActions2)); 550 &CountingPolicyTest::RetrieveActions_FetchFilteredActions2));
563 551
564 policy->Close(); 552 policy->Close();
565 } 553 }
566 554
567 // Check that merging of actions only occurs within the same day, not across 555 // Check that merging of actions only occurs within the same day, not across
568 // days, and that old data can be expired from the database. 556 // days, and that old data can be expired from the database.
569 TEST_F(CountingPolicyTest, MergingAndExpiring) { 557 TEST_F(CountingPolicyTest, MergingAndExpiring) {
570 CountingPolicy* policy = new CountingPolicy(profile_.get()); 558 CountingPolicy* policy = new CountingPolicy(profile_.get());
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 881
894 CheckReadData( 882 CheckReadData(
895 policy, 883 policy,
896 "punky", 884 "punky",
897 0, 885 0,
898 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); 886 base::Bind(&CountingPolicyTest::SomeURLsRemoved));
899 policy->Close(); 887 policy->Close();
900 } 888 }
901 889
902 } // namespace extensions 890 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698