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

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

Issue 9645003: Introduce abstractions to allow embedders to test RenderViewHost (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to head. Created 8 years, 9 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
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 "chrome/browser/visitedlink/visitedlink_event_listener.h" 15 #include "chrome/browser/visitedlink/visitedlink_event_listener.h"
16 #include "chrome/browser/visitedlink/visitedlink_master.h" 16 #include "chrome/browser/visitedlink/visitedlink_master.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/chrome_render_view_host_test_harness.h"
20 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
21 #include "content/browser/renderer_host/mock_render_process_host.h" 21 #include "content/browser/renderer_host/mock_render_process_host.h"
22 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
24 #include "content/test/test_browser_thread.h" 24 #include "content/test/test_browser_thread.h"
25 #include "content/test/test_renderer_host.h"
25 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
26 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
27 28
28 using content::BrowserThread; 29 using content::BrowserThread;
30 using content::RenderViewHostTester;
29 31
30 namespace { 32 namespace {
31 33
32 // a nice long URL that we can append numbers to to get new URLs 34 // a nice long URL that we can append numbers to to get new URLs
33 const char g_test_prefix[] = 35 const char g_test_prefix[] =
34 "http://www.google.com/products/foo/index.html?id=45028640526508376&seq="; 36 "http://www.google.com/products/foo/index.html?id=45028640526508376&seq=";
35 const int g_test_count = 1000; 37 const int g_test_count = 1000;
36 38
37 // Returns a test URL for index |i| 39 // Returns a test URL for index |i|
38 GURL TestURL(int i) { 40 GURL TestURL(int i) {
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); 561 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory);
560 }; 562 };
561 563
562 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness { 564 class VisitedLinkEventsTest : public ChromeRenderViewHostTestHarness {
563 public: 565 public:
564 VisitedLinkEventsTest() 566 VisitedLinkEventsTest()
565 : ui_thread_(BrowserThread::UI, &message_loop_), 567 : ui_thread_(BrowserThread::UI, &message_loop_),
566 file_thread_(BrowserThread::FILE, &message_loop_) {} 568 file_thread_(BrowserThread::FILE, &message_loop_) {}
567 virtual ~VisitedLinkEventsTest() {} 569 virtual ~VisitedLinkEventsTest() {}
568 virtual void SetUp() { 570 virtual void SetUp() {
569 rvh_factory_.set_render_process_host_factory(&vc_rph_factory_); 571 SetRenderProcessHostFactory(&vc_rph_factory_);
570 browser_context_.reset(new VisitCountingProfile()); 572 browser_context_.reset(new VisitCountingProfile());
571 ChromeRenderViewHostTestHarness::SetUp(); 573 ChromeRenderViewHostTestHarness::SetUp();
572 } 574 }
573 575
574 VisitCountingProfile* profile() const { 576 VisitCountingProfile* profile() const {
575 return static_cast<VisitCountingProfile*>(browser_context_.get()); 577 return static_cast<VisitCountingProfile*>(browser_context_.get());
576 } 578 }
577 579
578 void WaitForCoalescense() { 580 void WaitForCoalescense() {
579 // Let the timer fire. 581 // Let the timer fire.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 WaitForCoalescense(); 644 WaitForCoalescense();
643 645
644 // We should have no change in results except for one new reset event. 646 // We should have no change in results except for one new reset event.
645 EXPECT_EQ(6, profile()->add_count()); 647 EXPECT_EQ(6, profile()->add_count());
646 EXPECT_EQ(2, profile()->add_event_count()); 648 EXPECT_EQ(2, profile()->add_event_count());
647 EXPECT_EQ(1, profile()->reset_event_count()); 649 EXPECT_EQ(1, profile()->reset_event_count());
648 } 650 }
649 651
650 TEST_F(VisitedLinkEventsTest, Basics) { 652 TEST_F(VisitedLinkEventsTest, Basics) {
651 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster(); 653 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster();
652 rvh()->CreateRenderView(string16(), -1); 654 rvh_tester()->CreateRenderView(string16(), -1);
653 655
654 // Add a few URLs. 656 // Add a few URLs.
655 master->AddURL(GURL("http://acidtests.org/")); 657 master->AddURL(GURL("http://acidtests.org/"));
656 master->AddURL(GURL("http://google.com/")); 658 master->AddURL(GURL("http://google.com/"));
657 master->AddURL(GURL("http://chromium.org/")); 659 master->AddURL(GURL("http://chromium.org/"));
658 660
659 WaitForCoalescense(); 661 WaitForCoalescense();
660 662
661 // We now should have 1 add event. 663 // We now should have 1 add event.
662 EXPECT_EQ(1, profile()->add_event_count()); 664 EXPECT_EQ(1, profile()->add_event_count());
663 EXPECT_EQ(0, profile()->reset_event_count()); 665 EXPECT_EQ(0, profile()->reset_event_count());
664 666
665 master->DeleteAllURLs(); 667 master->DeleteAllURLs();
666 668
667 WaitForCoalescense(); 669 WaitForCoalescense();
668 670
669 // We should have no change in add results, plus one new reset event. 671 // We should have no change in add results, plus one new reset event.
670 EXPECT_EQ(1, profile()->add_event_count()); 672 EXPECT_EQ(1, profile()->add_event_count());
671 EXPECT_EQ(1, profile()->reset_event_count()); 673 EXPECT_EQ(1, profile()->reset_event_count());
672 } 674 }
673 675
674 TEST_F(VisitedLinkEventsTest, TabVisibility) { 676 TEST_F(VisitedLinkEventsTest, TabVisibility) {
675 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster(); 677 VisitedLinkMaster* master = profile()->GetVisitedLinkMaster();
676 rvh()->CreateRenderView(string16(), -1); 678 rvh_tester()->CreateRenderView(string16(), -1);
677 679
678 // Simulate tab becoming inactive. 680 // Simulate tab becoming inactive.
679 rvh()->WasHidden(); 681 rvh_tester()->SimulateWasHidden();
680 682
681 // Add a few URLs. 683 // Add a few URLs.
682 master->AddURL(GURL("http://acidtests.org/")); 684 master->AddURL(GURL("http://acidtests.org/"));
683 master->AddURL(GURL("http://google.com/")); 685 master->AddURL(GURL("http://google.com/"));
684 master->AddURL(GURL("http://chromium.org/")); 686 master->AddURL(GURL("http://chromium.org/"));
685 687
686 WaitForCoalescense(); 688 WaitForCoalescense();
687 689
688 // We shouldn't have any events. 690 // We shouldn't have any events.
689 EXPECT_EQ(0, profile()->add_event_count()); 691 EXPECT_EQ(0, profile()->add_event_count());
690 EXPECT_EQ(0, profile()->reset_event_count()); 692 EXPECT_EQ(0, profile()->reset_event_count());
691 693
692 // Simulate the tab becoming active. 694 // Simulate the tab becoming active.
693 rvh()->WasRestored(); 695 rvh_tester()->SimulateWasRestored();
694 696
695 // We should now have 3 add events, still no reset events. 697 // We should now have 3 add events, still no reset events.
696 EXPECT_EQ(1, profile()->add_event_count()); 698 EXPECT_EQ(1, profile()->add_event_count());
697 EXPECT_EQ(0, profile()->reset_event_count()); 699 EXPECT_EQ(0, profile()->reset_event_count());
698 700
699 // Deactivate the tab again. 701 // Deactivate the tab again.
700 rvh()->WasHidden(); 702 rvh_tester()->SimulateWasHidden();
701 703
702 // Add a bunch of URLs (over 50) to exhaust the link event buffer. 704 // Add a bunch of URLs (over 50) to exhaust the link event buffer.
703 for (int i = 0; i < 100; i++) 705 for (int i = 0; i < 100; i++)
704 master->AddURL(TestURL(i)); 706 master->AddURL(TestURL(i));
705 707
706 WaitForCoalescense(); 708 WaitForCoalescense();
707 709
708 // Again, no change in events until tab is active. 710 // Again, no change in events until tab is active.
709 EXPECT_EQ(1, profile()->add_event_count()); 711 EXPECT_EQ(1, profile()->add_event_count());
710 EXPECT_EQ(0, profile()->reset_event_count()); 712 EXPECT_EQ(0, profile()->reset_event_count());
711 713
712 // Activate the tab. 714 // Activate the tab.
713 rvh()->WasRestored(); 715 rvh_tester()->SimulateWasRestored();
714 716
715 // We should have only one more reset event. 717 // We should have only one more reset event.
716 EXPECT_EQ(1, profile()->add_event_count()); 718 EXPECT_EQ(1, profile()->add_event_count());
717 EXPECT_EQ(1, profile()->reset_event_count()); 719 EXPECT_EQ(1, profile()->reset_event_count());
718 } 720 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/web_ui_unittest.cc ('k') | chrome/browser/web_applications/web_app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698