OLD | NEW |
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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <cstdio> | 8 #include <cstdio> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/time/time.h" | 23 #include "base/time/time.h" |
24 #include "base/timer/mock_timer.h" | 24 #include "base/timer/mock_timer.h" |
25 #include "components/visitedlink/browser/visitedlink_delegate.h" | 25 #include "components/visitedlink/browser/visitedlink_delegate.h" |
26 #include "components/visitedlink/browser/visitedlink_event_listener.h" | 26 #include "components/visitedlink/browser/visitedlink_event_listener.h" |
27 #include "components/visitedlink/browser/visitedlink_master.h" | 27 #include "components/visitedlink/browser/visitedlink_master.h" |
28 #include "components/visitedlink/common/visitedlink.mojom.h" | 28 #include "components/visitedlink/common/visitedlink.mojom.h" |
29 #include "components/visitedlink/renderer/visitedlink_slave.h" | 29 #include "components/visitedlink/renderer/visitedlink_slave.h" |
30 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
31 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
32 #include "content/public/browser/notification_types.h" | 32 #include "content/public/browser/notification_types.h" |
| 33 #include "content/public/browser/render_widget_host_view.h" |
| 34 #include "content/public/browser/web_contents.h" |
33 #include "content/public/test/mock_render_process_host.h" | 35 #include "content/public/test/mock_render_process_host.h" |
34 #include "content/public/test/test_browser_context.h" | 36 #include "content/public/test/test_browser_context.h" |
35 #include "content/public/test/test_browser_thread_bundle.h" | 37 #include "content/public/test/test_browser_thread_bundle.h" |
36 #include "content/public/test/test_renderer_host.h" | 38 #include "content/public/test/test_renderer_host.h" |
37 #include "content/public/test/test_utils.h" | 39 #include "content/public/test/test_utils.h" |
38 #include "services/service_manager/public/cpp/interface_provider.h" | 40 #include "services/service_manager/public/cpp/interface_provider.h" |
39 #include "testing/gtest/include/gtest/gtest.h" | 41 #include "testing/gtest/include/gtest/gtest.h" |
40 #include "url/gurl.h" | 42 #include "url/gurl.h" |
41 | 43 |
42 using content::BrowserThread; | 44 using content::BrowserThread; |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 RenderViewHostTester::For(rvh())->CreateTestRenderView( | 782 RenderViewHostTester::For(rvh())->CreateTestRenderView( |
781 base::string16(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); | 783 base::string16(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); |
782 | 784 |
783 // Waiting complete rebuild the table. | 785 // Waiting complete rebuild the table. |
784 content::RunAllBlockingPoolTasksUntilIdle(); | 786 content::RunAllBlockingPoolTasksUntilIdle(); |
785 | 787 |
786 // After rebuild table expect reset event. | 788 // After rebuild table expect reset event. |
787 EXPECT_EQ(1, context()->reset_event_count()); | 789 EXPECT_EQ(1, context()->reset_event_count()); |
788 | 790 |
789 // Simulate tab becoming inactive. | 791 // Simulate tab becoming inactive. |
790 RenderViewHostTester::For(rvh())->SimulateWasHidden(); | 792 web_contents()->GetRenderWidgetHostView()->Hide(); |
791 | 793 |
792 // Add a few URLs. | 794 // Add a few URLs. |
793 master()->AddURL(GURL("http://acidtests.org/")); | 795 master()->AddURL(GURL("http://acidtests.org/")); |
794 master()->AddURL(GURL("http://google.com/")); | 796 master()->AddURL(GURL("http://google.com/")); |
795 master()->AddURL(GURL("http://chromium.org/")); | 797 master()->AddURL(GURL("http://chromium.org/")); |
796 ASSERT_TRUE(timer_->IsRunning()); | 798 ASSERT_TRUE(timer_->IsRunning()); |
797 timer_->Fire(); | 799 timer_->Fire(); |
798 context()->WaitForNoUpdate(); | 800 context()->WaitForNoUpdate(); |
799 | 801 |
800 // We shouldn't have any events. | 802 // We shouldn't have any events. |
801 EXPECT_EQ(0, context()->add_event_count()); | 803 EXPECT_EQ(0, context()->add_event_count()); |
802 EXPECT_EQ(1, context()->reset_event_count()); | 804 EXPECT_EQ(1, context()->reset_event_count()); |
803 | 805 |
804 // Simulate the tab becoming active. | 806 // Simulate the tab becoming active. |
805 RenderViewHostTester::For(rvh())->SimulateWasShown(); | 807 web_contents()->GetRenderWidgetHostView()->Show(); |
806 context()->WaitForUpdate(); | 808 context()->WaitForUpdate(); |
807 | 809 |
808 // We should now have 3 add events, still no reset events. | 810 // We should now have 3 add events, still no reset events. |
809 EXPECT_EQ(1, context()->add_event_count()); | 811 EXPECT_EQ(1, context()->add_event_count()); |
810 EXPECT_EQ(1, context()->reset_event_count()); | 812 EXPECT_EQ(1, context()->reset_event_count()); |
811 | 813 |
812 // Deactivate the tab again. | 814 // Deactivate the tab again. |
813 RenderViewHostTester::For(rvh())->SimulateWasHidden(); | 815 web_contents()->GetRenderWidgetHostView()->Hide(); |
814 | 816 |
815 // Add a bunch of URLs (over 50) to exhaust the link event buffer. | 817 // Add a bunch of URLs (over 50) to exhaust the link event buffer. |
816 for (int i = 0; i < 100; i++) | 818 for (int i = 0; i < 100; i++) |
817 master()->AddURL(TestURL(i)); | 819 master()->AddURL(TestURL(i)); |
818 | 820 |
819 ASSERT_TRUE(timer_->IsRunning()); | 821 ASSERT_TRUE(timer_->IsRunning()); |
820 timer_->Fire(); | 822 timer_->Fire(); |
821 context()->WaitForNoUpdate(); | 823 context()->WaitForNoUpdate(); |
822 | 824 |
823 // Again, no change in events until tab is active. | 825 // Again, no change in events until tab is active. |
824 EXPECT_EQ(1, context()->add_event_count()); | 826 EXPECT_EQ(1, context()->add_event_count()); |
825 EXPECT_EQ(1, context()->reset_event_count()); | 827 EXPECT_EQ(1, context()->reset_event_count()); |
826 | 828 |
827 // Activate the tab. | 829 // Activate the tab. |
828 RenderViewHostTester::For(rvh())->SimulateWasShown(); | 830 web_contents()->GetRenderWidgetHostView()->Show(); |
829 EXPECT_FALSE(timer_->IsRunning()); | 831 EXPECT_FALSE(timer_->IsRunning()); |
830 context()->WaitForUpdate(); | 832 context()->WaitForUpdate(); |
831 | 833 |
832 // We should have only one more reset event. | 834 // We should have only one more reset event. |
833 EXPECT_EQ(1, context()->add_event_count()); | 835 EXPECT_EQ(1, context()->add_event_count()); |
834 EXPECT_EQ(2, context()->reset_event_count()); | 836 EXPECT_EQ(2, context()->reset_event_count()); |
835 } | 837 } |
836 | 838 |
837 // Tests that VisitedLink ignores renderer process creation notification for a | 839 // Tests that VisitedLink ignores renderer process creation notification for a |
838 // different context. | 840 // different context. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 // Waiting complete loading the table. | 880 // Waiting complete loading the table. |
879 content::RunAllBlockingPoolTasksUntilIdle(); | 881 content::RunAllBlockingPoolTasksUntilIdle(); |
880 | 882 |
881 context()->binding().FlushForTesting(); | 883 context()->binding().FlushForTesting(); |
882 | 884 |
883 // After load table expect completely reset event. | 885 // After load table expect completely reset event. |
884 EXPECT_EQ(1, context()->completely_reset_event_count()); | 886 EXPECT_EQ(1, context()->completely_reset_event_count()); |
885 } | 887 } |
886 | 888 |
887 } // namespace visitedlink | 889 } // namespace visitedlink |
OLD | NEW |