OLD | NEW |
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 static void RetrieveActions_FetchFilteredActions1( | 179 static void RetrieveActions_FetchFilteredActions1( |
180 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 180 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
181 ASSERT_EQ(1, static_cast<int>(i->size())); | 181 ASSERT_EQ(1, static_cast<int>(i->size())); |
182 } | 182 } |
183 | 183 |
184 static void RetrieveActions_FetchFilteredActions2( | 184 static void RetrieveActions_FetchFilteredActions2( |
185 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 185 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
186 ASSERT_EQ(2, static_cast<int>(i->size())); | 186 ASSERT_EQ(2, static_cast<int>(i->size())); |
187 } | 187 } |
188 | 188 |
| 189 static void RetrieveActions_FetchFilteredActions300( |
| 190 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 191 ASSERT_EQ(300, static_cast<int>(i->size())); |
| 192 } |
| 193 |
189 static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { | 194 static void Arguments_Stripped(scoped_ptr<Action::ActionVector> i) { |
190 scoped_refptr<Action> last = i->front(); | 195 scoped_refptr<Action> last = i->front(); |
191 std::string args = | 196 std::string args = |
192 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " | 197 "ID=odlameecjipmbmbejkplpemijjgpljce CATEGORY=api_call " |
193 "API=extension.connect ARGS=[\"hello\",\"world\"] COUNT=1"; | 198 "API=extension.connect ARGS=[\"hello\",\"world\"] COUNT=1"; |
194 ASSERT_EQ(args, last->PrintForDebug()); | 199 ASSERT_EQ(args, last->PrintForDebug()); |
195 } | 200 } |
196 | 201 |
197 static void Arguments_GetTodaysActions( | 202 static void Arguments_GetTodaysActions( |
198 scoped_ptr<Action::ActionVector> actions) { | 203 scoped_ptr<Action::ActionVector> actions) { |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 base::StringPrintf("apicall_%d", i)); | 780 base::StringPrintf("apicall_%d", i)); |
776 policy->ProcessAction(action); | 781 policy->ProcessAction(action); |
777 } | 782 } |
778 | 783 |
779 policy->ScheduleAndForget(policy, &CountingPolicyTest::CheckQueueSize); | 784 policy->ScheduleAndForget(policy, &CountingPolicyTest::CheckQueueSize); |
780 WaitOnThread(BrowserThread::DB); | 785 WaitOnThread(BrowserThread::DB); |
781 | 786 |
782 policy->Close(); | 787 policy->Close(); |
783 } | 788 } |
784 | 789 |
| 790 TEST_F(CountingPolicyTest, CapReturns) { |
| 791 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 792 |
| 793 for (int i = 0; i < 305; i++) { |
| 794 scoped_refptr<Action> action = |
| 795 new Action("punky", |
| 796 base::Time::Now(), |
| 797 Action::ACTION_API_CALL, |
| 798 base::StringPrintf("apicall_%d", i)); |
| 799 policy->ProcessAction(action); |
| 800 } |
| 801 policy->Flush(); |
| 802 |
| 803 CheckReadFilteredData( |
| 804 policy, |
| 805 "punky", |
| 806 Action::ACTION_ANY, |
| 807 "", |
| 808 "", |
| 809 "", |
| 810 base::Bind( |
| 811 &CountingPolicyTest::RetrieveActions_FetchFilteredActions300)); |
| 812 policy->Close(); |
| 813 } |
| 814 |
785 TEST_F(CountingPolicyTest, RemoveAllURLs) { | 815 TEST_F(CountingPolicyTest, RemoveAllURLs) { |
786 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); | 816 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); |
787 | 817 |
788 // Use a mock clock to ensure that events are not recorded on the wrong day | 818 // Use a mock clock to ensure that events are not recorded on the wrong day |
789 // when the test is run close to local midnight. | 819 // when the test is run close to local midnight. |
790 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | 820 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
791 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | 821 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
792 base::TimeDelta::FromHours(12)); | 822 base::TimeDelta::FromHours(12)); |
793 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | 823 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
794 | 824 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 | 923 |
894 CheckReadData( | 924 CheckReadData( |
895 policy, | 925 policy, |
896 "punky", | 926 "punky", |
897 0, | 927 0, |
898 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); | 928 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); |
899 policy->Close(); | 929 policy->Close(); |
900 } | 930 } |
901 | 931 |
902 } // namespace extensions | 932 } // namespace extensions |
OLD | NEW |