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 <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/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "components/visitedlink/browser/visitedlink_delegate.h" | 17 #include "components/visitedlink/browser/visitedlink_delegate.h" |
18 #include "components/visitedlink/browser/visitedlink_event_listener.h" | 18 #include "components/visitedlink/browser/visitedlink_event_listener.h" |
19 #include "components/visitedlink/browser/visitedlink_master.h" | 19 #include "components/visitedlink/browser/visitedlink_master.h" |
20 #include "components/visitedlink/common/visitedlink_messages.h" | 20 #include "components/visitedlink/common/visitedlink_messages.h" |
21 #include "components/visitedlink/renderer/visitedlink_slave.h" | 21 #include "components/visitedlink/renderer/visitedlink_slave.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.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_context.h" | 26 #include "content/public/test/test_browser_context.h" |
27 #include "content/public/test/test_browser_thread_bundle.h" | 27 #include "content/public/test/test_browser_thread_bundle.h" |
28 #include "content/public/test/test_renderer_host.h" | 28 #include "content/public/test/test_renderer_host.h" |
| 29 #include "content/public/test/test_utils.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
30 #include "url/gurl.h" | 31 #include "url/gurl.h" |
31 | 32 |
32 using content::BrowserThread; | 33 using content::BrowserThread; |
33 using content::MockRenderProcessHost; | 34 using content::MockRenderProcessHost; |
34 using content::RenderViewHostTester; | 35 using content::RenderViewHostTester; |
35 | 36 |
36 namespace visitedlink { | 37 namespace visitedlink { |
37 | 38 |
38 namespace { | 39 namespace { |
(...skipping 13 matching lines...) Expand all Loading... |
52 std::vector<VisitedLinkSlave*> g_slaves; | 53 std::vector<VisitedLinkSlave*> g_slaves; |
53 | 54 |
54 class TestVisitedLinkDelegate : public VisitedLinkDelegate { | 55 class TestVisitedLinkDelegate : public VisitedLinkDelegate { |
55 public: | 56 public: |
56 virtual void RebuildTable( | 57 virtual void RebuildTable( |
57 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; | 58 const scoped_refptr<URLEnumerator>& enumerator) OVERRIDE; |
58 | 59 |
59 void AddURLForRebuild(const GURL& url); | 60 void AddURLForRebuild(const GURL& url); |
60 | 61 |
61 private: | 62 private: |
62 | |
63 URLs rebuild_urls_; | 63 URLs rebuild_urls_; |
64 }; | 64 }; |
65 | 65 |
66 void TestVisitedLinkDelegate::RebuildTable( | 66 void TestVisitedLinkDelegate::RebuildTable( |
67 const scoped_refptr<URLEnumerator>& enumerator) { | 67 const scoped_refptr<URLEnumerator>& enumerator) { |
68 for (URLs::const_iterator itr = rebuild_urls_.begin(); | 68 for (URLs::const_iterator itr = rebuild_urls_.begin(); |
69 itr != rebuild_urls_.end(); | 69 itr != rebuild_urls_.end(); |
70 ++itr) | 70 ++itr) |
71 enumerator->OnURL(*itr); | 71 enumerator->OnURL(*itr); |
72 enumerator->OnComplete(true); | 72 enumerator->OnComplete(true); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 return master_->Init(); | 152 return master_->Init(); |
153 } | 153 } |
154 | 154 |
155 // May be called multiple times (some tests will do this to clear things, | 155 // May be called multiple times (some tests will do this to clear things, |
156 // and TearDown will do this to make sure eveything is shiny before quitting. | 156 // and TearDown will do this to make sure eveything is shiny before quitting. |
157 void ClearDB() { | 157 void ClearDB() { |
158 if (master_.get()) | 158 if (master_.get()) |
159 master_.reset(NULL); | 159 master_.reset(NULL); |
160 | 160 |
161 // Wait for all pending file I/O to be completed. | 161 // Wait for all pending file I/O to be completed. |
162 BrowserThread::GetBlockingPool()->FlushForTesting(); | 162 content::RunAllBlockingPoolTasksUntilIdle(); |
163 } | 163 } |
164 | 164 |
165 // Loads the database from disk and makes sure that the same URLs are present | 165 // Loads the database from disk and makes sure that the same URLs are present |
166 // as were generated by TestIO_Create(). This also checks the URLs with a | 166 // as were generated by TestIO_Create(). This also checks the URLs with a |
167 // slave to make sure it reads the data properly. | 167 // slave to make sure it reads the data properly. |
168 void Reload() { | 168 void Reload() { |
169 // Clean up after our caller, who may have left the database open. | 169 // Clean up after our caller, who may have left the database open. |
170 ClearDB(); | 170 ClearDB(); |
171 | 171 |
172 ASSERT_TRUE(InitVisited(0, true)); | 172 ASSERT_TRUE(InitVisited(0, true)); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 public: | 578 public: |
579 VisitedLinkRenderProcessHostFactory() | 579 VisitedLinkRenderProcessHostFactory() |
580 : content::RenderProcessHostFactory() {} | 580 : content::RenderProcessHostFactory() {} |
581 virtual content::RenderProcessHost* CreateRenderProcessHost( | 581 virtual content::RenderProcessHost* CreateRenderProcessHost( |
582 content::BrowserContext* browser_context, | 582 content::BrowserContext* browser_context, |
583 content::SiteInstance* site_instance) const OVERRIDE { | 583 content::SiteInstance* site_instance) const OVERRIDE { |
584 return new VisitRelayingRenderProcessHost(browser_context); | 584 return new VisitRelayingRenderProcessHost(browser_context); |
585 } | 585 } |
586 | 586 |
587 private: | 587 private: |
588 | |
589 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); | 588 DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); |
590 }; | 589 }; |
591 | 590 |
592 class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { | 591 class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { |
593 public: | 592 public: |
594 virtual void SetUp() { | 593 virtual void SetUp() { |
595 SetRenderProcessHostFactory(&vc_rph_factory_); | 594 SetRenderProcessHostFactory(&vc_rph_factory_); |
596 content::RenderViewHostTestHarness::SetUp(); | 595 content::RenderViewHostTestHarness::SetUp(); |
597 } | 596 } |
598 | 597 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 VisitCountingContext different_context; | 758 VisitCountingContext different_context; |
760 VisitRelayingRenderProcessHost different_process_host(&different_context); | 759 VisitRelayingRenderProcessHost different_process_host(&different_context); |
761 | 760 |
762 content::NotificationService::current()->Notify( | 761 content::NotificationService::current()->Notify( |
763 content::NOTIFICATION_RENDERER_PROCESS_CREATED, | 762 content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
764 content::Source<content::RenderProcessHost>(&different_process_host), | 763 content::Source<content::RenderProcessHost>(&different_process_host), |
765 content::NotificationService::NoDetails()); | 764 content::NotificationService::NoDetails()); |
766 WaitForCoalescense(); | 765 WaitForCoalescense(); |
767 | 766 |
768 EXPECT_EQ(0, different_context.new_table_count()); | 767 EXPECT_EQ(0, different_context.new_table_count()); |
769 | |
770 } | 768 } |
771 | 769 |
772 } // namespace visitedlink | 770 } // namespace visitedlink |
OLD | NEW |