OLD | NEW |
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/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 "ID=punky CATEGORY=api_call API=brewster COUNT=%d", count); | 242 "ID=punky CATEGORY=api_call API=brewster COUNT=%d", count); |
243 if (count > 0) { | 243 if (count > 0) { |
244 ASSERT_EQ(1u, actions->size()); | 244 ASSERT_EQ(1u, actions->size()); |
245 ASSERT_EQ(api_print, actions->at(0)->PrintForDebug()); | 245 ASSERT_EQ(api_print, actions->at(0)->PrintForDebug()); |
246 ASSERT_EQ(time, actions->at(0)->time()); | 246 ASSERT_EQ(time, actions->at(0)->time()); |
247 } else { | 247 } else { |
248 ASSERT_EQ(0u, actions->size()); | 248 ASSERT_EQ(0u, actions->size()); |
249 } | 249 } |
250 } | 250 } |
251 | 251 |
| 252 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 253 std::string action_urls_cleared = |
| 254 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] COUNT=1"; |
| 255 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 256 ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug()); |
| 257 ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug()); |
| 258 } |
| 259 |
| 260 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 261 std::string action_nothing_cleared = |
| 262 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 263 "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" " |
| 264 "ARG_URL=http://www.arg-urls.com/ COUNT=1"; |
| 265 std::string action_has_page_url = |
| 266 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 267 "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" COUNT=1"; |
| 268 std::string action_has_arg_url = |
| 269 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 270 "ARG_URL=http://www.google.com/ COUNT=1"; |
| 271 std::string action_no_url_info = |
| 272 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] COUNT=1"; |
| 273 |
| 274 ASSERT_EQ(5, static_cast<int>(actions->size())); |
| 275 // These should be in reverse time order. |
| 276 ASSERT_EQ(action_nothing_cleared, actions->at(0)->PrintForDebug()); |
| 277 ASSERT_EQ(action_has_page_url, actions->at(1)->PrintForDebug()); |
| 278 ASSERT_EQ(action_no_url_info, actions->at(2)->PrintForDebug()); |
| 279 ASSERT_EQ(action_has_arg_url, actions->at(3)->PrintForDebug()); |
| 280 ASSERT_EQ(action_no_url_info, actions->at(4)->PrintForDebug()); |
| 281 } |
| 282 |
252 protected: | 283 protected: |
253 ExtensionService* extension_service_; | 284 ExtensionService* extension_service_; |
254 scoped_ptr<TestingProfile> profile_; | 285 scoped_ptr<TestingProfile> profile_; |
255 content::TestBrowserThreadBundle thread_bundle_; | 286 content::TestBrowserThreadBundle thread_bundle_; |
256 // Used to preserve a copy of the original command line. | 287 // Used to preserve a copy of the original command line. |
257 // The test framework will do this itself as well. However, by then, | 288 // The test framework will do this itself as well. However, by then, |
258 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 289 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
259 // TearDown(). | 290 // TearDown(). |
260 CommandLine saved_cmdline_; | 291 CommandLine saved_cmdline_; |
261 | 292 |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 scoped_refptr<Action> action = | 758 scoped_refptr<Action> action = |
728 new Action("punky", | 759 new Action("punky", |
729 base::Time::Now(), | 760 base::Time::Now(), |
730 Action::ACTION_API_CALL, | 761 Action::ACTION_API_CALL, |
731 base::StringPrintf("apicall_%d", i)); | 762 base::StringPrintf("apicall_%d", i)); |
732 policy->ProcessAction(action); | 763 policy->ProcessAction(action); |
733 } | 764 } |
734 | 765 |
735 policy->ScheduleAndForget(policy, &CountingPolicyTest::CheckQueueSize); | 766 policy->ScheduleAndForget(policy, &CountingPolicyTest::CheckQueueSize); |
736 WaitOnThread(BrowserThread::DB); | 767 WaitOnThread(BrowserThread::DB); |
737 | |
738 policy->Close(); | 768 policy->Close(); |
739 } | 769 } |
740 | 770 |
| 771 TEST_F(CountingPolicyTest, RemoveAllURLs) { |
| 772 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); |
| 773 |
| 774 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 775 // when the test is run close to local midnight. |
| 776 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 777 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 778 base::TimeDelta::FromHours(12)); |
| 779 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 780 |
| 781 // Record some actions |
| 782 scoped_refptr<Action> action = |
| 783 new Action("punky", mock_clock->Now(), |
| 784 Action::ACTION_DOM_ACCESS, "lets"); |
| 785 action->mutable_args()->AppendString("vamoose"); |
| 786 action->set_page_url(GURL("http://www.google.com")); |
| 787 action->set_page_title("Google"); |
| 788 action->set_arg_url(GURL("http://www.google.com")); |
| 789 policy->ProcessAction(action); |
| 790 |
| 791 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 792 action = new Action( |
| 793 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 794 action->mutable_args()->AppendString("vamoose"); |
| 795 action->set_page_url(GURL("http://www.google2.com")); |
| 796 action->set_page_title("Google"); |
| 797 // Deliberately no arg url set to make sure it stills works if there is no arg |
| 798 // url. |
| 799 policy->ProcessAction(action); |
| 800 |
| 801 // Clean all the URLs. |
| 802 std::vector<GURL> no_url_restrictions; |
| 803 policy->RemoveURLs(no_url_restrictions); |
| 804 |
| 805 CheckReadData( |
| 806 policy, |
| 807 "punky", |
| 808 0, |
| 809 base::Bind(&CountingPolicyTest::AllURLsRemoved)); |
| 810 policy->Close(); |
| 811 } |
| 812 |
| 813 TEST_F(CountingPolicyTest, RemoveSpecificURLs) { |
| 814 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); |
| 815 |
| 816 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 817 // when the test is run close to local midnight. |
| 818 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 819 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 820 base::TimeDelta::FromHours(12)); |
| 821 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 822 |
| 823 // Record some actions |
| 824 // This should have the page url and args url cleared. |
| 825 scoped_refptr<Action> action = new Action("punky", mock_clock->Now(), |
| 826 Action::ACTION_DOM_ACCESS, "lets"); |
| 827 action->mutable_args()->AppendString("vamoose"); |
| 828 action->set_page_url(GURL("http://www.google1.com")); |
| 829 action->set_page_title("Google"); |
| 830 action->set_arg_url(GURL("http://www.google1.com")); |
| 831 policy->ProcessAction(action); |
| 832 |
| 833 // This should have the page url cleared but not args url. |
| 834 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 835 action = new Action( |
| 836 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 837 action->mutable_args()->AppendString("vamoose"); |
| 838 action->set_page_url(GURL("http://www.google1.com")); |
| 839 action->set_page_title("Google"); |
| 840 action->set_arg_url(GURL("http://www.google.com")); |
| 841 policy->ProcessAction(action); |
| 842 |
| 843 // This should have the page url cleared. The args url is deliberately not |
| 844 // set to make sure this doesn't cause any issues. |
| 845 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 846 action = new Action( |
| 847 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 848 action->mutable_args()->AppendString("vamoose"); |
| 849 action->set_page_url(GURL("http://www.google2.com")); |
| 850 action->set_page_title("Google"); |
| 851 policy->ProcessAction(action); |
| 852 |
| 853 // This should have the args url cleared but not the page url or page title. |
| 854 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 855 action = new Action( |
| 856 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 857 action->mutable_args()->AppendString("vamoose"); |
| 858 action->set_page_url(GURL("http://www.google.com")); |
| 859 action->set_page_title("Google"); |
| 860 action->set_arg_url(GURL("http://www.google1.com")); |
| 861 policy->ProcessAction(action); |
| 862 |
| 863 // This should have neither cleared. |
| 864 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 865 action = new Action( |
| 866 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 867 action->mutable_args()->AppendString("vamoose"); |
| 868 action->set_page_url(GURL("http://www.google.com")); |
| 869 action->set_page_title("Google"); |
| 870 action->set_arg_url(GURL("http://www.arg-urls.com")); |
| 871 policy->ProcessAction(action); |
| 872 |
| 873 // Clean some URLs. |
| 874 std::vector<GURL> urls; |
| 875 urls.push_back(GURL("http://www.google1.com")); |
| 876 urls.push_back(GURL("http://www.google2.com")); |
| 877 urls.push_back(GURL("http://www.url_not_in_db.com")); |
| 878 policy->RemoveURLs(urls); |
| 879 |
| 880 CheckReadData( |
| 881 policy, |
| 882 "punky", |
| 883 0, |
| 884 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); |
| 885 policy->Close(); |
| 886 } |
| 887 |
741 } // namespace extensions | 888 } // namespace extensions |
OLD | NEW |