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

Unified Diff: chrome/browser/extensions/activity_log/counting_policy_unittest.cc

Issue 154053004: Introducing the activityLogPrivate.deleteActivities() API call. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebasing Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/activity_log/counting_policy_unittest.cc
diff --git a/chrome/browser/extensions/activity_log/counting_policy_unittest.cc b/chrome/browser/extensions/activity_log/counting_policy_unittest.cc
index d93d80a8471b416e95e8c72ac2c200bf9f4c15e0..fd07fc82a94975b6e76f05fe871783b130e18015 100644
--- a/chrome/browser/extensions/activity_log/counting_policy_unittest.cc
+++ b/chrome/browser/extensions/activity_log/counting_policy_unittest.cc
@@ -296,6 +296,107 @@ class CountingPolicyTest : public testing::Test {
ASSERT_NE(-1, action.action_id());
}
+ // A helper function initializes the policy with a number of actions, calls
+ // RemoveActions on a policy object and then checks the result of the
+ // deletion.
+ void CheckRemoveActions(
+ ActivityLogDatabasePolicy* policy,
+ const std::vector<int64>& action_ids,
+ const base::Callback<void(scoped_ptr<Action::ActionVector>)>& checker) {
+
+ // Record some actions
+ scoped_refptr<Action> action = new Action(
+ "punky1", base::Time::Now(), Action::ACTION_DOM_ACCESS, "lets1");
+ action->mutable_args()->AppendString("vamoose1");
+ action->set_page_url(GURL("http://www.google1.com"));
+ action->set_page_title("Google1");
+ action->set_arg_url(GURL("http://www.args-url1.com"));
+ policy->ProcessAction(action);
+ // Record the same action twice, so there are multiple entries in the
+ // database.
+ policy->ProcessAction(action);
+
+ action = new Action(
+ "punky2", base::Time::Now(), Action::ACTION_API_CALL, "lets2");
+ action->mutable_args()->AppendString("vamoose2");
+ action->set_page_url(GURL("http://www.google2.com"));
+ action->set_page_title("Google2");
+ action->set_arg_url(GURL("http://www.args-url2.com"));
+ policy->ProcessAction(action);
+ // Record the same action twice, so there are multiple entries in the
+ // database.
+ policy->ProcessAction(action);
+
+ // Submit a request to delete actions.
+ policy->RemoveActions(action_ids);
+
+ // Check the result of the deletion. The checker function gets all
+ // activities in the database.
+ CheckReadData(policy, "", -1, checker);
+
+ // Clean database.
+ policy->DeleteDatabase();
+ }
+
+ static void AllActionsDeleted(scoped_ptr<Action::ActionVector> actions) {
+ ASSERT_EQ(0, static_cast<int>(actions->size()));
+ }
+
+ static void NoActionsDeleted(scoped_ptr<Action::ActionVector> actions) {
+ // These will be in the vector in reverse time order.
+ ASSERT_EQ(2, static_cast<int>(actions->size()));
+ CheckAction(*actions->at(0),
+ "punky2",
+ Action::ACTION_API_CALL,
+ "lets2",
+ "",
+ "http://www.google2.com/",
+ "Google2",
+ "http://www.args-url2.com/",
+ 2);
+ ASSERT_EQ(2, actions->at(0)->action_id());
+ CheckAction(*actions->at(1),
+ "punky1",
+ Action::ACTION_DOM_ACCESS,
+ "lets1",
+ "",
+ "http://www.google1.com/",
+ "Google1",
+ "http://www.args-url1.com/",
+ 2);
+ ASSERT_EQ(1, actions->at(1)->action_id());
+ }
+
+ static void Action1Deleted(scoped_ptr<Action::ActionVector> actions) {
+ // These will be in the vector in reverse time order.
+ ASSERT_EQ(1, static_cast<int>(actions->size()));
+ CheckAction(*actions->at(0),
+ "punky2",
+ Action::ACTION_API_CALL,
+ "lets2",
+ "",
+ "http://www.google2.com/",
+ "Google2",
+ "http://www.args-url2.com/",
+ 2);
+ ASSERT_EQ(2, actions->at(0)->action_id());
+ }
+
+ static void Action2Deleted(scoped_ptr<Action::ActionVector> actions) {
+ // These will be in the vector in reverse time order.
+ ASSERT_EQ(1, static_cast<int>(actions->size()));
+ CheckAction(*actions->at(0),
+ "punky1",
+ Action::ACTION_DOM_ACCESS,
+ "lets1",
+ "",
+ "http://www.google1.com/",
+ "Google1",
+ "http://www.args-url1.com/",
+ 2);
+ ASSERT_EQ(1, actions->at(0)->action_id());
+ }
+
protected:
ExtensionService* extension_service_;
scoped_ptr<TestingProfile> profile_;
@@ -1008,7 +1109,7 @@ TEST_F(CountingPolicyTest, RemoveExtensionData) {
policy->Close();
}
-TEST_F(CountingPolicyTest, DeleteActions) {
+TEST_F(CountingPolicyTest, DeleteDatabase) {
CountingPolicy* policy = new CountingPolicy(profile_.get());
policy->Init();
// Disable row expiration for this test by setting a time before any actions
@@ -1152,4 +1253,50 @@ TEST_F(CountingPolicyTest, DuplicateRows) {
policy->Close();
}
+TEST_F(CountingPolicyTest, RemoveActions) {
+ ActivityLogDatabasePolicy* policy = new CountingPolicy(profile_.get());
+ policy->Init();
+
+ std::vector<int64> action_ids;
+
+ CheckRemoveActions(
+ policy, action_ids, base::Bind(&CountingPolicyTest::NoActionsDeleted));
+
+ action_ids.push_back(-1);
+ action_ids.push_back(-10);
+ action_ids.push_back(0);
+ action_ids.push_back(5);
+ action_ids.push_back(10);
+ CheckRemoveActions(
+ policy, action_ids, base::Bind(&CountingPolicyTest::NoActionsDeleted));
+ action_ids.clear();
+
+ for (int i = 0; i < 50; i++) {
+ action_ids.push_back(i + 3);
+ }
+ CheckRemoveActions(
+ policy, action_ids, base::Bind(&CountingPolicyTest::NoActionsDeleted));
+ action_ids.clear();
+
+ // CheckRemoveActions pushes two actions to the Activity Log database with IDs
+ // 1 and 2.
+ action_ids.push_back(1);
+ action_ids.push_back(2);
+ CheckRemoveActions(
+ policy, action_ids, base::Bind(&CountingPolicyTest::AllActionsDeleted));
+ action_ids.clear();
+
+ action_ids.push_back(1);
+ CheckRemoveActions(
+ policy, action_ids, base::Bind(&CountingPolicyTest::Action1Deleted));
+ action_ids.clear();
+
+ action_ids.push_back(2);
+ CheckRemoveActions(
+ policy, action_ids, base::Bind(&CountingPolicyTest::Action2Deleted));
+ action_ids.clear();
+
+ policy->Close();
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698