Chromium Code Reviews| 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 c4f22fd23b3058a12aae4ead3706280e67f4d3cd..2772f4c914c4e2c2a18ad7e420f5c842e8b8a1f1 100644 |
| --- a/chrome/browser/extensions/activity_log/counting_policy_unittest.cc |
| +++ b/chrome/browser/extensions/activity_log/counting_policy_unittest.cc |
| @@ -289,6 +289,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_; |
| @@ -1001,7 +1102,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 |
| @@ -1117,4 +1218,66 @@ 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(); |
| + |
| + // policy->RemoveActions() deletes actions in batches of 50 itemis. Test the |
|
mvrable
2014/02/11 17:44:35
s/itemis/items/
pmarch
2014/02/12 18:19:04
Done.
|
| + // batch size boundary. |
| + for (int i = 0; i < 50; i++) { |
| + action_ids.push_back(i + 3); |
| + } |
| + CheckRemoveActions( |
| + policy, action_ids, base::Bind(&CountingPolicyTest::NoActionsDeleted)); |
| + action_ids.clear(); |
| + |
| + for (int i = 0; i < 51; i++) { |
| + action_ids.push_back(i + 3); |
| + } |
| + CheckRemoveActions( |
| + policy, action_ids, base::Bind(&CountingPolicyTest::NoActionsDeleted)); |
| + action_ids.clear(); |
| + |
| + for (int i = 0; i < 110; 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 |