OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/visitedlink/visitedlink_master.h" | 15 #include "chrome/browser/visitedlink/visitedlink_master.h" |
16 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" | 16 #include "chrome/browser/visitedlink/visitedlink_event_listener.h" |
17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
18 #include "chrome/renderer/visitedlink_slave.h" | 18 #include "chrome/renderer/visitedlink_slave.h" |
19 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
19 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
20 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
21 #include "content/browser/renderer_host/browser_render_process_host.h" | 22 #include "content/browser/renderer_host/browser_render_process_host.h" |
22 #include "content/browser/renderer_host/test_render_view_host.h" | |
23 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // a nice long URL that we can append numbers to to get new URLs | 29 // a nice long URL that we can append numbers to to get new URLs |
30 const char g_test_prefix[] = | 30 const char g_test_prefix[] = |
31 "http://www.google.com/products/foo/index.html?id=45028640526508376&seq="; | 31 "http://www.google.com/products/foo/index.html?id=45028640526508376&seq="; |
32 const int g_test_count = 1000; | 32 const int g_test_count = 1000; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 virtual RenderProcessHost* CreateRenderProcessHost( | 556 virtual RenderProcessHost* CreateRenderProcessHost( |
557 content::BrowserContext* browser_context) const OVERRIDE { | 557 content::BrowserContext* browser_context) const OVERRIDE { |
558 return new VisitRelayingRenderProcessHost(browser_context); | 558 return new VisitRelayingRenderProcessHost(browser_context); |
559 } | 559 } |
560 | 560 |
561 private: | 561 private: |
562 | 562 |
563 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); | 563 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); |
564 }; | 564 }; |
565 | 565 |
566 class VisitedLinkEventsTest : public RenderViewHostTestHarness { | 566 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness { |
567 public: | 567 public: |
568 VisitedLinkEventsTest() | 568 VisitedLinkEventsTest() |
569 : RenderViewHostTestHarness(), | 569 : ChromeRenderViewHostTestHarness(), |
Paweł Hajdan Jr.
2011/09/13 19:16:36
nit: Needed?
| |
570 ui_thread_(BrowserThread::UI, &message_loop_), | 570 ui_thread_(BrowserThread::UI, &message_loop_), |
571 file_thread_(BrowserThread::FILE, &message_loop_) {} | 571 file_thread_(BrowserThread::FILE, &message_loop_) {} |
572 ~VisitedLinkEventsTest() { | 572 virtual ~VisitedLinkEventsTest() {} |
573 // This ends up using the file thread to schedule the delete. | |
574 profile_.reset(); | |
575 message_loop_.RunAllPending(); | |
576 } | |
577 virtual void SetFactoryMode() {} | 573 virtual void SetFactoryMode() {} |
578 virtual void SetUp() { | 574 virtual void SetUp() { |
579 SetFactoryMode(); | 575 SetFactoryMode(); |
580 event_listener_.reset(new VisitedLinkEventListener()); | 576 event_listener_.reset(new VisitedLinkEventListener()); |
581 rvh_factory_.set_render_process_host_factory(&vc_rph_factory_); | 577 rvh_factory_.set_render_process_host_factory(&vc_rph_factory_); |
582 profile_.reset(new VisitCountingProfile(event_listener_.get())); | 578 browser_context_.reset(new VisitCountingProfile(event_listener_.get())); |
583 RenderViewHostTestHarness::SetUp(); | 579 ChromeRenderViewHostTestHarness::SetUp(); |
584 } | 580 } |
585 | 581 |
586 VisitCountingProfile* profile() const { | 582 VisitCountingProfile* profile() const { |
587 return static_cast<VisitCountingProfile*>(profile_.get()); | 583 return static_cast<VisitCountingProfile*>(browser_context_.get()); |
588 } | 584 } |
589 | 585 |
590 void WaitForCoalescense() { | 586 void WaitForCoalescense() { |
591 // Let the timer fire. | 587 // Let the timer fire. |
592 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 588 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
593 new MessageLoop::QuitTask(), 110); | 589 new MessageLoop::QuitTask(), 110); |
594 MessageLoop::current()->Run(); | 590 MessageLoop::current()->Run(); |
595 } | 591 } |
596 | 592 |
597 protected: | 593 protected: |
598 VisitedLinkRenderProcessHostFactory vc_rph_factory_; | 594 VisitedLinkRenderProcessHostFactory vc_rph_factory_; |
599 | 595 |
600 private: | 596 private: |
601 scoped_ptr<VisitedLinkEventListener> event_listener_; | 597 scoped_ptr<VisitedLinkEventListener> event_listener_; |
602 BrowserThread ui_thread_; | 598 BrowserThread ui_thread_; |
603 BrowserThread file_thread_; | 599 BrowserThread file_thread_; |
604 | 600 |
605 DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest); | 601 DISALLOW_COPY_AND_ASSIGN(VisitedLinkEventsTest); |
606 }; | 602 }; |
607 | 603 |
608 TEST_F(VisitedLinkEventsTest, Coalescense) { | 604 TEST_F(VisitedLinkEventsTest, Coalescense) { |
609 // add some URLs to master. | 605 // add some URLs to master. |
610 VisitedLinkMaster* master = profile_->GetVisitedLinkMaster(); | 606 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster(); |
611 // Add a few URLs. | 607 // Add a few URLs. |
612 master->AddURL(GURL("http://acidtests.org/")); | 608 master->AddURL(GURL("http://acidtests.org/")); |
613 master->AddURL(GURL("http://google.com/")); | 609 master->AddURL(GURL("http://google.com/")); |
614 master->AddURL(GURL("http://chromium.org/")); | 610 master->AddURL(GURL("http://chromium.org/")); |
615 // Just for kicks, add a duplicate URL. This shouldn't increase the resulting | 611 // Just for kicks, add a duplicate URL. This shouldn't increase the resulting |
616 master->AddURL(GURL("http://acidtests.org/")); | 612 master->AddURL(GURL("http://acidtests.org/")); |
617 | 613 |
618 // Make sure that coalescing actually occurs. There should be no links or | 614 // Make sure that coalescing actually occurs. There should be no links or |
619 // events received by the renderer. | 615 // events received by the renderer. |
620 EXPECT_EQ(0, profile()->add_count()); | 616 EXPECT_EQ(0, profile()->add_count()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 | 648 |
653 WaitForCoalescense(); | 649 WaitForCoalescense(); |
654 | 650 |
655 // We should have no change in results except for one new reset event. | 651 // We should have no change in results except for one new reset event. |
656 EXPECT_EQ(6, profile()->add_count()); | 652 EXPECT_EQ(6, profile()->add_count()); |
657 EXPECT_EQ(2, profile()->add_event_count()); | 653 EXPECT_EQ(2, profile()->add_event_count()); |
658 EXPECT_EQ(1, profile()->reset_event_count()); | 654 EXPECT_EQ(1, profile()->reset_event_count()); |
659 } | 655 } |
660 | 656 |
661 TEST_F(VisitedLinkEventsTest, Basics) { | 657 TEST_F(VisitedLinkEventsTest, Basics) { |
662 VisitedLinkMaster* master = profile_->GetVisitedLinkMaster(); | 658 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster(); |
663 rvh()->CreateRenderView(string16()); | 659 rvh()->CreateRenderView(string16()); |
664 | 660 |
665 // Add a few URLs. | 661 // Add a few URLs. |
666 master->AddURL(GURL("http://acidtests.org/")); | 662 master->AddURL(GURL("http://acidtests.org/")); |
667 master->AddURL(GURL("http://google.com/")); | 663 master->AddURL(GURL("http://google.com/")); |
668 master->AddURL(GURL("http://chromium.org/")); | 664 master->AddURL(GURL("http://chromium.org/")); |
669 | 665 |
670 WaitForCoalescense(); | 666 WaitForCoalescense(); |
671 | 667 |
672 // We now should have 1 add event. | 668 // We now should have 1 add event. |
673 EXPECT_EQ(1, profile()->add_event_count()); | 669 EXPECT_EQ(1, profile()->add_event_count()); |
674 EXPECT_EQ(0, profile()->reset_event_count()); | 670 EXPECT_EQ(0, profile()->reset_event_count()); |
675 | 671 |
676 master->DeleteAllURLs(); | 672 master->DeleteAllURLs(); |
677 | 673 |
678 WaitForCoalescense(); | 674 WaitForCoalescense(); |
679 | 675 |
680 // We should have no change in add results, plus one new reset event. | 676 // We should have no change in add results, plus one new reset event. |
681 EXPECT_EQ(1, profile()->add_event_count()); | 677 EXPECT_EQ(1, profile()->add_event_count()); |
682 EXPECT_EQ(1, profile()->reset_event_count()); | 678 EXPECT_EQ(1, profile()->reset_event_count()); |
683 } | 679 } |
684 | 680 |
685 TEST_F(VisitedLinkEventsTest, TabVisibility) { | 681 TEST_F(VisitedLinkEventsTest, TabVisibility) { |
686 VisitedLinkMaster* master = profile_->GetVisitedLinkMaster(); | 682 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster(); |
687 rvh()->CreateRenderView(string16()); | 683 rvh()->CreateRenderView(string16()); |
688 | 684 |
689 // Simulate tab becoming inactive. | 685 // Simulate tab becoming inactive. |
690 rvh()->WasHidden(); | 686 rvh()->WasHidden(); |
691 | 687 |
692 // Add a few URLs. | 688 // Add a few URLs. |
693 master->AddURL(GURL("http://acidtests.org/")); | 689 master->AddURL(GURL("http://acidtests.org/")); |
694 master->AddURL(GURL("http://google.com/")); | 690 master->AddURL(GURL("http://google.com/")); |
695 master->AddURL(GURL("http://chromium.org/")); | 691 master->AddURL(GURL("http://chromium.org/")); |
696 | 692 |
(...skipping 23 matching lines...) Expand all Loading... | |
720 EXPECT_EQ(1, profile()->add_event_count()); | 716 EXPECT_EQ(1, profile()->add_event_count()); |
721 EXPECT_EQ(0, profile()->reset_event_count()); | 717 EXPECT_EQ(0, profile()->reset_event_count()); |
722 | 718 |
723 // Activate the tab. | 719 // Activate the tab. |
724 rvh()->WasRestored(); | 720 rvh()->WasRestored(); |
725 | 721 |
726 // We should have only one more reset event. | 722 // We should have only one more reset event. |
727 EXPECT_EQ(1, profile()->add_event_count()); | 723 EXPECT_EQ(1, profile()->add_event_count()); |
728 EXPECT_EQ(1, profile()->reset_event_count()); | 724 EXPECT_EQ(1, profile()->reset_event_count()); |
729 } | 725 } |
OLD | NEW |