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()); | |
felt
2013/08/27 23:16:55
I'm trying to make a rule that new tests should di
karenlees
2013/08/27 23:26:55
Sure, if you already have the new rule can you poi
felt
2013/08/27 23:32:47
Np, I sort of originally imagined I would get to t
| |
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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 768 |
738 policy->Close(); | 769 policy->Close(); |
739 } | 770 } |
740 | 771 |
772 TEST_F(CountingPolicyTest, RemoveAllURLs) { | |
773 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); | |
774 | |
775 // Use a mock clock to ensure that events are not recorded on the wrong day | |
776 // when the test is run close to local midnight. | |
777 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | |
778 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | |
779 base::TimeDelta::FromHours(12)); | |
780 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | |
781 | |
782 // Record some actions | |
783 scoped_refptr<Action> action = | |
784 new Action("punky", mock_clock->Now(), | |
785 Action::ACTION_DOM_ACCESS, "lets"); | |
786 action->mutable_args()->AppendString("vamoose"); | |
787 action->set_page_url(GURL("http://www.google.com")); | |
788 action->set_page_title("Google"); | |
789 action->set_arg_url(GURL("http://www.google.com")); | |
790 policy->ProcessAction(action); | |
791 | |
792 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); | |
793 action = new Action( | |
794 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
795 action->mutable_args()->AppendString("vamoose"); | |
796 action->set_page_url(GURL("http://www.google2.com")); | |
797 action->set_page_title("Google"); | |
798 // Deliberately no arg url set to make sure it stills works if there is no arg | |
799 // url. | |
800 policy->ProcessAction(action); | |
801 | |
802 // Clean all the URLs. | |
803 std::vector<GURL> no_url_restrictions; | |
804 policy->RemoveURLs(no_url_restrictions); | |
805 | |
806 CheckReadData( | |
807 policy, | |
808 "punky", | |
809 0, | |
810 base::Bind(&CountingPolicyTest::AllURLsRemoved)); | |
811 policy->Close(); | |
812 } | |
813 | |
814 TEST_F(CountingPolicyTest, RemoveSpecificURLs) { | |
815 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); | |
816 | |
817 // Use a mock clock to ensure that events are not recorded on the wrong day | |
818 // when the test is run close to local midnight. | |
819 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | |
820 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | |
821 base::TimeDelta::FromHours(12)); | |
822 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | |
823 | |
824 // Record some actions | |
825 // This should have the page url and args url cleared. | |
826 scoped_refptr<Action> action = new Action("punky", mock_clock->Now(), | |
827 Action::ACTION_DOM_ACCESS, "lets"); | |
828 action->mutable_args()->AppendString("vamoose"); | |
829 action->set_page_url(GURL("http://www.google1.com")); | |
830 action->set_page_title("Google"); | |
831 action->set_arg_url(GURL("http://www.google1.com")); | |
832 policy->ProcessAction(action); | |
833 | |
834 // This should have the page url cleared but not args url. | |
835 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); | |
836 action = new Action( | |
837 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
838 action->mutable_args()->AppendString("vamoose"); | |
839 action->set_page_url(GURL("http://www.google1.com")); | |
840 action->set_page_title("Google"); | |
841 action->set_arg_url(GURL("http://www.google.com")); | |
842 policy->ProcessAction(action); | |
843 | |
844 // This should have the page url cleared. The args url is deliberately not | |
845 // set to make sure this doesn't cause any issues. | |
846 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); | |
847 action = new Action( | |
848 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
849 action->mutable_args()->AppendString("vamoose"); | |
850 action->set_page_url(GURL("http://www.google2.com")); | |
851 action->set_page_title("Google"); | |
852 policy->ProcessAction(action); | |
853 | |
854 // This should have the args url cleared but not the page url or page title. | |
855 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); | |
856 action = new Action( | |
857 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
858 action->mutable_args()->AppendString("vamoose"); | |
859 action->set_page_url(GURL("http://www.google.com")); | |
860 action->set_page_title("Google"); | |
861 action->set_arg_url(GURL("http://www.google1.com")); | |
862 policy->ProcessAction(action); | |
863 | |
864 // This should have neither cleared. | |
865 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); | |
866 action = new Action( | |
867 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
868 action->mutable_args()->AppendString("vamoose"); | |
869 action->set_page_url(GURL("http://www.google.com")); | |
870 action->set_page_title("Google"); | |
871 action->set_arg_url(GURL("http://www.arg-urls.com")); | |
872 policy->ProcessAction(action); | |
873 | |
874 // Clean some URLs. | |
875 std::vector<GURL> urls; | |
876 urls.push_back(GURL("http://www.google1.com")); | |
877 urls.push_back(GURL("http://www.google2.com")); | |
878 urls.push_back(GURL("http://www.url_not_in_db.com")); | |
879 policy->RemoveURLs(urls); | |
880 | |
881 CheckReadData( | |
882 policy, | |
883 "punky", | |
884 0, | |
885 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); | |
886 policy->Close(); | |
887 } | |
888 | |
741 } // namespace extensions | 889 } // namespace extensions |
OLD | NEW |