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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 "ID=punky CATEGORY=api_call API=brewster COUNT=%d", count); | 187 "ID=punky CATEGORY=api_call API=brewster COUNT=%d", count); |
188 if (count > 0) { | 188 if (count > 0) { |
189 ASSERT_EQ(1u, actions->size()); | 189 ASSERT_EQ(1u, actions->size()); |
190 ASSERT_EQ(api_print, actions->at(0)->PrintForDebug()); | 190 ASSERT_EQ(api_print, actions->at(0)->PrintForDebug()); |
191 ASSERT_EQ(time, actions->at(0)->time()); | 191 ASSERT_EQ(time, actions->at(0)->time()); |
192 } else { | 192 } else { |
193 ASSERT_EQ(0u, actions->size()); | 193 ASSERT_EQ(0u, actions->size()); |
194 } | 194 } |
195 } | 195 } |
196 | 196 |
197 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | |
198 std::string action_urls_cleared = | |
199 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] COUNT=1"; | |
200 ASSERT_EQ(2, static_cast<int>(actions->size())); | |
201 ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug()); | |
202 ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug()); | |
203 } | |
204 | |
205 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { | |
206 std::string action_urls_not_cleared = | |
207 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " | |
208 "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" " | |
209 "ARG_URL=http://www.google.com/ COUNT=1"; | |
210 std::string action_urls_cleared = | |
211 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] COUNT=1"; | |
212 ASSERT_EQ(3, static_cast<int>(actions->size())); | |
213 ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug()); | |
214 ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug()); | |
215 ASSERT_EQ(action_urls_not_cleared, actions->at(2)->PrintForDebug()); | |
216 } | |
217 | |
197 protected: | 218 protected: |
198 ExtensionService* extension_service_; | 219 ExtensionService* extension_service_; |
199 scoped_ptr<TestingProfile> profile_; | 220 scoped_ptr<TestingProfile> profile_; |
200 content::TestBrowserThreadBundle thread_bundle_; | 221 content::TestBrowserThreadBundle thread_bundle_; |
201 // Used to preserve a copy of the original command line. | 222 // Used to preserve a copy of the original command line. |
202 // The test framework will do this itself as well. However, by then, | 223 // The test framework will do this itself as well. However, by then, |
203 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 224 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
204 // TearDown(). | 225 // TearDown(). |
205 CommandLine saved_cmdline_; | 226 CommandLine saved_cmdline_; |
206 | 227 |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 | 586 |
566 CheckReadData( | 587 CheckReadData( |
567 policy, | 588 policy, |
568 "punky", | 589 "punky", |
569 0, | 590 0, |
570 base::Bind( | 591 base::Bind( |
571 &CountingPolicyTest::Arguments_CheckMergeCountAndTime, 3, time5)); | 592 &CountingPolicyTest::Arguments_CheckMergeCountAndTime, 3, time5)); |
572 policy->Close(); | 593 policy->Close(); |
573 } | 594 } |
574 | 595 |
596 TEST_F(CountingPolicyTest, RemoveAllURLs) { | |
597 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); | |
598 | |
599 // Use a mock clock to ensure that events are not recorded on the wrong day | |
600 // when the test is run close to local midnight. | |
601 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | |
602 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | |
603 base::TimeDelta::FromHours(12)); | |
604 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | |
605 | |
606 // Record some actions | |
607 scoped_refptr<Action> action = | |
608 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.
| |
609 Action::ACTION_DOM_ACCESS, "lets"); | |
610 action->mutable_args()->AppendString("vamoose"); | |
611 action->set_page_url(GURL("http://www.google.com")); | |
612 action->set_page_title("Google"); | |
613 action->set_arg_url(GURL("http://www.google.com")); | |
614 policy->ProcessAction(action); | |
615 | |
616 action = new Action( | |
617 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
618 action->mutable_args()->AppendString("vamoose"); | |
619 action->set_page_url(GURL("http://www.google2.com")); | |
620 action->set_page_title("Google"); | |
621 action->set_arg_url(GURL("http://www.google2.com")); | |
622 policy->ProcessAction(action); | |
623 | |
624 // Clean all the URLs. | |
625 std::vector<GURL> no_url_restrictions; | |
626 policy->RemoveURLs(no_url_restrictions); | |
627 | |
628 CheckReadData( | |
629 policy, | |
630 "punky", | |
631 0, | |
632 base::Bind(&CountingPolicyTest::AllURLsRemoved)); | |
633 policy->Close(); | |
634 } | |
635 | |
636 TEST_F(CountingPolicyTest, RemoveSpecificURLs) { | |
637 ActivityLogPolicy* policy = new CountingPolicy(profile_.get()); | |
638 | |
639 // Use a mock clock to ensure that events are not recorded on the wrong day | |
640 // when the test is run close to local midnight. | |
641 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); | |
642 mock_clock->SetNow(base::Time::Now().LocalMidnight() + | |
643 base::TimeDelta::FromHours(12)); | |
644 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); | |
645 | |
646 // Record some actions | |
647 scoped_refptr<Action> action = | |
648 new Action("punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
649 action->mutable_args()->AppendString("vamoose"); | |
650 action->set_page_url(GURL("http://www.google1.com")); | |
651 action->set_page_title("Google"); | |
652 action->set_arg_url(GURL("http://www.google.com")); | |
653 policy->ProcessAction(action); | |
654 | |
655 action = new Action( | |
656 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
657 action->mutable_args()->AppendString("vamoose"); | |
658 action->set_page_url(GURL("http://www.google2.com")); | |
659 action->set_page_title("Google"); | |
660 action->set_arg_url(GURL("http://www.google2.com")); | |
661 policy->ProcessAction(action); | |
662 | |
663 action = new Action( | |
664 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); | |
665 action->mutable_args()->AppendString("vamoose"); | |
666 action->set_page_url(GURL("http://www.google.com")); | |
667 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
| |
668 policy->ProcessAction(action); | |
669 | |
670 // Clean some URLs. | |
671 std::vector<GURL> urls; | |
672 urls.push_back(GURL("http://www.google1.com")); | |
673 urls.push_back(GURL("http://www.google2.com")); | |
674 urls.push_back(GURL("http://www.url_not_in_db.com")); | |
675 policy->RemoveURLs(urls); | |
676 | |
677 CheckReadData( | |
678 policy, | |
679 "punky", | |
680 0, | |
681 base::Bind(&CountingPolicyTest::SomeURLsRemoved)); | |
682 policy->Close(); | |
683 } | |
684 | |
575 } // namespace extensions | 685 } // namespace extensions |
OLD | NEW |