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

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

Issue 11573060: Remove VisitedLink dependency on rest of chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use delegate instead Created 8 years 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) 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/file_util.h" 9 #include "base/file_util.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.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 "base/time.h" 15 #include "base/time.h"
16 #include "chrome/browser/visitedlink/visitedlink_delegate.h"
16 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" 17 #include "chrome/browser/visitedlink/visitedlink_event_listener.h"
17 #include "chrome/browser/visitedlink/visitedlink_master.h" 18 #include "chrome/browser/visitedlink/visitedlink_master.h"
18 #include "chrome/browser/visitedlink/visitedlink_master_factory.h"
19 #include "chrome/common/render_messages.h" 19 #include "chrome/common/render_messages.h"
20 #include "chrome/renderer/visitedlink_slave.h" 20 #include "chrome/renderer/visitedlink_slave.h"
21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
25 #include "content/public/test/mock_render_process_host.h" 25 #include "content/public/test/mock_render_process_host.h"
26 #include "content/public/test/test_browser_thread.h" 26 #include "content/public/test/test_browser_thread.h"
27 #include "content/public/test/test_renderer_host.h" 27 #include "content/public/test/test_renderer_host.h"
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 #include "testing/gtest/include/gtest/gtest.h" 29 #include "testing/gtest/include/gtest/gtest.h"
30 30
31 using content::BrowserThread; 31 using content::BrowserThread;
32 using content::MockRenderProcessHost; 32 using content::MockRenderProcessHost;
33 using content::RenderViewHostTester; 33 using content::RenderViewHostTester;
34 34
35 namespace { 35 namespace {
36 36
37 // a nice long URL that we can append numbers to to get new URLs 37 // a nice long URL that we can append numbers to to get new URLs
38 const char g_test_prefix[] = 38 const char g_test_prefix[] =
39 "http://www.google.com/products/foo/index.html?id=45028640526508376&seq="; 39 "http://www.google.com/products/foo/index.html?id=45028640526508376&seq=";
40 const int g_test_count = 1000; 40 const int g_test_count = 1000;
41 41
42 // Returns a test URL for index |i| 42 // Returns a test URL for index |i|
43 GURL TestURL(int i) { 43 GURL TestURL(int i) {
44 return GURL(StringPrintf("%s%d", g_test_prefix, i)); 44 return GURL(StringPrintf("%s%d", g_test_prefix, i));
45 } 45 }
46 46
47 ProfileKeyedService* BuildVisitedLinkMaster(Profile* profile) {
48 VisitedLinkMaster* master = new VisitedLinkMaster(profile);
49 master->Init();
50 return master;
51 }
52
53 std::vector<VisitedLinkSlave*> g_slaves; 47 std::vector<VisitedLinkSlave*> g_slaves;
54 48
55 } // namespace 49 } // namespace
56 50
57 class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener { 51 class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener {
58 public: 52 public:
59 TrackingVisitedLinkEventListener() 53 TrackingVisitedLinkEventListener()
60 : reset_count_(0), 54 : reset_count_(0),
61 add_count_(0) {} 55 add_count_(0) {}
62 56
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 virtual content::RenderProcessHost* CreateRenderProcessHost( 546 virtual content::RenderProcessHost* CreateRenderProcessHost(
553 content::BrowserContext* browser_context) const OVERRIDE { 547 content::BrowserContext* browser_context) const OVERRIDE {
554 return new VisitRelayingRenderProcessHost(browser_context); 548 return new VisitRelayingRenderProcessHost(browser_context);
555 } 549 }
556 550
557 private: 551 private:
558 552
559 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); 553 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory);
560 }; 554 };
561 555
556 class TestVisitedLinkDelegate : public VisitedLinkDelegate {
557 public:
558 virtual bool IsEquivalentContext(content::BrowserContext* context1,
559 content::BrowserContext* context2) OVERRIDE;
560 virtual void RebuildTable(URLEnumerator* enumerator) OVERRIDE;
561 };
562
563 bool TestVisitedLinkDelegate::IsEquivalentContext(
564 content::BrowserContext* context1, content::BrowserContext* context2) {
565 DCHECK_EQ(context1, context2);
566 return true; // Test only has one profile.
567 }
568
569 void TestVisitedLinkDelegate::RebuildTable(URLEnumerator* enumerator) {
570 enumerator->OnComplete(true);
571 }
572
562 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness { 573 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness {
563 public: 574 public:
564 VisitedLinkEventsTest() 575 VisitedLinkEventsTest()
565 : ui_thread_(BrowserThread::UI, &message_loop_), 576 : ui_thread_(BrowserThread::UI, &message_loop_),
566 file_thread_(BrowserThread::FILE, &message_loop_) {} 577 file_thread_(BrowserThread::FILE, &message_loop_) {}
567 virtual ~VisitedLinkEventsTest() {} 578 virtual ~VisitedLinkEventsTest() {}
568 virtual void SetUp() { 579 virtual void SetUp() {
569 browser_context_.reset(new VisitCountingProfile()); 580 browser_context_.reset(new VisitCountingProfile());
570 profile()->CreateHistoryService(true, false); 581 profile()->CreateHistoryService(true, false);
571 master_ = static_cast<VisitedLinkMaster*>( 582 master_.reset(new VisitedLinkMaster(profile(), &delegate_));
572 VisitedLinkMasterFactory::GetInstance()-> 583 master_->Init();
573 SetTestingFactoryAndUse(profile(), BuildVisitedLinkMaster));
574 SetRenderProcessHostFactory(&vc_rph_factory_); 584 SetRenderProcessHostFactory(&vc_rph_factory_);
575 ChromeRenderViewHostTestHarness::SetUp(); 585 ChromeRenderViewHostTestHarness::SetUp();
576 } 586 }
577 587
578 VisitCountingProfile* profile() const { 588 VisitCountingProfile* profile() const {
579 return static_cast<VisitCountingProfile*>(browser_context_.get()); 589 return static_cast<VisitCountingProfile*>(browser_context_.get());
580 } 590 }
581 591
582 VisitedLinkMaster* master() const { 592 VisitedLinkMaster* master() const {
583 return master_; 593 return master_.get();
584 } 594 }
585 595
586 void WaitForCoalescense() { 596 void WaitForCoalescense() {
587 // Let the timer fire. 597 // Let the timer fire.
588 MessageLoop::current()->PostDelayedTask( 598 MessageLoop::current()->PostDelayedTask(
589 FROM_HERE, 599 FROM_HERE,
590 MessageLoop::QuitClosure(), 600 MessageLoop::QuitClosure(),
591 base::TimeDelta::FromMilliseconds(110)); 601 base::TimeDelta::FromMilliseconds(110));
592 MessageLoop::current()->Run(); 602 MessageLoop::current()->Run();
593 } 603 }
594 604
595 protected: 605 protected:
596 VisitedLinkRenderProcessHostFactory vc_rph_factory_; 606 VisitedLinkRenderProcessHostFactory vc_rph_factory_;
597 607
598 private: 608 private:
599 VisitedLinkMaster* master_; 609 TestVisitedLinkDelegate delegate_;
610 scoped_ptr<VisitedLinkMaster> master_;
600 content::TestBrowserThread ui_thread_; 611 content::TestBrowserThread ui_thread_;
601 content::TestBrowserThread file_thread_; 612 content::TestBrowserThread file_thread_;
602 613
603 DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest); 614 DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest);
604 }; 615 };
605 616
606 TEST_F(VisitedLinkEventsTest, Coalescense) { 617 TEST_F(VisitedLinkEventsTest, Coalescense) {
607 // add some URLs to master. 618 // add some URLs to master.
608 // Add a few URLs. 619 // Add a few URLs.
609 master()->AddURL(GURL("http://acidtests.org/")); 620 master()->AddURL(GURL("http://acidtests.org/"));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 EXPECT_EQ(1, profile()->add_event_count()); 730 EXPECT_EQ(1, profile()->add_event_count());
720 EXPECT_EQ(0, profile()->reset_event_count()); 731 EXPECT_EQ(0, profile()->reset_event_count());
721 732
722 // Activate the tab. 733 // Activate the tab.
723 rvh_tester()->SimulateWasShown(); 734 rvh_tester()->SimulateWasShown();
724 735
725 // We should have only one more reset event. 736 // We should have only one more reset event.
726 EXPECT_EQ(1, profile()->add_event_count()); 737 EXPECT_EQ(1, profile()->add_event_count());
727 EXPECT_EQ(1, profile()->reset_event_count()); 738 EXPECT_EQ(1, profile()->reset_event_count());
728 } 739 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698