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

Side by Side Diff: chrome/browser/visitedlink_unittest.cc

Issue 342068: Third patch in getting rid of caching MessageLoop pointers and always using C... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <vector> 5 #include <vector>
6 #include <string> 6 #include <string>
7 #include <cstdio> 7 #include <cstdio>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/process_util.h" 12 #include "base/process_util.h"
13 #include "base/shared_memory.h" 13 #include "base/shared_memory.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "chrome/browser/chrome_thread.h"
15 #include "chrome/browser/visitedlink_master.h" 16 #include "chrome/browser/visitedlink_master.h"
16 #include "chrome/browser/visitedlink_event_listener.h" 17 #include "chrome/browser/visitedlink_event_listener.h"
17 #include "chrome/browser/renderer_host/browser_render_process_host.h" 18 #include "chrome/browser/renderer_host/browser_render_process_host.h"
18 #include "chrome/browser/renderer_host/test/test_render_view_host.h" 19 #include "chrome/browser/renderer_host/test/test_render_view_host.h"
19 #include "chrome/common/render_messages.h" 20 #include "chrome/common/render_messages.h"
20 #include "chrome/renderer/visitedlink_slave.h" 21 #include "chrome/renderer/visitedlink_slave.h"
21 #include "googleurl/src/gurl.h" 22 #include "googleurl/src/gurl.h"
22 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
23 24
24 namespace { 25 namespace {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 int reset_count() const { return reset_count_; } 65 int reset_count() const { return reset_count_; }
65 int add_count() const { return add_count_; } 66 int add_count() const { return add_count_; }
66 67
67 private: 68 private:
68 int reset_count_; 69 int reset_count_;
69 int add_count_; 70 int add_count_;
70 }; 71 };
71 72
72 class VisitedLinkTest : public testing::Test { 73 class VisitedLinkTest : public testing::Test {
73 protected: 74 protected:
75 VisitedLinkTest()
76 : ui_thread_(ChromeThread::UI, &message_loop_),
77 file_thread_(ChromeThread::FILE, &message_loop_) {}
74 // Initialize the history system. This should be called before InitVisited(). 78 // Initialize the history system. This should be called before InitVisited().
75 bool InitHistory() { 79 bool InitHistory() {
76 history_service_ = new HistoryService; 80 history_service_ = new HistoryService;
77 return history_service_->Init(history_dir_, NULL); 81 return history_service_->Init(history_dir_, NULL);
78 } 82 }
79 83
80 // Initializes the visited link objects. Pass in the size that you want a 84 // Initializes the visited link objects. Pass in the size that you want a
81 // freshly created table to be. 0 means use the default. 85 // freshly created table to be. 0 means use the default.
82 // 86 //
83 // |suppress_rebuild| is set when we're not testing rebuilding, see 87 // |suppress_rebuild| is set when we're not testing rebuilding, see
84 // the VisitedLinkMaster constructor. 88 // the VisitedLinkMaster constructor.
85 bool InitVisited(int initial_size, bool suppress_rebuild) { 89 bool InitVisited(int initial_size, bool suppress_rebuild) {
86 // Initialize the visited link system. 90 // Initialize the visited link system.
87 master_.reset(new VisitedLinkMaster(NULL, &listener_, history_service_, 91 master_.reset(new VisitedLinkMaster(&listener_, history_service_,
88 suppress_rebuild, visited_file_, 92 suppress_rebuild, visited_file_,
89 initial_size)); 93 initial_size));
90 return master_->Init(); 94 return master_->Init();
91 } 95 }
92 96
93 // May be called multiple times (some tests will do this to clear things, 97 // May be called multiple times (some tests will do this to clear things,
94 // and TearDown will do this to make sure eveything is shiny before quitting. 98 // and TearDown will do this to make sure eveything is shiny before quitting.
95 void ClearDB() { 99 void ClearDB() {
96 if (master_.get()) 100 if (master_.get())
97 master_.reset(NULL); 101 master_.reset(NULL);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 visited_file_ = history_dir_.Append(FILE_PATH_LITERAL("VisitedLinks")); 167 visited_file_ = history_dir_.Append(FILE_PATH_LITERAL("VisitedLinks"));
164 listener_.SetUp(); 168 listener_.SetUp();
165 } 169 }
166 170
167 virtual void TearDown() { 171 virtual void TearDown() {
168 ClearDB(); 172 ClearDB();
169 file_util::Delete(history_dir_, true); 173 file_util::Delete(history_dir_, true);
170 } 174 }
171 175
172 MessageLoop message_loop_; 176 MessageLoop message_loop_;
177 ChromeThread ui_thread_;
178 ChromeThread file_thread_;
173 179
174 // Filenames for the services; 180 // Filenames for the services;
175 FilePath history_dir_; 181 FilePath history_dir_;
176 FilePath visited_file_; 182 FilePath visited_file_;
177 183
178 scoped_ptr<VisitedLinkMaster> master_; 184 scoped_ptr<VisitedLinkMaster> master_;
179 scoped_refptr<HistoryService> history_service_; 185 scoped_refptr<HistoryService> history_service_;
180 TrackingVisitedLinkEventListener listener_; 186 TrackingVisitedLinkEventListener listener_;
181 }; 187 };
182 188
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 class VisitCountingProfile : public TestingProfile { 451 class VisitCountingProfile : public TestingProfile {
446 public: 452 public:
447 explicit VisitCountingProfile(VisitedLinkEventListener* event_listener) 453 explicit VisitCountingProfile(VisitedLinkEventListener* event_listener)
448 : add_count_(0), 454 : add_count_(0),
449 add_event_count_(0), 455 add_event_count_(0),
450 reset_event_count_(0), 456 reset_event_count_(0),
451 event_listener_(event_listener) {} 457 event_listener_(event_listener) {}
452 458
453 virtual VisitedLinkMaster* GetVisitedLinkMaster() { 459 virtual VisitedLinkMaster* GetVisitedLinkMaster() {
454 if (!visited_link_master_.get()) { 460 if (!visited_link_master_.get()) {
455 visited_link_master_.reset( 461 visited_link_master_.reset(new VisitedLinkMaster(event_listener_, this));
456 new VisitedLinkMaster(NULL, event_listener_, this));
457 visited_link_master_->Init(); 462 visited_link_master_->Init();
458 } 463 }
459 return visited_link_master_.get(); 464 return visited_link_master_.get();
460 } 465 }
461 466
462 void CountAddEvent(int by) { 467 void CountAddEvent(int by) {
463 add_count_ += by; 468 add_count_ += by;
464 add_event_count_++; 469 add_event_count_++;
465 } 470 }
466 471
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 void set_relay_mode(bool mode) { relay_mode_ = mode; } 568 void set_relay_mode(bool mode) { relay_mode_ = mode; }
564 569
565 private: 570 private:
566 bool relay_mode_; 571 bool relay_mode_;
567 572
568 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); 573 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory);
569 }; 574 };
570 575
571 class VisitedLinkEventsTest : public RenderViewHostTestHarness { 576 class VisitedLinkEventsTest : public RenderViewHostTestHarness {
572 public: 577 public:
573 VisitedLinkEventsTest() : RenderViewHostTestHarness() {} 578 VisitedLinkEventsTest()
579 : RenderViewHostTestHarness(),
580 file_thread_(ChromeThread::FILE, &message_loop_) {}
581 ~VisitedLinkEventsTest() {
582 // This ends up using the file thread to schedule the delete.
583 profile_.reset();
584 message_loop_.RunAllPending();
585 }
574 virtual void SetFactoryMode() {} 586 virtual void SetFactoryMode() {}
575 virtual void SetUp() { 587 virtual void SetUp() {
576 SetFactoryMode(); 588 SetFactoryMode();
577 event_listener_.reset(new VisitedLinkEventListener()); 589 event_listener_.reset(new VisitedLinkEventListener());
578 rvh_factory_.set_render_process_host_factory(&vc_rph_factory_); 590 rvh_factory_.set_render_process_host_factory(&vc_rph_factory_);
579 profile_.reset(new VisitCountingProfile(event_listener_.get())); 591 profile_.reset(new VisitCountingProfile(event_listener_.get()));
580 RenderViewHostTestHarness::SetUp(); 592 RenderViewHostTestHarness::SetUp();
581 } 593 }
582 594
583 VisitCountingProfile* profile() const { 595 VisitCountingProfile* profile() const {
584 return static_cast<VisitCountingProfile*>(profile_.get()); 596 return static_cast<VisitCountingProfile*>(profile_.get());
585 } 597 }
586 598
587 void WaitForCoalescense() { 599 void WaitForCoalescense() {
588 // Let the timer fire. 600 // Let the timer fire.
589 MessageLoop::current()->PostDelayedTask(FROM_HERE, 601 MessageLoop::current()->PostDelayedTask(FROM_HERE,
590 new MessageLoop::QuitTask(), 110); 602 new MessageLoop::QuitTask(), 110);
591 MessageLoop::current()->Run(); 603 MessageLoop::current()->Run();
592 } 604 }
593 605
594 protected: 606 protected:
595 VisitedLinkRenderProcessHostFactory vc_rph_factory_; 607 VisitedLinkRenderProcessHostFactory vc_rph_factory_;
596 608
597 private: 609 private:
598 scoped_ptr<VisitedLinkEventListener> event_listener_; 610 scoped_ptr<VisitedLinkEventListener> event_listener_;
611 ChromeThread file_thread_;
599 612
600 DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest); 613 DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest);
601 }; 614 };
602 615
603 class VisitedLinkRelayTest : public VisitedLinkEventsTest { 616 class VisitedLinkRelayTest : public VisitedLinkEventsTest {
604 public: 617 public:
605 virtual void SetFactoryMode() { vc_rph_factory_.set_relay_mode(true); } 618 virtual void SetFactoryMode() { vc_rph_factory_.set_relay_mode(true); }
606 }; 619 };
607 620
608 TEST_F(VisitedLinkEventsTest, Coalescense) { 621 TEST_F(VisitedLinkEventsTest, Coalescense) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 EXPECT_EQ(0, profile()->add_event_count()); 760 EXPECT_EQ(0, profile()->add_event_count());
748 EXPECT_EQ(0, profile()->reset_event_count()); 761 EXPECT_EQ(0, profile()->reset_event_count());
749 762
750 rvh()->CreateRenderView(); 763 rvh()->CreateRenderView();
751 764
752 // We should now have just a reset event: adds are eaten up by a reset 765 // We should now have just a reset event: adds are eaten up by a reset
753 // that followed. 766 // that followed.
754 EXPECT_EQ(0, profile()->add_event_count()); 767 EXPECT_EQ(0, profile()->add_event_count());
755 EXPECT_EQ(1, profile()->reset_event_count()); 768 EXPECT_EQ(1, profile()->reset_event_count());
756 } 769 }
OLDNEW
« no previous file with comments | « chrome/browser/visitedlink_perftest.cc ('k') | chrome/browser/web_resource/web_resource_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698