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

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

Issue 18878009: Add functions to clean URLs from the activity log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added counting policy Created 7 years, 4 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 c7c364efe896e6b56511bbf7c723db4fa98a0ef2..c249c255228300857e8d171192fd5f41986df9b1 100644
--- a/chrome/browser/extensions/activity_log/counting_policy_unittest.cc
+++ b/chrome/browser/extensions/activity_log/counting_policy_unittest.cc
@@ -194,6 +194,27 @@ class CountingPolicyTest : public testing::Test {
}
}
+ static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) {
+ std::string action_urls_cleared =
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] COUNT=1";
+ ASSERT_EQ(2, static_cast<int>(actions->size()));
+ ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug());
+ ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug());
+ }
+
+ static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) {
+ std::string action_urls_not_cleared =
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] "
+ "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" "
+ "ARG_URL=http://www.google.com/ COUNT=1";
+ std::string action_urls_cleared =
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] COUNT=1";
+ ASSERT_EQ(3, static_cast<int>(actions->size()));
+ ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug());
+ ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug());
+ ASSERT_EQ(action_urls_not_cleared, actions->at(2)->PrintForDebug());
+ }
+
protected:
ExtensionService* extension_service_;
scoped_ptr<TestingProfile> profile_;
@@ -572,4 +593,93 @@ TEST_F(CountingPolicyTest, MoreMerging) {
policy->Close();
}
+TEST_F(CountingPolicyTest, RemoveAllURLs) {
+ ActivityLogPolicy* policy = new CountingPolicy(profile_.get());
+
+ // Use a mock clock to ensure that events are not recorded on the wrong day
+ // when the test is run close to local midnight.
+ base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
+ mock_clock->SetNow(base::Time::Now().LocalMidnight() +
+ base::TimeDelta::FromHours(12));
+ policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
+
+ // Record some actions
+ scoped_refptr<Action> action =
+ new Action("punky", mock_clock->Now(),
mvrable 2013/08/26 18:14:57 When data is read from the database in CheckReadDa
karenlees 2013/08/26 22:58:36 Done.
+ Action::ACTION_DOM_ACCESS, "lets");
+ action->mutable_args()->AppendString("vamoose");
+ action->set_page_url(GURL("http://www.google.com"));
+ action->set_page_title("Google");
+ action->set_arg_url(GURL("http://www.google.com"));
+ policy->ProcessAction(action);
+
+ action = new Action(
+ "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
+ action->mutable_args()->AppendString("vamoose");
+ action->set_page_url(GURL("http://www.google2.com"));
+ action->set_page_title("Google");
+ action->set_arg_url(GURL("http://www.google2.com"));
+ policy->ProcessAction(action);
+
+ // Clean all the URLs.
+ std::vector<GURL> no_url_restrictions;
+ policy->RemoveURLs(no_url_restrictions);
+
+ CheckReadData(
+ policy,
+ "punky",
+ 0,
+ base::Bind(&CountingPolicyTest::AllURLsRemoved));
+ policy->Close();
+}
+
+TEST_F(CountingPolicyTest, RemoveSpecificURLs) {
+ ActivityLogPolicy* policy = new CountingPolicy(profile_.get());
+
+ // Use a mock clock to ensure that events are not recorded on the wrong day
+ // when the test is run close to local midnight.
+ base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
+ mock_clock->SetNow(base::Time::Now().LocalMidnight() +
+ base::TimeDelta::FromHours(12));
+ policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
+
+ // Record some actions
+ scoped_refptr<Action> action =
+ new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
+ action->mutable_args()->AppendString("vamoose");
+ action->set_page_url(GURL("http://www.google1.com"));
+ action->set_page_title("Google");
+ action->set_arg_url(GURL("http://www.google.com"));
+ policy->ProcessAction(action);
+
+ action = new Action(
+ "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
+ action->mutable_args()->AppendString("vamoose");
+ action->set_page_url(GURL("http://www.google2.com"));
+ action->set_page_title("Google");
+ action->set_arg_url(GURL("http://www.google2.com"));
+ policy->ProcessAction(action);
+
+ action = new Action(
+ "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
+ action->mutable_args()->AppendString("vamoose");
+ action->set_page_url(GURL("http://www.google.com"));
+ action->set_page_title("Google");
mvrable 2013/08/26 18:14:57 Missing a action->set_arg_url(GURL("http://www.goo
karenlees 2013/08/26 22:58:36 This was deliberate to make sure the sql statement
+ policy->ProcessAction(action);
+
+ // Clean some URLs.
+ std::vector<GURL> urls;
+ urls.push_back(GURL("http://www.google1.com"));
+ urls.push_back(GURL("http://www.google2.com"));
+ urls.push_back(GURL("http://www.url_not_in_db.com"));
+ policy->RemoveURLs(urls);
+
+ CheckReadData(
+ policy,
+ "punky",
+ 0,
+ base::Bind(&CountingPolicyTest::SomeURLsRemoved));
+ policy->Close();
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698