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

Side by Side Diff: components/visitedlink/test/visitedlink_unittest.cc

Issue 666133002: Standardize usage of virtual/override/final in components/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <cstdio> 5 #include <cstdio>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 // Returns a test URL for index |i| 48 // Returns a test URL for index |i|
49 GURL TestURL(int i) { 49 GURL TestURL(int i) {
50 return GURL(base::StringPrintf("%s%d", g_test_prefix, i)); 50 return GURL(base::StringPrintf("%s%d", g_test_prefix, i));
51 } 51 }
52 52
53 std::vector<VisitedLinkSlave*> g_slaves; 53 std::vector<VisitedLinkSlave*> g_slaves;
54 54
55 class TestVisitedLinkDelegate : public VisitedLinkDelegate { 55 class TestVisitedLinkDelegate : public VisitedLinkDelegate {
56 public: 56 public:
57 virtual void RebuildTable( 57 void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override;
58 const scoped_refptr<URLEnumerator>& enumerator) override;
59 58
60 void AddURLForRebuild(const GURL& url); 59 void AddURLForRebuild(const GURL& url);
61 60
62 private: 61 private:
63 URLs rebuild_urls_; 62 URLs rebuild_urls_;
64 }; 63 };
65 64
66 void TestVisitedLinkDelegate::RebuildTable( 65 void TestVisitedLinkDelegate::RebuildTable(
67 const scoped_refptr<URLEnumerator>& enumerator) { 66 const scoped_refptr<URLEnumerator>& enumerator) {
68 for (URLs::const_iterator itr = rebuild_urls_.begin(); 67 for (URLs::const_iterator itr = rebuild_urls_.begin();
69 itr != rebuild_urls_.end(); 68 itr != rebuild_urls_.end();
70 ++itr) 69 ++itr)
71 enumerator->OnURL(*itr); 70 enumerator->OnURL(*itr);
72 enumerator->OnComplete(true); 71 enumerator->OnComplete(true);
73 } 72 }
74 73
75 void TestVisitedLinkDelegate::AddURLForRebuild(const GURL& url) { 74 void TestVisitedLinkDelegate::AddURLForRebuild(const GURL& url) {
76 rebuild_urls_.push_back(url); 75 rebuild_urls_.push_back(url);
77 } 76 }
78 77
79 class TestURLIterator : public VisitedLinkMaster::URLIterator { 78 class TestURLIterator : public VisitedLinkMaster::URLIterator {
80 public: 79 public:
81 explicit TestURLIterator(const URLs& urls); 80 explicit TestURLIterator(const URLs& urls);
82 81
83 virtual const GURL& NextURL() override; 82 const GURL& NextURL() override;
84 virtual bool HasNextURL() const override; 83 bool HasNextURL() const override;
85 84
86 private: 85 private:
87 URLs::const_iterator iterator_; 86 URLs::const_iterator iterator_;
88 URLs::const_iterator end_; 87 URLs::const_iterator end_;
89 }; 88 };
90 89
91 TestURLIterator::TestURLIterator(const URLs& urls) 90 TestURLIterator::TestURLIterator(const URLs& urls)
92 : iterator_(urls.begin()), 91 : iterator_(urls.begin()),
93 end_(urls.end()) { 92 end_(urls.end()) {
94 } 93 }
95 94
96 const GURL& TestURLIterator::NextURL() { 95 const GURL& TestURLIterator::NextURL() {
97 return *(iterator_++); 96 return *(iterator_++);
98 } 97 }
99 98
100 bool TestURLIterator::HasNextURL() const { 99 bool TestURLIterator::HasNextURL() const {
101 return iterator_ != end_; 100 return iterator_ != end_;
102 } 101 }
103 102
104 } // namespace 103 } // namespace
105 104
106 class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener { 105 class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener {
107 public: 106 public:
108 TrackingVisitedLinkEventListener() 107 TrackingVisitedLinkEventListener()
109 : reset_count_(0), 108 : reset_count_(0),
110 add_count_(0) {} 109 add_count_(0) {}
111 110
112 virtual void NewTable(base::SharedMemory* table) override { 111 void NewTable(base::SharedMemory* table) override {
113 if (table) { 112 if (table) {
114 for (std::vector<VisitedLinkSlave>::size_type i = 0; 113 for (std::vector<VisitedLinkSlave>::size_type i = 0;
115 i < g_slaves.size(); i++) { 114 i < g_slaves.size(); i++) {
116 base::SharedMemoryHandle new_handle = base::SharedMemory::NULLHandle(); 115 base::SharedMemoryHandle new_handle = base::SharedMemory::NULLHandle();
117 table->ShareToProcess(base::GetCurrentProcessHandle(), &new_handle); 116 table->ShareToProcess(base::GetCurrentProcessHandle(), &new_handle);
118 g_slaves[i]->OnUpdateVisitedLinks(new_handle); 117 g_slaves[i]->OnUpdateVisitedLinks(new_handle);
119 } 118 }
120 } 119 }
121 } 120 }
122 virtual void Add(VisitedLinkCommon::Fingerprint) override { add_count_++; } 121 void Add(VisitedLinkCommon::Fingerprint) override { add_count_++; }
123 virtual void Reset() override { reset_count_++; } 122 void Reset() override { reset_count_++; }
124 123
125 void SetUp() { 124 void SetUp() {
126 reset_count_ = 0; 125 reset_count_ = 0;
127 add_count_ = 0; 126 add_count_ = 0;
128 } 127 }
129 128
130 int reset_count() const { return reset_count_; } 129 int reset_count() const { return reset_count_; }
131 int add_count() const { return add_count_; } 130 int add_count() const { return add_count_; }
132 131
133 private: 132 private:
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 class VisitRelayingRenderProcessHost : public MockRenderProcessHost { 528 class VisitRelayingRenderProcessHost : public MockRenderProcessHost {
530 public: 529 public:
531 explicit VisitRelayingRenderProcessHost( 530 explicit VisitRelayingRenderProcessHost(
532 content::BrowserContext* browser_context) 531 content::BrowserContext* browser_context)
533 : MockRenderProcessHost(browser_context), widgets_(0) { 532 : MockRenderProcessHost(browser_context), widgets_(0) {
534 content::NotificationService::current()->Notify( 533 content::NotificationService::current()->Notify(
535 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 534 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
536 content::Source<RenderProcessHost>(this), 535 content::Source<RenderProcessHost>(this),
537 content::NotificationService::NoDetails()); 536 content::NotificationService::NoDetails());
538 } 537 }
539 virtual ~VisitRelayingRenderProcessHost() { 538 ~VisitRelayingRenderProcessHost() override {
540 content::NotificationService::current()->Notify( 539 content::NotificationService::current()->Notify(
541 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, 540 content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
542 content::Source<content::RenderProcessHost>(this), 541 content::Source<content::RenderProcessHost>(this),
543 content::NotificationService::NoDetails()); 542 content::NotificationService::NoDetails());
544 } 543 }
545 544
546 virtual void WidgetRestored() override { widgets_++; } 545 void WidgetRestored() override { widgets_++; }
547 virtual void WidgetHidden() override { widgets_--; } 546 void WidgetHidden() override { widgets_--; }
548 virtual int VisibleWidgetCount() const override { return widgets_; } 547 int VisibleWidgetCount() const override { return widgets_; }
549 548
550 virtual bool Send(IPC::Message* msg) override { 549 bool Send(IPC::Message* msg) override {
551 VisitCountingContext* counting_context = 550 VisitCountingContext* counting_context =
552 static_cast<VisitCountingContext*>( 551 static_cast<VisitCountingContext*>(
553 GetBrowserContext()); 552 GetBrowserContext());
554 553
555 if (msg->type() == ChromeViewMsg_VisitedLink_Add::ID) { 554 if (msg->type() == ChromeViewMsg_VisitedLink_Add::ID) {
556 PickleIterator iter(*msg); 555 PickleIterator iter(*msg);
557 std::vector<uint64> fingerprints; 556 std::vector<uint64> fingerprints;
558 CHECK(IPC::ReadParam(msg, &iter, &fingerprints)); 557 CHECK(IPC::ReadParam(msg, &iter, &fingerprints));
559 counting_context->CountAddEvent(fingerprints.size()); 558 counting_context->CountAddEvent(fingerprints.size());
560 } else if (msg->type() == ChromeViewMsg_VisitedLink_Reset::ID) { 559 } else if (msg->type() == ChromeViewMsg_VisitedLink_Reset::ID) {
(...skipping 10 matching lines...) Expand all
571 int widgets_; 570 int widgets_;
572 571
573 DISALLOW_COPY_AND_ASSIGN(VisitRelayingRenderProcessHost); 572 DISALLOW_COPY_AND_ASSIGN(VisitRelayingRenderProcessHost);
574 }; 573 };
575 574
576 class VisitedLinkRenderProcessHostFactory 575 class VisitedLinkRenderProcessHostFactory
577 : public content::RenderProcessHostFactory { 576 : public content::RenderProcessHostFactory {
578 public: 577 public:
579 VisitedLinkRenderProcessHostFactory() 578 VisitedLinkRenderProcessHostFactory()
580 : content::RenderProcessHostFactory() {} 579 : content::RenderProcessHostFactory() {}
581 virtual content::RenderProcessHost* CreateRenderProcessHost( 580 content::RenderProcessHost* CreateRenderProcessHost(
582 content::BrowserContext* browser_context, 581 content::BrowserContext* browser_context,
583 content::SiteInstance* site_instance) const override { 582 content::SiteInstance* site_instance) const override {
584 return new VisitRelayingRenderProcessHost(browser_context); 583 return new VisitRelayingRenderProcessHost(browser_context);
585 } 584 }
586 585
587 private: 586 private:
588 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); 587 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory);
589 }; 588 };
590 589
591 class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { 590 class VisitedLinkEventsTest : public content::RenderViewHostTestHarness {
592 public: 591 public:
593 virtual void SetUp() { 592 virtual void SetUp() {
594 SetRenderProcessHostFactory(&vc_rph_factory_); 593 SetRenderProcessHostFactory(&vc_rph_factory_);
595 content::RenderViewHostTestHarness::SetUp(); 594 content::RenderViewHostTestHarness::SetUp();
596 } 595 }
597 596
598 virtual content::BrowserContext* CreateBrowserContext() override { 597 content::BrowserContext* CreateBrowserContext() override {
599 VisitCountingContext* context = new VisitCountingContext(); 598 VisitCountingContext* context = new VisitCountingContext();
600 master_.reset(new VisitedLinkMaster(context, &delegate_, true)); 599 master_.reset(new VisitedLinkMaster(context, &delegate_, true));
601 master_->Init(); 600 master_->Init();
602 return context; 601 return context;
603 } 602 }
604 603
605 VisitCountingContext* context() { 604 VisitCountingContext* context() {
606 return static_cast<VisitCountingContext*>(browser_context()); 605 return static_cast<VisitCountingContext*>(browser_context());
607 } 606 }
608 607
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 content::NotificationService::current()->Notify( 760 content::NotificationService::current()->Notify(
762 content::NOTIFICATION_RENDERER_PROCESS_CREATED, 761 content::NOTIFICATION_RENDERER_PROCESS_CREATED,
763 content::Source<content::RenderProcessHost>(&different_process_host), 762 content::Source<content::RenderProcessHost>(&different_process_host),
764 content::NotificationService::NoDetails()); 763 content::NotificationService::NoDetails());
765 WaitForCoalescense(); 764 WaitForCoalescense();
766 765
767 EXPECT_EQ(0, different_context.new_table_count()); 766 EXPECT_EQ(0, different_context.new_table_count());
768 } 767 }
769 768
770 } // namespace visitedlink 769 } // namespace visitedlink
OLDNEW
« no previous file with comments | « components/visitedlink/test/visitedlink_perftest.cc ('k') | components/web_cache/browser/web_cache_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698