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

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

Issue 23629015: Add deletion to the activityLogPrivate API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Undoing last commit 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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 733 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 policy->RemoveURLs(urls); 927 policy->RemoveURLs(urls);
923 928
924 CheckReadData( 929 CheckReadData(
925 policy, 930 policy,
926 "punky", 931 "punky",
927 0, 932 0,
928 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); 933 base::Bind(&CountingPolicyTest::SomeURLsRemoved));
929 policy->Close(); 934 policy->Close();
930 } 935 }
931 936
937 TEST_F(CountingPolicyTest, DeleteActions) {
938 CountingPolicy* policy = new CountingPolicy(profile_.get());
939 // Disable row expiration for this test by setting a time before any actions
940 // we generate.
941 policy->set_retention_time(base::TimeDelta::FromDays(14));
942
943 // Use a mock clock to ensure that events are not recorded on the wrong day
944 // when the test is run close to local midnight. Note: Ownership is passed
945 // to the policy, but we still keep a pointer locally. The policy will take
946 // care of destruction; this is safe since the policy outlives all our
947 // accesses to the mock clock.
948 base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
949 mock_clock->SetNow(base::Time::Now().LocalMidnight() +
950 base::TimeDelta::FromHours(12));
951 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
952
953 // Record some actions
954 scoped_refptr<Action> action =
955 new Action("punky",
956 mock_clock->Now() - base::TimeDelta::FromMinutes(40),
957 Action::ACTION_API_CALL,
958 "brewster");
959 action->mutable_args()->AppendString("woof");
960 policy->ProcessAction(action);
961
962 action = new Action("punky",
963 mock_clock->Now() - base::TimeDelta::FromMinutes(30),
964 Action::ACTION_API_CALL,
965 "brewster");
966 action->mutable_args()->AppendString("meow");
967 policy->ProcessAction(action);
968
969 action = new Action("punky",
970 mock_clock->Now() - base::TimeDelta::FromMinutes(20),
971 Action::ACTION_API_CALL,
972 "extension.sendMessage");
973 action->mutable_args()->AppendString("not");
974 action->mutable_args()->AppendString("stripped");
975 policy->ProcessAction(action);
976
977 action =
978 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
979 action->mutable_args()->AppendString("vamoose");
980 action->set_page_url(GURL("http://www.google.com"));
981 policy->ProcessAction(action);
982
983 action = new Action(
984 "scoobydoo", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
985 action->mutable_args()->AppendString("vamoose");
986 action->set_page_url(GURL("http://www.google.com"));
987 policy->ProcessAction(action);
988
989 CheckReadData(
990 policy,
991 "punky",
992 0,
993 base::Bind(&CountingPolicyTest::Arguments_GetTodaysActions));
994
995 policy->DeleteDatabase();
996
997 CheckReadFilteredData(
998 policy,
999 "",
1000 Action::ACTION_ANY,
1001 "",
1002 "",
1003 "",
1004 base::Bind(
1005 &CountingPolicyTest::RetrieveActions_FetchFilteredActions0));
1006
1007 policy->Close();
1008 }
1009
932 } // namespace extensions 1010 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698