Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/browser/extensions/activity_log/fullstream_ui_policy_unittest.cc

Issue 18878009: Add functions to clean URLs from the activity log (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use const_iterator Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/extensions/activity_log/fullstream_ui_policy.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ASSERT_EQ(2, static_cast<int>(actions->size()));
195 CheckAction(*actions->at(0), "punky", Action::ACTION_API_CALL, "lets",
196 "[\"vamoose\"]", "", "", "");
197 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets",
198 "[\"vamoose\"]", "", "", "");
199 }
200
201 static void SomeURLsRemoved(scoped_ptr<Action::ActionVector> actions) {
202 // These will be in the vector in reverse time order.
203 ASSERT_EQ(5, static_cast<int>(actions->size()));
204 CheckAction(*actions->at(0), "punky", Action::ACTION_DOM_ACCESS, "lets",
205 "[\"vamoose\"]", "http://www.google.com/", "Google",
206 "http://www.args-url.com/");
207 CheckAction(*actions->at(1), "punky", Action::ACTION_DOM_ACCESS, "lets",
208 "[\"vamoose\"]", "http://www.google.com/", "Google", "");
209 CheckAction(*actions->at(2), "punky", Action::ACTION_DOM_ACCESS, "lets",
210 "[\"vamoose\"]", "", "", "");
211 CheckAction(*actions->at(3), "punky", Action::ACTION_DOM_ACCESS, "lets",
212 "[\"vamoose\"]", "", "", "http://www.google.com/");
213 CheckAction(*actions->at(4), "punky", Action::ACTION_DOM_ACCESS, "lets",
214 "[\"vamoose\"]", "", "", "");
215 }
216
217 static void CheckAction(const Action& action,
218 const std::string& expected_id,
219 const Action::ActionType& expected_type,
220 const std::string& expected_api_name,
221 const std::string& expected_args_str,
222 const std::string& expected_page_url,
223 const std::string& expected_page_title,
224 const std::string& expected_arg_url) {
225 ASSERT_EQ(expected_id, action.extension_id());
226 ASSERT_EQ(expected_type, action.action_type());
227 ASSERT_EQ(expected_api_name, action.api_name());
228 ASSERT_EQ(expected_args_str,
229 ActivityLogPolicy::Util::Serialize(action.args()));
230 ASSERT_EQ(expected_page_url, action.SerializePageUrl());
231 ASSERT_EQ(expected_page_title, action.page_title());
232 ASSERT_EQ(expected_arg_url, action.SerializeArgUrl());
233 }
234
193 protected: 235 protected:
194 ExtensionService* extension_service_; 236 ExtensionService* extension_service_;
195 scoped_ptr<TestingProfile> profile_; 237 scoped_ptr<TestingProfile> profile_;
196 content::TestBrowserThreadBundle thread_bundle_; 238 content::TestBrowserThreadBundle thread_bundle_;
197 // Used to preserve a copy of the original command line. 239 // Used to preserve a copy of the original command line.
198 // The test framework will do this itself as well. However, by then, 240 // The test framework will do this itself as well. However, by then,
199 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in 241 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in
200 // TearDown(). 242 // TearDown().
201 CommandLine saved_cmdline_; 243 CommandLine saved_cmdline_;
202 244
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 policy->ProcessAction(action); 518 policy->ProcessAction(action);
477 519
478 CheckReadData( 520 CheckReadData(
479 policy, 521 policy,
480 "punky", 522 "punky",
481 3, 523 3,
482 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions)); 524 base::Bind(&FullStreamUIPolicyTest::Arguments_GetOlderActions));
483 policy->Close(); 525 policy->Close();
484 } 526 }
485 527
528 TEST_F(FullStreamUIPolicyTest, RemoveAllURLs) {
529 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
530
531 // Use a mock clock to ensure that events are not recorded on the wrong day
532 // when the test is run close to local midnight.
533 base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
534 mock_clock->SetNow(base::Time::Now().LocalMidnight() +
535 base::TimeDelta::FromHours(12));
536 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
537
538 // Record some actions
539 scoped_refptr<Action> action =
540 new Action("punky", mock_clock->Now(),
541 Action::ACTION_DOM_ACCESS, "lets");
542 action->mutable_args()->AppendString("vamoose");
543 action->set_page_url(GURL("http://www.google.com"));
544 action->set_page_title("Google");
545 action->set_arg_url(GURL("http://www.google.com"));
546 policy->ProcessAction(action);
547
548 mock_clock->Advance(base::TimeDelta::FromSeconds(1));
549 action = new Action(
550 "punky", mock_clock->Now(), Action::ACTION_API_CALL, "lets");
551 action->mutable_args()->AppendString("vamoose");
552 action->set_page_url(GURL("http://www.google2.com"));
553 action->set_page_title("Google");
554 // Deliberately no arg url set to make sure it still works when there is no
555 // arg url.
556 policy->ProcessAction(action);
557
558 // Clean all the URLs.
559 std::vector<GURL> no_url_restrictions;
560 policy->RemoveURLs(no_url_restrictions);
561
562 CheckReadData(
563 policy,
564 "punky",
565 0,
566 base::Bind(&FullStreamUIPolicyTest::AllURLsRemoved));
567 policy->Close();
568 }
569
570 TEST_F(FullStreamUIPolicyTest, RemoveSpecificURLs) {
571 ActivityLogPolicy* policy = new FullStreamUIPolicy(profile_.get());
572
573 // Use a mock clock to ensure that events are not recorded on the wrong day
574 // when the test is run close to local midnight.
575 base::SimpleTestClock* mock_clock = new base::SimpleTestClock();
576 mock_clock->SetNow(base::Time::Now().LocalMidnight() +
577 base::TimeDelta::FromHours(12));
578 policy->SetClockForTesting(scoped_ptr<base::Clock>(mock_clock));
579
580 // Record some actions
581 // This should have the page url and args url cleared.
582 scoped_refptr<Action> action = new Action("punky", mock_clock->Now(),
583 Action::ACTION_DOM_ACCESS, "lets");
584 action->mutable_args()->AppendString("vamoose");
585 action->set_page_url(GURL("http://www.google1.com"));
586 action->set_page_title("Google");
587 action->set_arg_url(GURL("http://www.google1.com"));
588 policy->ProcessAction(action);
589
590 // This should have the page url cleared but not args url.
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.google1.com"));
596 action->set_page_title("Google");
597 action->set_arg_url(GURL("http://www.google.com"));
598 policy->ProcessAction(action);
599
600 // This should have the page url cleared. The args url is deliberately not set
601 // to make sure this doesn't cause any issues.
602 mock_clock->Advance(base::TimeDelta::FromSeconds(1));
603 action = new Action(
604 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
605 action->mutable_args()->AppendString("vamoose");
606 action->set_page_url(GURL("http://www.google2.com"));
607 action->set_page_title("Google");
608 policy->ProcessAction(action);
609
610 // This should have the args url cleared but not the page url or page title.
611 mock_clock->Advance(base::TimeDelta::FromSeconds(1));
612 action = new Action(
613 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
614 action->mutable_args()->AppendString("vamoose");
615 action->set_page_url(GURL("http://www.google.com"));
616 action->set_page_title("Google");
617 action->set_arg_url(GURL("http://www.google1.com"));
618 policy->ProcessAction(action);
619
620 // This should have neither cleared.
621 mock_clock->Advance(base::TimeDelta::FromSeconds(1));
622 action = new Action(
623 "punky", mock_clock->Now(), Action::ACTION_DOM_ACCESS, "lets");
624 action->mutable_args()->AppendString("vamoose");
625 action->set_page_url(GURL("http://www.google.com"));
626 action->set_page_title("Google");
627 action->set_arg_url(GURL("http://www.args-url.com"));
628 policy->ProcessAction(action);
629
630 // Clean some URLs.
631 std::vector<GURL> urls;
632 urls.push_back(GURL("http://www.google1.com"));
633 urls.push_back(GURL("http://www.google2.com"));
634 urls.push_back(GURL("http://www.url_not_in_db.com"));
635 policy->RemoveURLs(urls);
636
637 CheckReadData(
638 policy,
639 "punky",
640 0,
641 base::Bind(&FullStreamUIPolicyTest::SomeURLsRemoved));
642 policy->Close();
643 }
644
486 } // namespace extensions 645 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log/fullstream_ui_policy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698