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/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "base/test/simple_test_clock.h" | 10 #include "base/test/simple_test_clock.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 std::string api_print = | 183 std::string api_print = |
184 "ID=punky CATEGORY=api_call API=brewster ARGS=[\"woof\"]"; | 184 "ID=punky CATEGORY=api_call API=brewster ARGS=[\"woof\"]"; |
185 std::string dom_print = | 185 std::string dom_print = |
186 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " | 186 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
187 "PAGE_URL=http://www.google.com/"; | 187 "PAGE_URL=http://www.google.com/"; |
188 ASSERT_EQ(2, static_cast<int>(actions->size())); | 188 ASSERT_EQ(2, static_cast<int>(actions->size())); |
189 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); | 189 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); |
190 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); | 190 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); |
191 } | 191 } |
192 | 192 |
| 193 static void AllURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 194 std::string action_urls_cleared = |
| 195 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"]"; |
| 196 ASSERT_EQ(2, static_cast<int>(actions->size())); |
| 197 ASSERT_EQ(action_urls_cleared, actions->at(0)->PrintForDebug()); |
| 198 ASSERT_EQ(action_urls_cleared, actions->at(1)->PrintForDebug()); |
| 199 } |
| 200 |
| 201 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) { |
| 202 std::string action_nothing_cleared = |
| 203 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 204 "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\" " |
| 205 "ARG_URL=http://www.arg-urls.com/"; |
| 206 std::string action_has_page_url = |
| 207 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 208 "PAGE_URL=http://www.google.com/ PAGE_TITLE=\"Google\""; |
| 209 std::string action_has_arg_url = |
| 210 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"] " |
| 211 "ARG_URL=http://www.google.com/"; |
| 212 std::string action_no_url_info = |
| 213 "ID=punky CATEGORY=dom_access API=lets ARGS=[\"vamoose\"]"; |
| 214 |
| 215 ASSERT_EQ(5, static_cast<int>(actions->size())); |
| 216 // These should be in reverse time order. |
| 217 EXPECT_EQ(action_nothing_cleared, actions->at(0)->PrintForDebug()); |
| 218 EXPECT_EQ(action_has_page_url, actions->at(1)->PrintForDebug()); |
| 219 EXPECT_EQ(action_no_url_info, actions->at(2)->PrintForDebug()); |
| 220 EXPECT_EQ(action_has_arg_url, actions->at(3)->PrintForDebug()); |
| 221 EXPECT_EQ(action_no_url_info, actions->at(4)->PrintForDebug()); |
| 222 } |
| 223 |
193 protected: | 224 protected: |
194 ExtensionService* extension_service_; | 225 ExtensionService* extension_service_; |
195 scoped_ptr<TestingProfile> profile_; | 226 scoped_ptr<TestingProfile> profile_; |
196 content::TestBrowserThreadBundle thread_bundle_; | 227 content::TestBrowserThreadBundle thread_bundle_; |
197 // Used to preserve a copy of the original command line. | 228 // Used to preserve a copy of the original command line. |
198 // The test framework will do this itself as well. However, by then, | 229 // The test framework will do this itself as well. However, by then, |
199 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in | 230 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in |
200 // TearDown(). | 231 // TearDown(). |
201 CommandLine saved_cmdline_; | 232 CommandLine saved_cmdline_; |
202 | 233 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 policy->ProcessAction(action); | 507 policy->ProcessAction(action); |
477 | 508 |
478 CheckReadData( | 509 CheckReadData( |
479 policy, | 510 policy, |
480 "punky", | 511 "punky", |
481 3, | 512 3, |
482 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions)); | 513 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions)); |
483 policy->Close(); | 514 policy->Close(); |
484 } | 515 } |
485 | 516 |
| 517 TEST_F(FullStreamUIPolicyTest, RemoveAllURLs) { |
| 518 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| 519 |
| 520 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 521 // when the test is run close to local midnight. |
| 522 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 523 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 524 base::TimeDelta::FromHours(12)); |
| 525 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 526 |
| 527 // Record some actions |
| 528 scoped_refptr<Action> action = |
| 529 new Action("punky", mock_clock->Now(), |
| 530 Action::ACTION_DOM_ACCESS, "lets"); |
| 531 action->mutable_args()->AppendString("vamoose"); |
| 532 action->set_page_url(GURL("http://www.google.com")); |
| 533 action->set_page_title("Google"); |
| 534 action->set_arg_url(GURL("http://www.google.com")); |
| 535 policy->ProcessAction(action); |
| 536 |
| 537 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 538 action = new Action( |
| 539 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 540 action->mutable_args()->AppendString("vamoose"); |
| 541 action->set_page_url(GURL("http://www.google2.com")); |
| 542 action->set_page_title("Google"); |
| 543 // Deliberately no arg url set to make sure it still works when there is no |
| 544 // arg url. |
| 545 policy->ProcessAction(action); |
| 546 |
| 547 // Clean all the URLs. |
| 548 std::vector<GURL> no_url_restrictions; |
| 549 policy->RemoveURLs(no_url_restrictions); |
| 550 |
| 551 CheckReadData( |
| 552 policy, |
| 553 "punky", |
| 554 0, |
| 555 base::Bind(&FullStreamUIPolicyTest::AllURLsRemoved)); |
| 556 policy->Close(); |
| 557 } |
| 558 |
| 559 TEST_F(FullStreamUIPolicyTest, RemoveSpecificURLs) { |
| 560 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get()); |
| 561 |
| 562 // Use a mock clock to ensure that events are not recorded on the wrong day |
| 563 // when the test is run close to local midnight. |
| 564 base::SimpleTestClock* mock_clock = new base::SimpleTestClock(); |
| 565 mock_clock->SetNow(base::Time::Now().LocalMidnight() + |
| 566 base::TimeDelta::FromHours(12)); |
| 567 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock)); |
| 568 |
| 569 // Record some actions |
| 570 // This should have the page url and args url cleared. |
| 571 scoped_refptr<Action> action = new Action("punky", mock_clock->Now(), |
| 572 Action::ACTION_DOM_ACCESS, "lets"); |
| 573 action->mutable_args()->AppendString("vamoose"); |
| 574 action->set_page_url(GURL("http://www.google1.com")); |
| 575 action->set_page_title("Google"); |
| 576 action->set_arg_url(GURL("http://www.google1.com")); |
| 577 policy->ProcessAction(action); |
| 578 |
| 579 // This should have the page url cleared but not args url. |
| 580 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 581 action = new Action( |
| 582 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 583 action->mutable_args()->AppendString("vamoose"); |
| 584 action->set_page_url(GURL("http://www.google1.com")); |
| 585 action->set_page_title("Google"); |
| 586 action->set_arg_url(GURL("http://www.google.com")); |
| 587 policy->ProcessAction(action); |
| 588 |
| 589 // This should have the page url cleared. The args url is deliberately not set |
| 590 // to make sure this doesn't cause any issues. |
| 591 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 592 action = new Action( |
| 593 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 594 action->mutable_args()->AppendString("vamoose"); |
| 595 action->set_page_url(GURL("http://www.google2.com")); |
| 596 action->set_page_title("Google"); |
| 597 policy->ProcessAction(action); |
| 598 |
| 599 // This should have the args url cleared but not the page url or page title. |
| 600 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 601 action = new Action( |
| 602 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 603 action->mutable_args()->AppendString("vamoose"); |
| 604 action->set_page_url(GURL("http://www.google.com")); |
| 605 action->set_page_title("Google"); |
| 606 action->set_arg_url(GURL("http://www.google1.com")); |
| 607 policy->ProcessAction(action); |
| 608 |
| 609 // This should have neither cleared. |
| 610 mock_clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 611 action = new Action( |
| 612 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets"); |
| 613 action->mutable_args()->AppendString("vamoose"); |
| 614 action->set_page_url(GURL("http://www.google.com")); |
| 615 action->set_page_title("Google"); |
| 616 action->set_arg_url(GURL("http://www.arg-urls.com")); |
| 617 policy->ProcessAction(action); |
| 618 |
| 619 // Clean some URLs. |
| 620 std::vector<GURL> urls; |
| 621 urls.push_back(GURL("http://www.google1.com")); |
| 622 urls.push_back(GURL("http://www.google2.com")); |
| 623 urls.push_back(GURL("http://www.url_not_in_db.com")); |
| 624 policy->RemoveURLs(urls); |
| 625 |
| 626 CheckReadData( |
| 627 policy, |
| 628 "punky", |
| 629 0, |
| 630 base::Bind(&FullStreamUIPolicyTest::SomeURLsRemoved)); |
| 631 policy->Close(); |
| 632 } |
| 633 |
486 } // namespace extensions | 634 } // namespace extensions |
OLD | NEW |