Index: chrome/browser/extensions/activity_log/fullstream_ui_policy_unittest.cc |
diff --git a/chrome/browser/extensions/activity_log/fullstream_ui_policy_unittest.cc b/chrome/browser/extensions/activity_log/fullstream_ui_policy_unittest.cc |
index 2f5edff348073a7c1461857fe0d4f2a8ae75b461..7f2fab901d116125fd47742b9db3647209f1514b 100644 |
--- a/chrome/browser/extensions/activity_log/fullstream_ui_policy_unittest.cc |
+++ b/chrome/browser/extensions/activity_log/fullstream_ui_policy_unittest.cc |
@@ -190,6 +190,37 @@ class FullStreamUIPolicyTest : public testing::Test { |
ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); |
} |
+ static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
+ std::string action_urls_cleared = |
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"]"; |
+ 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_nothing_cleared = |
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
+ "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" " |
+ "ARG_URL=http://www.arg-urls.com/"; |
+ std::string action_has_page_url = |
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
+ "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\""; |
+ std::string action_has_arg_url = |
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
+ "ARG_URL=http://www.google.com/"; |
+ std::string action_no_url_info = |
+ "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"]"; |
+ |
+ ASSERT_EQ(5, static_cast<int>(actions->size())); |
+ // These should be in reverse time order. |
+ EXPECT_EQ(action_nothing_cleared, actions->at(0)->PrintForDebug()); |
+ EXPECT_EQ(action_has_page_url, actions->at(1)->PrintForDebug()); |
+ EXPECT_EQ(action_no_url_info, actions->at(2)->PrintForDebug()); |
+ EXPECT_EQ(action_has_arg_url, actions->at(3)->PrintForDebug()); |
+ EXPECT_EQ(action_no_url_info, actions->at(4)->PrintForDebug()); |
+ } |
+ |
protected: |
ExtensionService* extension_service_; |
scoped_ptr<TestingProfile> profile_; |
@@ -483,4 +514,121 @@ TEST_F(FullStreamUIPolicyTest, GetOlderActions) { |
policy->Close(); |
} |
+TEST_F(FullStreamUIPolicyTest, RemoveAllURLs) { |
+ ActivityLogPolicy* policy = new FullStreamUIPolicy(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.google.com")); |
+ action->set_page_title("Google"); |
+ action->set_arg_url(GURL("http://www.google.com")); |
+ policy->ProcessAction(action); |
+ |
+ mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
+ 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"); |
+ // Deliberately no arg url set to make sure it still works when there is no |
+ // arg url. |
+ policy->ProcessAction(action); |
+ |
+ // Clean all the URLs. |
+ std::vector<GURL> no_url_restrictions; |
+ policy->RemoveURLs(no_url_restrictions); |
+ |
+ CheckReadData( |
+ policy, |
+ "punky", |
+ 0, |
+ base::Bind(&FullStreamUIPolicyTest::AllURLsRemoved)); |
+ policy->Close(); |
+} |
+ |
+TEST_F(FullStreamUIPolicyTest, RemoveSpecificURLs) { |
+ ActivityLogPolicy* policy = new FullStreamUIPolicy(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 |
+ // This should have the page url and args url cleared. |
+ 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.google1.com")); |
+ policy->ProcessAction(action); |
+ |
+ // This should have the page url cleared but not args url. |
+ mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
+ 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); |
+ |
+ // This should have the page url cleared. The args url is deliberately not set |
+ // to make sure this doesn't cause any issues. |
+ mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
+ 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"); |
+ policy->ProcessAction(action); |
+ |
+ // This should have the args url cleared but not the page url or page title. |
+ mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
+ 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"); |
+ action->set_arg_url(GURL("http://www.google1.com")); |
+ policy->ProcessAction(action); |
+ |
+ // This should have neither cleared. |
+ mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
+ 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"); |
+ action->set_arg_url(GURL("http://www.arg-urls.com")); |
+ 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(&FullStreamUIPolicyTest::SomeURLsRemoved)); |
+ policy->Close(); |
+} |
+ |
} // namespace extensions |