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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 scoped_ptr<Action::ActionVector> results) { | 169 scoped_ptr<Action::ActionVector> results) { |
170 checker.Run(results.Pass()); | 170 checker.Run(results.Pass()); |
171 done.Run(); | 171 done.Run(); |
172 } | 172 } |
173 | 173 |
174 static void TimeoutCallback() { | 174 static void TimeoutCallback() { |
175 base::MessageLoop::current()->QuitWhenIdle(); | 175 base::MessageLoop::current()->QuitWhenIdle(); |
176 FAIL() << "Policy test timed out waiting for results"; | 176 FAIL() << "Policy test timed out waiting for results"; |
177 } | 177 } |
178 | 178 |
| 179 static void RetrieveActions_FetchFilteredActions0( |
| 180 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 181 ASSERT_EQ(0, static_cast<int>(i->size())); |
| 182 } |
| 183 |
179 static void RetrieveActions_FetchFilteredActions1( | 184 static void RetrieveActions_FetchFilteredActions1( |
180 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 185 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
181 ASSERT_EQ(1, static_cast<int>(i->size())); | 186 ASSERT_EQ(1, static_cast<int>(i->size())); |
182 } | 187 } |
183 | 188 |
184 static void RetrieveActions_FetchFilteredActions2( | 189 static void RetrieveActions_FetchFilteredActions2( |
185 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 190 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
186 ASSERT_EQ(2, static_cast<int>(i->size())); | 191 ASSERT_EQ(2, static_cast<int>(i->size())); |
187 } | 192 } |
188 | 193 |
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
892 policy->RemoveURLs(urls); | 897 policy->RemoveURLs(urls); |
893 | 898 |
894 CheckReadData( | 899 CheckReadData( |
895 policy, | 900 policy, |
896 "punky", | 901 "punky", |
897 0, | 902 0, |
898 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); | 903 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); |
899 policy->Close(); | 904 policy->Close(); |
900 } | 905 } |
901 | 906 |
| 907 TEST_F(CountingPolicyTest, DeleteActions) { |
| 908 CountingPolicy* policy = new CountingPolicy(profile_.get()); |
| 909 // Disable row expiration for this test by setting a time before any actions |
| 910 // we generate. |
| 911 policy->set_retention_time(base::TimeDelta::FromDays(14)); |
| 912 |
| 913 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 914 // when the test is run close to local midnight. Note: Ownership is passed |
| 915 // to the policy, but we still keep a pointer locally. The policy will take |
| 916 // care of destruction; this is safe since the policy outlives all our |
| 917 // accesses to the mock clock. |
| 918 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 919 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 920 base::TimeDelta::FromHours(12)); |
| 921 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 922 |
| 923 // Record some actions |
| 924 scoped_refptr<Action> action = |
| 925 new Action("punky", |
| 926 mock_clock->Now() - base::TimeDelta::FromMinutes(40), |
| 927 Action::ACTION_API_CALL, |
| 928 "brewster"); |
| 929 action->mutable_args()->AppendString("woof"); |
| 930 policy->ProcessAction(action); |
| 931 |
| 932 action = new Action("punky", |
| 933 mock_clock->Now() - base::TimeDelta::FromMinutes(30), |
| 934 Action::ACTION_API_CALL, |
| 935 "brewster"); |
| 936 action->mutable_args()->AppendString("meow"); |
| 937 policy->ProcessAction(action); |
| 938 |
| 939 action = new Action("punky", |
| 940 mock_clock->Now() - base::TimeDelta::FromMinutes(20), |
| 941 Action::ACTION_API_CALL, |
| 942 "extension.sendMessage"); |
| 943 action->mutable_args()->AppendString("not"); |
| 944 action->mutable_args()->AppendString("stripped"); |
| 945 policy->ProcessAction(action); |
| 946 |
| 947 action = |
| 948 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 949 action->mutable_args()->AppendString("vamoose"); |
| 950 action->set_page_url(GURL("http://www.google.com")); |
| 951 policy->ProcessAction(action); |
| 952 |
| 953 action = new Action( |
| 954 "scoobydoo", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 955 action->mutable_args()->AppendString("vamoose"); |
| 956 action->set_page_url(GURL("http://www.google.com")); |
| 957 policy->ProcessAction(action); |
| 958 |
| 959 CheckReadData( |
| 960 policy, |
| 961 "punky", |
| 962 0, |
| 963 base::Bind(&CountingPolicyTest::Arguments_GetTodaysActions)); |
| 964 |
| 965 policy->DeleteDatabase(); |
| 966 |
| 967 CheckReadFilteredData( |
| 968 policy, |
| 969 "", |
| 970 Action::ACTION_ANY, |
| 971 "", |
| 972 "", |
| 973 "", |
| 974 base::Bind( |
| 975 &CountingPolicyTest::RetrieveActions_FetchFilteredActions0)); |
| 976 |
| 977 policy->Close(); |
| 978 } |
| 979 |
902 } // namespace extensions | 980 } // namespace extensions |
OLD | NEW |