[email protected] | 02798a98 | 2012-01-27 00:45:33 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 5 | #include <stddef.h> |
| 6 | #include <stdint.h> |
| 7 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <cstdio> |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 9 | #include <memory> |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | |
Sebastien Marchand | 53801a3 | 2019-01-25 16:26:11 | [diff] [blame] | 13 | #include "base/bind.h" |
thestig | 819adcc8 | 2014-09-10 22:24:53 | [diff] [blame] | 14 | #include "base/files/file_util.h" |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 15 | #include "base/location.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 2773016 | 2013-07-23 14:51:55 | [diff] [blame] | 17 | #include "base/process/process_handle.h" |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 18 | #include "base/run_loop.h" |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 19 | #include "base/single_thread_task_runner.h" |
[email protected] | c72674b | 2013-06-11 04:16:43 | [diff] [blame] | 20 | #include "base/strings/string_util.h" |
gab | 7966d31 | 2016-05-11 20:35:01 | [diff] [blame] | 21 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | bbd8da9 | 2013-06-28 02:12:20 | [diff] [blame] | 22 | #include "base/time/time.h" |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 23 | #include "base/timer/mock_timer.h" |
[email protected] | 1f371fa | 2013-01-23 00:35:14 | [diff] [blame] | 24 | #include "components/visitedlink/browser/visitedlink_delegate.h" |
| 25 | #include "components/visitedlink/browser/visitedlink_event_listener.h" |
| 26 | #include "components/visitedlink/browser/visitedlink_master.h" |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 27 | #include "components/visitedlink/common/visitedlink.mojom.h" |
[email protected] | 1f371fa | 2013-01-23 00:35:14 | [diff] [blame] | 28 | #include "components/visitedlink/renderer/visitedlink_slave.h" |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 29 | #include "content/public/browser/browser_thread.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 30 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 31 | #include "content/public/browser/notification_types.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 32 | #include "content/public/test/browser_task_environment.h" |
[email protected] | 08a932d5 | 2012-06-03 21:42:12 | [diff] [blame] | 33 | #include "content/public/test/mock_render_process_host.h" |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 34 | #include "content/public/test/test_browser_context.h" |
[email protected] | b1e3f20 | 2012-06-04 14:45:50 | [diff] [blame] | 35 | #include "content/public/test/test_renderer_host.h" |
mtomasz | f7d99a5c | 2014-09-15 16:23:46 | [diff] [blame] | 36 | #include "content/public/test/test_utils.h" |
Julie Jeongeun Kim | 8ab180f7 | 2019-09-25 09:25:46 | [diff] [blame^] | 37 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 38 | #include "mojo/public/cpp/bindings/receiver_set.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | e3b599e | 2013-07-05 07:15:17 | [diff] [blame] | 40 | #include "url/gurl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 42 | using content::BrowserThread; |
[email protected] | eddd88670 | 2012-03-16 14:53:23 | [diff] [blame] | 43 | using content::MockRenderProcessHost; |
[email protected] | c025738 | 2012-03-12 20:15:34 | [diff] [blame] | 44 | using content::RenderViewHostTester; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 45 | |
Matt Falkenhagen | 24abf782 | 2017-12-15 23:55:11 | [diff] [blame] | 46 | namespace content { |
| 47 | class SiteInstance; |
| 48 | } |
| 49 | |
[email protected] | ab3eaeed | 2013-05-17 00:18:44 | [diff] [blame] | 50 | namespace visitedlink { |
[email protected] | 1f371fa | 2013-01-23 00:35:14 | [diff] [blame] | 51 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 52 | namespace { |
| 53 | |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 54 | typedef std::vector<GURL> URLs; |
| 55 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | // a nice long URL that we can append numbers to to get new URLs |
| 57 | const char g_test_prefix[] = |
| 58 | "http://www.google.com/products/foo/index.html?id=45028640526508376&seq="; |
| 59 | const int g_test_count = 1000; |
| 60 | |
| 61 | // Returns a test URL for index |i| |
| 62 | GURL TestURL(int i) { |
[email protected] | 7d3cbc9 | 2013-03-18 22:33:04 | [diff] [blame] | 63 | return GURL(base::StringPrintf("%s%d", g_test_prefix, i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | } |
| 65 | |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 66 | std::vector<VisitedLinkSlave*> g_slaves; |
| 67 | |
| 68 | class TestVisitedLinkDelegate : public VisitedLinkDelegate { |
| 69 | public: |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 70 | void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 71 | |
| 72 | void AddURLForRebuild(const GURL& url); |
| 73 | |
| 74 | private: |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 75 | URLs rebuild_urls_; |
| 76 | }; |
| 77 | |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 78 | void TestVisitedLinkDelegate::RebuildTable( |
| 79 | const scoped_refptr<URLEnumerator>& enumerator) { |
| 80 | for (URLs::const_iterator itr = rebuild_urls_.begin(); |
| 81 | itr != rebuild_urls_.end(); |
| 82 | ++itr) |
| 83 | enumerator->OnURL(*itr); |
| 84 | enumerator->OnComplete(true); |
| 85 | } |
| 86 | |
| 87 | void TestVisitedLinkDelegate::AddURLForRebuild(const GURL& url) { |
| 88 | rebuild_urls_.push_back(url); |
| 89 | } |
| 90 | |
| 91 | class TestURLIterator : public VisitedLinkMaster::URLIterator { |
| 92 | public: |
| 93 | explicit TestURLIterator(const URLs& urls); |
| 94 | |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 95 | const GURL& NextURL() override; |
| 96 | bool HasNextURL() const override; |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | URLs::const_iterator iterator_; |
| 100 | URLs::const_iterator end_; |
| 101 | }; |
| 102 | |
| 103 | TestURLIterator::TestURLIterator(const URLs& urls) |
| 104 | : iterator_(urls.begin()), |
| 105 | end_(urls.end()) { |
| 106 | } |
| 107 | |
| 108 | const GURL& TestURLIterator::NextURL() { |
| 109 | return *(iterator_++); |
| 110 | } |
| 111 | |
| 112 | bool TestURLIterator::HasNextURL() const { |
| 113 | return iterator_ != end_; |
| 114 | } |
[email protected] | dba45e3 | 2013-01-04 20:27:15 | [diff] [blame] | 115 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 116 | } // namespace |
| 117 | |
| 118 | class TrackingVisitedLinkEventListener : public VisitedLinkMaster::Listener { |
| 119 | public: |
| 120 | TrackingVisitedLinkEventListener() |
| 121 | : reset_count_(0), |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 122 | completely_reset_count_(0), |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 123 | add_count_(0) {} |
| 124 | |
Ken Rockot | aeb7eca | 2018-03-30 16:40:09 | [diff] [blame] | 125 | void NewTable(base::ReadOnlySharedMemoryRegion* table_region) override { |
| 126 | if (table_region->IsValid()) { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 127 | for (std::vector<VisitedLinkSlave>::size_type i = 0; |
| 128 | i < g_slaves.size(); i++) { |
Ken Rockot | aeb7eca | 2018-03-30 16:40:09 | [diff] [blame] | 129 | g_slaves[i]->UpdateVisitedLinks(table_region->Duplicate()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 130 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | } |
| 132 | } |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 133 | void Add(VisitedLinkCommon::Fingerprint) override { add_count_++; } |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 134 | void Reset(bool invalidate_hashes) override { |
| 135 | if (invalidate_hashes) |
| 136 | completely_reset_count_++; |
| 137 | else |
| 138 | reset_count_++; |
| 139 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 140 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 141 | void SetUp() { |
| 142 | reset_count_ = 0; |
| 143 | add_count_ = 0; |
| 144 | } |
| 145 | |
| 146 | int reset_count() const { return reset_count_; } |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 147 | int completely_reset_count() { return completely_reset_count_; } |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 148 | int add_count() const { return add_count_; } |
| 149 | |
| 150 | private: |
| 151 | int reset_count_; |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 152 | int completely_reset_count_; |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 153 | int add_count_; |
| 154 | }; |
[email protected] | c2c998c | 2009-01-27 19:08:39 | [diff] [blame] | 155 | |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 156 | class VisitedLinkTest : public testing::Test { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 157 | protected: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | // Initializes the visited link objects. Pass in the size that you want a |
| 159 | // freshly created table to be. 0 means use the default. |
| 160 | // |
| 161 | // |suppress_rebuild| is set when we're not testing rebuilding, see |
| 162 | // the VisitedLinkMaster constructor. |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 163 | // |
| 164 | // |wait_for_io_complete| wait for result of async loading. |
| 165 | bool InitVisited(int initial_size, |
| 166 | bool suppress_rebuild, |
| 167 | bool wait_for_io_complete) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 168 | // Initialize the visited link system. |
[email protected] | b42e6d8 | 2012-11-02 02:44:56 | [diff] [blame] | 169 | master_.reset(new VisitedLinkMaster(new TrackingVisitedLinkEventListener(), |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 170 | &delegate_, |
[email protected] | bff706b | 2013-01-25 00:15:01 | [diff] [blame] | 171 | true, |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 172 | suppress_rebuild, visited_file_, |
| 173 | initial_size)); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 174 | bool result = master_->Init(); |
| 175 | if (result && wait_for_io_complete) { |
| 176 | // Wait for all pending file I/O to be completed. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 177 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 178 | } |
| 179 | return result; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | // May be called multiple times (some tests will do this to clear things, |
| 183 | // and TearDown will do this to make sure eveything is shiny before quitting. |
| 184 | void ClearDB() { |
Zinovy Nis | e8482f5 | 2018-05-29 06:08:44 | [diff] [blame] | 185 | master_.reset(nullptr); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 186 | |
[email protected] | 3189013e | 2012-01-19 04:11:57 | [diff] [blame] | 187 | // Wait for all pending file I/O to be completed. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 188 | content::RunAllTasksUntilIdle(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | // Loads the database from disk and makes sure that the same URLs are present |
| 192 | // as were generated by TestIO_Create(). This also checks the URLs with a |
| 193 | // slave to make sure it reads the data properly. |
| 194 | void Reload() { |
| 195 | // Clean up after our caller, who may have left the database open. |
| 196 | ClearDB(); |
| 197 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 198 | ASSERT_TRUE(InitVisited(0, true, true)); |
| 199 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 200 | master_->DebugValidate(); |
| 201 | |
| 202 | // check that the table has the proper number of entries |
| 203 | int used_count = master_->GetUsedCount(); |
| 204 | ASSERT_EQ(used_count, g_test_count); |
| 205 | |
| 206 | // Create a slave database. |
| 207 | VisitedLinkSlave slave; |
Ken Rockot | aeb7eca | 2018-03-30 16:40:09 | [diff] [blame] | 208 | slave.UpdateVisitedLinks(master_->mapped_table_memory().region.Duplicate()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 209 | g_slaves.push_back(&slave); |
| 210 | |
| 211 | bool found; |
| 212 | for (int i = 0; i < g_test_count; i++) { |
| 213 | GURL cur = TestURL(i); |
| 214 | found = master_->IsVisited(cur); |
| 215 | EXPECT_TRUE(found) << "URL " << i << "not found in master."; |
| 216 | |
| 217 | found = slave.IsVisited(cur); |
| 218 | EXPECT_TRUE(found) << "URL " << i << "not found in slave."; |
| 219 | } |
| 220 | |
| 221 | // test some random URL so we know that it returns false sometimes too |
| 222 | found = master_->IsVisited(GURL("http://unfound.site/")); |
| 223 | ASSERT_FALSE(found); |
| 224 | found = slave.IsVisited(GURL("http://unfound.site/")); |
| 225 | ASSERT_FALSE(found); |
| 226 | |
| 227 | master_->DebugValidate(); |
| 228 | |
| 229 | g_slaves.clear(); |
| 230 | } |
| 231 | |
| 232 | // testing::Test |
dcheng | 30a1b154 | 2014-10-29 21:27:50 | [diff] [blame] | 233 | void SetUp() override { |
[email protected] | f708ed1 | 2010-09-23 12:18:34 | [diff] [blame] | 234 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 235 | |
vabr | 8c498ea4 | 2016-09-15 12:41:58 | [diff] [blame] | 236 | history_dir_ = temp_dir_.GetPath().AppendASCII("VisitedLinkTest"); |
[email protected] | 426d1c9 | 2013-12-03 20:08:54 | [diff] [blame] | 237 | ASSERT_TRUE(base::CreateDirectory(history_dir_)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 238 | |
[email protected] | c2c998c | 2009-01-27 19:08:39 | [diff] [blame] | 239 | visited_file_ = history_dir_.Append(FILE_PATH_LITERAL("VisitedLinks")); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 240 | } |
| 241 | |
dcheng | 30a1b154 | 2014-10-29 21:27:50 | [diff] [blame] | 242 | void TearDown() override { ClearDB(); } |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 243 | |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 244 | base::ScopedTempDir temp_dir_; |
[email protected] | f708ed1 | 2010-09-23 12:18:34 | [diff] [blame] | 245 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 246 | // Filenames for the services; |
[email protected] | 9e27571 | 2013-02-10 19:20:14 | [diff] [blame] | 247 | base::FilePath history_dir_; |
| 248 | base::FilePath visited_file_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 249 | |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 250 | std::unique_ptr<VisitedLinkMaster> master_; |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 251 | TestVisitedLinkDelegate delegate_; |
Gabriel Charette | 798fde7 | 2019-08-20 22:24:04 | [diff] [blame] | 252 | content::BrowserTaskEnvironment task_environment_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 253 | }; |
| 254 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 255 | // This test creates and reads some databases to make sure the data is |
| 256 | // preserved throughout those operations. |
| 257 | TEST_F(VisitedLinkTest, DatabaseIO) { |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 258 | ASSERT_TRUE(InitVisited(0, true, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 259 | |
| 260 | for (int i = 0; i < g_test_count; i++) |
| 261 | master_->AddURL(TestURL(i)); |
| 262 | |
| 263 | // Test that the database was written properly |
| 264 | Reload(); |
| 265 | } |
| 266 | |
| 267 | // Checks that we can delete things properly when there are collisions. |
| 268 | TEST_F(VisitedLinkTest, Delete) { |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 269 | static const int32_t kInitialSize = 17; |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 270 | ASSERT_TRUE(InitVisited(kInitialSize, true, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 271 | |
| 272 | // Add a cluster from 14-17 wrapping around to 0. These will all hash to the |
| 273 | // same value. |
[email protected] | c2c998c | 2009-01-27 19:08:39 | [diff] [blame] | 274 | const VisitedLinkCommon::Fingerprint kFingerprint0 = kInitialSize * 0 + 14; |
| 275 | const VisitedLinkCommon::Fingerprint kFingerprint1 = kInitialSize * 1 + 14; |
| 276 | const VisitedLinkCommon::Fingerprint kFingerprint2 = kInitialSize * 2 + 14; |
| 277 | const VisitedLinkCommon::Fingerprint kFingerprint3 = kInitialSize * 3 + 14; |
| 278 | const VisitedLinkCommon::Fingerprint kFingerprint4 = kInitialSize * 4 + 14; |
[email protected] | f8c42c9 | 2009-07-04 17:22:08 | [diff] [blame] | 279 | master_->AddFingerprint(kFingerprint0, false); // @14 |
| 280 | master_->AddFingerprint(kFingerprint1, false); // @15 |
| 281 | master_->AddFingerprint(kFingerprint2, false); // @16 |
| 282 | master_->AddFingerprint(kFingerprint3, false); // @0 |
| 283 | master_->AddFingerprint(kFingerprint4, false); // @1 |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 284 | |
| 285 | // Deleting 14 should move the next value up one slot (we do not specify an |
| 286 | // order). |
| 287 | EXPECT_EQ(kFingerprint3, master_->hash_table_[0]); |
| 288 | master_->DeleteFingerprint(kFingerprint3, false); |
[email protected] | c2c998c | 2009-01-27 19:08:39 | [diff] [blame] | 289 | VisitedLinkCommon::Fingerprint zero_fingerprint = 0; |
| 290 | EXPECT_EQ(zero_fingerprint, master_->hash_table_[1]); |
| 291 | EXPECT_NE(zero_fingerprint, master_->hash_table_[0]); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | |
| 293 | // Deleting the other four should leave the table empty. |
| 294 | master_->DeleteFingerprint(kFingerprint0, false); |
| 295 | master_->DeleteFingerprint(kFingerprint1, false); |
| 296 | master_->DeleteFingerprint(kFingerprint2, false); |
| 297 | master_->DeleteFingerprint(kFingerprint4, false); |
| 298 | |
| 299 | EXPECT_EQ(0, master_->used_items_); |
| 300 | for (int i = 0; i < kInitialSize; i++) |
[email protected] | c2c998c | 2009-01-27 19:08:39 | [diff] [blame] | 301 | EXPECT_EQ(zero_fingerprint, master_->hash_table_[i]) << |
| 302 | "Hash table has values in it."; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // When we delete more than kBigDeleteThreshold we trigger different behavior |
| 306 | // where the entire file is rewritten. |
| 307 | TEST_F(VisitedLinkTest, BigDelete) { |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 308 | ASSERT_TRUE(InitVisited(16381, true, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 309 | |
| 310 | // Add the base set of URLs that won't be deleted. |
| 311 | // Reload() will test for these. |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 312 | for (int32_t i = 0; i < g_test_count; i++) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 313 | master_->AddURL(TestURL(i)); |
| 314 | |
| 315 | // Add more URLs than necessary to trigger this case. |
| 316 | const int kTestDeleteCount = VisitedLinkMaster::kBigDeleteThreshold + 2; |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 317 | URLs urls_to_delete; |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 318 | for (int32_t i = g_test_count; i < g_test_count + kTestDeleteCount; i++) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 319 | GURL url(TestURL(i)); |
| 320 | master_->AddURL(url); |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 321 | urls_to_delete.push_back(url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 322 | } |
| 323 | |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 324 | TestURLIterator iterator(urls_to_delete); |
| 325 | master_->DeleteURLs(&iterator); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 326 | master_->DebugValidate(); |
| 327 | |
| 328 | Reload(); |
| 329 | } |
| 330 | |
| 331 | TEST_F(VisitedLinkTest, DeleteAll) { |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 332 | ASSERT_TRUE(InitVisited(0, true, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 333 | |
| 334 | { |
| 335 | VisitedLinkSlave slave; |
Ken Rockot | aeb7eca | 2018-03-30 16:40:09 | [diff] [blame] | 336 | slave.UpdateVisitedLinks(master_->mapped_table_memory().region.Duplicate()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 337 | g_slaves.push_back(&slave); |
| 338 | |
| 339 | // Add the test URLs. |
| 340 | for (int i = 0; i < g_test_count; i++) { |
| 341 | master_->AddURL(TestURL(i)); |
| 342 | ASSERT_EQ(i + 1, master_->GetUsedCount()); |
| 343 | } |
| 344 | master_->DebugValidate(); |
| 345 | |
| 346 | // Make sure the slave picked up the adds. |
| 347 | for (int i = 0; i < g_test_count; i++) |
| 348 | EXPECT_TRUE(slave.IsVisited(TestURL(i))); |
| 349 | |
| 350 | // Clear the table and make sure the slave picked it up. |
| 351 | master_->DeleteAllURLs(); |
| 352 | EXPECT_EQ(0, master_->GetUsedCount()); |
| 353 | for (int i = 0; i < g_test_count; i++) { |
| 354 | EXPECT_FALSE(master_->IsVisited(TestURL(i))); |
| 355 | EXPECT_FALSE(slave.IsVisited(TestURL(i))); |
| 356 | } |
| 357 | |
| 358 | // Close the database. |
| 359 | g_slaves.clear(); |
| 360 | ClearDB(); |
| 361 | } |
| 362 | |
| 363 | // Reopen and validate. |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 364 | ASSERT_TRUE(InitVisited(0, true, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 365 | master_->DebugValidate(); |
| 366 | EXPECT_EQ(0, master_->GetUsedCount()); |
| 367 | for (int i = 0; i < g_test_count; i++) |
| 368 | EXPECT_FALSE(master_->IsVisited(TestURL(i))); |
| 369 | } |
| 370 | |
| 371 | // This tests that the master correctly resizes its tables when it gets too |
| 372 | // full, notifies its slaves of the change, and updates the disk. |
| 373 | TEST_F(VisitedLinkTest, Resizing) { |
| 374 | // Create a very small database. |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 375 | const int32_t initial_size = 17; |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 376 | ASSERT_TRUE(InitVisited(initial_size, true, true)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 377 | |
| 378 | // ...and a slave |
| 379 | VisitedLinkSlave slave; |
Ken Rockot | aeb7eca | 2018-03-30 16:40:09 | [diff] [blame] | 380 | slave.UpdateVisitedLinks(master_->mapped_table_memory().region.Duplicate()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 381 | g_slaves.push_back(&slave); |
| 382 | |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 383 | int32_t used_count = master_->GetUsedCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 384 | ASSERT_EQ(used_count, 0); |
| 385 | |
| 386 | for (int i = 0; i < g_test_count; i++) { |
| 387 | master_->AddURL(TestURL(i)); |
| 388 | used_count = master_->GetUsedCount(); |
| 389 | ASSERT_EQ(i + 1, used_count); |
| 390 | } |
| 391 | |
| 392 | // Verify that the table got resized sufficiently. |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 393 | int32_t table_size; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 394 | VisitedLinkCommon::Fingerprint* table; |
| 395 | master_->GetUsageStatistics(&table_size, &table); |
| 396 | used_count = master_->GetUsedCount(); |
| 397 | ASSERT_GT(table_size, used_count); |
| 398 | ASSERT_EQ(used_count, g_test_count) << |
| 399 | "table count doesn't match the # of things we added"; |
| 400 | |
| 401 | // Verify that the slave got the resize message and has the same |
| 402 | // table information. |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 403 | int32_t child_table_size; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 404 | VisitedLinkCommon::Fingerprint* child_table; |
| 405 | slave.GetUsageStatistics(&child_table_size, &child_table); |
| 406 | ASSERT_EQ(table_size, child_table_size); |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 407 | for (int32_t i = 0; i < table_size; i++) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 408 | ASSERT_EQ(table[i], child_table[i]); |
| 409 | } |
| 410 | |
| 411 | master_->DebugValidate(); |
| 412 | g_slaves.clear(); |
| 413 | |
| 414 | // This tests that the file is written correctly by reading it in using |
| 415 | // a new database. |
| 416 | Reload(); |
| 417 | } |
| 418 | |
| 419 | // Tests that if the database doesn't exist, it will be rebuilt from history. |
| 420 | TEST_F(VisitedLinkTest, Rebuild) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 421 | // Add half of our URLs to history. This needs to be done before we |
| 422 | // initialize the visited link DB. |
| 423 | int history_count = g_test_count / 2; |
| 424 | for (int i = 0; i < history_count; i++) |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 425 | delegate_.AddURLForRebuild(TestURL(i)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 426 | |
| 427 | // Initialize the visited link DB. Since the visited links file doesn't exist |
| 428 | // and we don't suppress history rebuilding, this will load from history. |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 429 | ASSERT_TRUE(InitVisited(0, false, false)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 430 | |
| 431 | // While the table is rebuilding, add the rest of the URLs to the visited |
| 432 | // link system. This isn't guaranteed to happen during the rebuild, so we |
| 433 | // can't be 100% sure we're testing the right thing, but in practice is. |
| 434 | // All the adds above will generally take some time queuing up on the |
| 435 | // history thread, and it will take a while to catch up to actually |
| 436 | // processing the rebuild that has queued behind it. We will generally |
| 437 | // finish adding all of the URLs before it has even found the first URL. |
| 438 | for (int i = history_count; i < g_test_count; i++) |
| 439 | master_->AddURL(TestURL(i)); |
| 440 | |
| 441 | // Add one more and then delete it. |
| 442 | master_->AddURL(TestURL(g_test_count)); |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 443 | URLs urls_to_delete; |
| 444 | urls_to_delete.push_back(TestURL(g_test_count)); |
| 445 | TestURLIterator iterator(urls_to_delete); |
| 446 | master_->DeleteURLs(&iterator); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 447 | |
| 448 | // Wait for the rebuild to complete. The task will terminate the message |
| 449 | // loop when the rebuild is done. There's no chance that the rebuild will |
| 450 | // complete before we set the task because the rebuild completion message |
| 451 | // is posted to the message loop; until we Run() it, rebuild can not |
| 452 | // complete. |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 453 | base::RunLoop run_loop; |
| 454 | master_->set_rebuild_complete_task(run_loop.QuitClosure()); |
| 455 | run_loop.Run(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 456 | |
| 457 | // Test that all URLs were written to the database properly. |
| 458 | Reload(); |
| 459 | |
| 460 | // Make sure the extra one was *not* written (Reload won't test this). |
| 461 | EXPECT_FALSE(master_->IsVisited(TestURL(g_test_count))); |
| 462 | } |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 463 | |
[email protected] | aed132ed | 2009-08-19 22:44:12 | [diff] [blame] | 464 | // Test that importing a large number of URLs will work |
| 465 | TEST_F(VisitedLinkTest, BigImport) { |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 466 | ASSERT_TRUE(InitVisited(0, false, false)); |
[email protected] | aed132ed | 2009-08-19 22:44:12 | [diff] [blame] | 467 | |
| 468 | // Before the table rebuilds, add a large number of URLs |
| 469 | int total_count = VisitedLinkMaster::kDefaultTableSize + 10; |
| 470 | for (int i = 0; i < total_count; i++) |
| 471 | master_->AddURL(TestURL(i)); |
| 472 | |
| 473 | // Wait for the rebuild to complete. |
[email protected] | ec04d3f | 2013-06-06 21:31:39 | [diff] [blame] | 474 | base::RunLoop run_loop; |
| 475 | master_->set_rebuild_complete_task(run_loop.QuitClosure()); |
| 476 | run_loop.Run(); |
[email protected] | aed132ed | 2009-08-19 22:44:12 | [diff] [blame] | 477 | |
| 478 | // Ensure that the right number of URLs are present |
| 479 | int used_count = master_->GetUsedCount(); |
| 480 | ASSERT_EQ(used_count, total_count); |
| 481 | } |
| 482 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 483 | TEST_F(VisitedLinkTest, Listener) { |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 484 | ASSERT_TRUE(InitVisited(0, true, true)); |
| 485 | |
| 486 | TrackingVisitedLinkEventListener* listener = |
| 487 | static_cast<TrackingVisitedLinkEventListener*>(master_->GetListener()); |
| 488 | |
| 489 | // Verify that VisitedLinkMaster::Listener::Reset(true) was never called when |
| 490 | // the table was created. |
| 491 | EXPECT_EQ(0, listener->completely_reset_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 492 | |
| 493 | // Add test URLs. |
| 494 | for (int i = 0; i < g_test_count; i++) { |
| 495 | master_->AddURL(TestURL(i)); |
| 496 | ASSERT_EQ(i + 1, master_->GetUsedCount()); |
| 497 | } |
| 498 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 499 | // Delete an URL. |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 500 | URLs urls_to_delete; |
| 501 | urls_to_delete.push_back(TestURL(0)); |
| 502 | TestURLIterator iterator(urls_to_delete); |
| 503 | master_->DeleteURLs(&iterator); |
| 504 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 505 | // ... and all of the remaining ones. |
| 506 | master_->DeleteAllURLs(); |
| 507 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 508 | // Verify that VisitedLinkMaster::Listener::Add was called for each added URL. |
[email protected] | b42e6d8 | 2012-11-02 02:44:56 | [diff] [blame] | 509 | EXPECT_EQ(g_test_count, listener->add_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 510 | // Verify that VisitedLinkMaster::Listener::Reset was called both when one and |
| 511 | // all URLs are deleted. |
[email protected] | b42e6d8 | 2012-11-02 02:44:56 | [diff] [blame] | 512 | EXPECT_EQ(2, listener->reset_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 513 | |
| 514 | ClearDB(); |
| 515 | |
| 516 | ASSERT_TRUE(InitVisited(0, true, true)); |
| 517 | |
| 518 | listener = |
| 519 | static_cast<TrackingVisitedLinkEventListener*>(master_->GetListener()); |
| 520 | // Verify that VisitedLinkMaster::Listener::Reset(true) was called when the |
| 521 | // table was loaded. |
| 522 | EXPECT_EQ(1, listener->completely_reset_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 523 | } |
| 524 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 525 | class VisitCountingContext : public mojom::VisitedLinkNotificationSink { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 526 | public: |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 527 | VisitCountingContext() |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 528 | : add_count_(0), |
| 529 | add_event_count_(0), |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 530 | reset_event_count_(0), |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 531 | completely_reset_event_count_(0), |
Lukasz Anforowicz | 2b269973 | 2018-04-12 18:49:10 | [diff] [blame] | 532 | new_table_count_(0) {} |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 533 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 534 | void Bind(mojo::ScopedMessagePipeHandle handle) { |
Julie Jeongeun Kim | 8ab180f7 | 2019-09-25 09:25:46 | [diff] [blame^] | 535 | receiver_.Add(this, |
| 536 | mojo::PendingReceiver<mojom::VisitedLinkNotificationSink>( |
| 537 | std::move(handle))); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 538 | } |
| 539 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 540 | void WaitForUpdate() { |
| 541 | base::RunLoop run_loop; |
| 542 | quit_closure_ = run_loop.QuitClosure(); |
| 543 | run_loop.Run(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 544 | } |
| 545 | |
Julie Jeongeun Kim | 8ab180f7 | 2019-09-25 09:25:46 | [diff] [blame^] | 546 | void WaitForNoUpdate() { receiver_.FlushForTesting(); } |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 547 | |
Julie Jeongeun Kim | 8ab180f7 | 2019-09-25 09:25:46 | [diff] [blame^] | 548 | mojo::ReceiverSet<mojom::VisitedLinkNotificationSink>& binding() { |
| 549 | return receiver_; |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 550 | } |
| 551 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 552 | void NotifyUpdate() { |
| 553 | if (!quit_closure_.is_null()) |
Daniel Cheng | 83563bc | 2019-04-30 23:50:24 | [diff] [blame] | 554 | std::move(quit_closure_).Run(); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | void UpdateVisitedLinks( |
Ken Rockot | aeb7eca | 2018-03-30 16:40:09 | [diff] [blame] | 558 | base::ReadOnlySharedMemoryRegion table_region) override { |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 559 | new_table_count_++; |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 560 | NotifyUpdate(); |
| 561 | } |
| 562 | |
| 563 | void AddVisitedLinks(const std::vector<uint64_t>& link_hashes) override { |
| 564 | add_count_ += link_hashes.size(); |
| 565 | add_event_count_++; |
| 566 | NotifyUpdate(); |
| 567 | } |
| 568 | |
| 569 | void ResetVisitedLinks(bool invalidate_cached_hashes) override { |
| 570 | if (invalidate_cached_hashes) |
| 571 | completely_reset_event_count_++; |
| 572 | else |
| 573 | reset_event_count_++; |
| 574 | NotifyUpdate(); |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 575 | } |
| 576 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 577 | int add_count() const { return add_count_; } |
| 578 | int add_event_count() const { return add_event_count_; } |
| 579 | int reset_event_count() const { return reset_event_count_; } |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 580 | int completely_reset_event_count() const { |
| 581 | return completely_reset_event_count_; |
| 582 | } |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 583 | int new_table_count() const { return new_table_count_; } |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 584 | |
| 585 | private: |
| 586 | int add_count_; |
| 587 | int add_event_count_; |
| 588 | int reset_event_count_; |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 589 | int completely_reset_event_count_; |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 590 | int new_table_count_; |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 591 | |
| 592 | base::Closure quit_closure_; |
Julie Jeongeun Kim | 8ab180f7 | 2019-09-25 09:25:46 | [diff] [blame^] | 593 | mojo::ReceiverSet<mojom::VisitedLinkNotificationSink> receiver_; |
Lukasz Anforowicz | 2b269973 | 2018-04-12 18:49:10 | [diff] [blame] | 594 | |
| 595 | DISALLOW_COPY_AND_ASSIGN(VisitCountingContext); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 596 | }; |
| 597 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 598 | // Stub out as little as possible, borrowing from RenderProcessHost. |
[email protected] | b6a2f8de | 2012-01-31 17:28:49 | [diff] [blame] | 599 | class VisitRelayingRenderProcessHost : public MockRenderProcessHost { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 600 | public: |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 601 | explicit VisitRelayingRenderProcessHost( |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 602 | content::BrowserContext* browser_context, |
| 603 | VisitCountingContext* context) |
Bo Liu | eb218ee | 2018-03-21 20:24:35 | [diff] [blame] | 604 | : MockRenderProcessHost(browser_context) { |
ben | a06f7d6 | 2017-04-04 20:48:52 | [diff] [blame] | 605 | OverrideBinderForTesting( |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 606 | mojom::VisitedLinkNotificationSink::Name_, |
| 607 | base::Bind(&VisitCountingContext::Bind, base::Unretained(context))); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 608 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 609 | content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 610 | content::Source<RenderProcessHost>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 611 | content::NotificationService::NoDetails()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 612 | } |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 613 | ~VisitRelayingRenderProcessHost() override { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 614 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 615 | content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 616 | content::Source<content::RenderProcessHost>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 617 | content::NotificationService::NoDetails()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 618 | } |
| 619 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 620 | private: |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 621 | DISALLOW_COPY_AND_ASSIGN(VisitRelayingRenderProcessHost); |
| 622 | }; |
| 623 | |
| 624 | class VisitedLinkRenderProcessHostFactory |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 625 | : public content::RenderProcessHostFactory { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 626 | public: |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 627 | VisitedLinkRenderProcessHostFactory() : context_(new VisitCountingContext) {} |
dcheng | 00ea022b | 2014-10-21 11:24:56 | [diff] [blame] | 628 | content::RenderProcessHost* CreateRenderProcessHost( |
Matt Falkenhagen | 24abf782 | 2017-12-15 23:55:11 | [diff] [blame] | 629 | content::BrowserContext* browser_context, |
Lucas Furukawa Gadani | 0a70be9 | 2019-06-28 17:31:26 | [diff] [blame] | 630 | content::SiteInstance* site_instance) override { |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 631 | return new VisitRelayingRenderProcessHost(browser_context, context_.get()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 632 | } |
| 633 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 634 | VisitCountingContext* context() { return context_.get(); } |
| 635 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 636 | private: |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 637 | std::unique_ptr<VisitCountingContext> context_; |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 638 | DISALLOW_COPY_AND_ASSIGN(VisitedLinkRenderProcessHostFactory); |
| 639 | }; |
| 640 | |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 641 | class VisitedLinkEventsTest : public content::RenderViewHostTestHarness { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 642 | public: |
dcheng | 30a1b154 | 2014-10-29 21:27:50 | [diff] [blame] | 643 | void SetUp() override { |
[email protected] | 9a46725f | 2012-10-24 18:25:48 | [diff] [blame] | 644 | SetRenderProcessHostFactory(&vc_rph_factory_); |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 645 | content::RenderViewHostTestHarness::SetUp(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 646 | } |
| 647 | |
wkorman | 1c17345b | 2015-11-12 03:02:42 | [diff] [blame] | 648 | void TearDown() override { |
| 649 | // Explicitly destroy the master before proceeding with the rest |
| 650 | // of teardown because it posts a task to close a file handle, and |
| 651 | // we need to make sure we've finished all file related work |
| 652 | // before our superclass sets about destroying the scoped temp |
| 653 | // directory. |
| 654 | master_.reset(); |
| 655 | RenderViewHostTestHarness::TearDown(); |
| 656 | } |
| 657 | |
Sylvain Defresne | 330d05c | 2019-08-07 12:36:37 | [diff] [blame] | 658 | std::unique_ptr<content::BrowserContext> CreateBrowserContext() override { |
| 659 | auto context = std::make_unique<content::TestBrowserContext>(); |
| 660 | CreateVisitedLinkMaster(context.get()); |
[email protected] | cc99c9f | 2013-07-15 12:26:09 | [diff] [blame] | 661 | return context; |
| 662 | } |
| 663 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 664 | VisitCountingContext* context() { return vc_rph_factory_.context(); } |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 665 | |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 666 | VisitedLinkMaster* master() const { |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 667 | return master_.get(); |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 668 | } |
| 669 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 670 | protected: |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 671 | void CreateVisitedLinkMaster(content::BrowserContext* browser_context) { |
tzik | 57c66e3 | 2018-07-02 08:02:57 | [diff] [blame] | 672 | timer_.reset(new base::MockOneShotTimer()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 673 | master_.reset(new VisitedLinkMaster(browser_context, &delegate_, true)); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 674 | static_cast<VisitedLinkEventListener*>(master_->GetListener()) |
| 675 | ->SetCoalesceTimerForTest(timer_.get()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 676 | master_->Init(); |
| 677 | } |
| 678 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 679 | VisitedLinkRenderProcessHostFactory vc_rph_factory_; |
| 680 | |
[email protected] | 4c3d9d6 | 2013-01-09 22:37:20 | [diff] [blame] | 681 | TestVisitedLinkDelegate delegate_; |
tzik | 57c66e3 | 2018-07-02 08:02:57 | [diff] [blame] | 682 | std::unique_ptr<base::MockOneShotTimer> timer_; |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 683 | std::unique_ptr<VisitedLinkMaster> master_; |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 684 | }; |
| 685 | |
wkorman | 1c17345b | 2015-11-12 03:02:42 | [diff] [blame] | 686 | TEST_F(VisitedLinkEventsTest, Coalescence) { |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 687 | // Waiting complete rebuild the table. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 688 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 689 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 690 | // After rebuild table expect reset event. |
| 691 | EXPECT_EQ(1, context()->reset_event_count()); |
| 692 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 693 | // add some URLs to master. |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 694 | // Add a few URLs. |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 695 | master()->AddURL(GURL("http://acidtests.org/")); |
| 696 | master()->AddURL(GURL("http://google.com/")); |
| 697 | master()->AddURL(GURL("http://chromium.org/")); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 698 | // Just for kicks, add a duplicate URL. This shouldn't increase the resulting |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 699 | master()->AddURL(GURL("http://acidtests.org/")); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 700 | ASSERT_TRUE(timer_->IsRunning()); |
| 701 | timer_->Fire(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 702 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 703 | context()->WaitForUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 704 | |
| 705 | // We now should have 3 entries added in 1 event. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 706 | EXPECT_EQ(3, context()->add_count()); |
| 707 | EXPECT_EQ(1, context()->add_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 708 | |
| 709 | // Test whether the coalescing continues by adding a few more URLs. |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 710 | master()->AddURL(GURL("http://google.com/chrome/")); |
| 711 | master()->AddURL(GURL("http://webkit.org/")); |
| 712 | master()->AddURL(GURL("http://acid3.acidtests.org/")); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 713 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 714 | ASSERT_TRUE(timer_->IsRunning()); |
| 715 | timer_->Fire(); |
| 716 | context()->WaitForUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 717 | |
| 718 | // We should have 6 entries added in 2 events. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 719 | EXPECT_EQ(6, context()->add_count()); |
| 720 | EXPECT_EQ(2, context()->add_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 721 | |
| 722 | // Test whether duplicate entries produce add events. |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 723 | master()->AddURL(GURL("http://acidtests.org/")); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 724 | EXPECT_FALSE(timer_->IsRunning()); |
| 725 | context()->WaitForNoUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 726 | |
| 727 | // We should have no change in results. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 728 | EXPECT_EQ(6, context()->add_count()); |
| 729 | EXPECT_EQ(2, context()->add_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 730 | |
| 731 | // Ensure that the coalescing does not resume after resetting. |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 732 | master()->AddURL(GURL("http://build.chromium.org/")); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 733 | EXPECT_TRUE(timer_->IsRunning()); |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 734 | master()->DeleteAllURLs(); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 735 | EXPECT_FALSE(timer_->IsRunning()); |
| 736 | context()->WaitForNoUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 737 | |
| 738 | // We should have no change in results except for one new reset event. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 739 | EXPECT_EQ(6, context()->add_count()); |
| 740 | EXPECT_EQ(2, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 741 | EXPECT_EQ(2, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 742 | } |
| 743 | |
[email protected] | 7fa7dd5 | 2011-04-24 01:09:42 | [diff] [blame] | 744 | TEST_F(VisitedLinkEventsTest, Basics) { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 745 | RenderViewHostTester::For(rvh())->CreateTestRenderView( |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 746 | base::string16(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); |
[email protected] | 6e8d6464 | 2009-08-10 15:27:19 | [diff] [blame] | 747 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 748 | // Waiting complete rebuild the table. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 749 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 750 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 751 | // After rebuild table expect reset event. |
| 752 | EXPECT_EQ(1, context()->reset_event_count()); |
| 753 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 754 | // Add a few URLs. |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 755 | master()->AddURL(GURL("http://acidtests.org/")); |
| 756 | master()->AddURL(GURL("http://google.com/")); |
| 757 | master()->AddURL(GURL("http://chromium.org/")); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 758 | ASSERT_TRUE(timer_->IsRunning()); |
| 759 | timer_->Fire(); |
| 760 | context()->WaitForUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 761 | |
| 762 | // We now should have 1 add event. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 763 | EXPECT_EQ(1, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 764 | EXPECT_EQ(1, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 765 | |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 766 | master()->DeleteAllURLs(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 767 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 768 | EXPECT_FALSE(timer_->IsRunning()); |
| 769 | context()->WaitForNoUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 770 | |
| 771 | // We should have no change in add results, plus one new reset event. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 772 | EXPECT_EQ(1, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 773 | EXPECT_EQ(2, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 774 | } |
| 775 | |
[email protected] | 7fa7dd5 | 2011-04-24 01:09:42 | [diff] [blame] | 776 | TEST_F(VisitedLinkEventsTest, TabVisibility) { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 777 | RenderViewHostTester::For(rvh())->CreateTestRenderView( |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 778 | base::string16(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, false); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 779 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 780 | // Waiting complete rebuild the table. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 781 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 782 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 783 | // After rebuild table expect reset event. |
| 784 | EXPECT_EQ(1, context()->reset_event_count()); |
| 785 | |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 786 | // Simulate tab becoming inactive. |
bsep | f3b00fa5 | 2017-02-11 00:06:38 | [diff] [blame] | 787 | RenderViewHostTester::For(rvh())->SimulateWasHidden(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 788 | |
| 789 | // Add a few URLs. |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 790 | master()->AddURL(GURL("http://acidtests.org/")); |
| 791 | master()->AddURL(GURL("http://google.com/")); |
| 792 | master()->AddURL(GURL("http://chromium.org/")); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 793 | ASSERT_TRUE(timer_->IsRunning()); |
| 794 | timer_->Fire(); |
| 795 | context()->WaitForNoUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 796 | |
| 797 | // We shouldn't have any events. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 798 | EXPECT_EQ(0, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 799 | EXPECT_EQ(1, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 800 | |
| 801 | // Simulate the tab becoming active. |
bsep | f3b00fa5 | 2017-02-11 00:06:38 | [diff] [blame] | 802 | RenderViewHostTester::For(rvh())->SimulateWasShown(); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 803 | context()->WaitForUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 804 | |
| 805 | // We should now have 3 add events, still no reset events. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 806 | EXPECT_EQ(1, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 807 | EXPECT_EQ(1, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 808 | |
| 809 | // Deactivate the tab again. |
bsep | f3b00fa5 | 2017-02-11 00:06:38 | [diff] [blame] | 810 | RenderViewHostTester::For(rvh())->SimulateWasHidden(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 811 | |
| 812 | // Add a bunch of URLs (over 50) to exhaust the link event buffer. |
| 813 | for (int i = 0; i < 100; i++) |
[email protected] | 5016ee1 | 2012-10-26 23:56:31 | [diff] [blame] | 814 | master()->AddURL(TestURL(i)); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 815 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 816 | ASSERT_TRUE(timer_->IsRunning()); |
| 817 | timer_->Fire(); |
| 818 | context()->WaitForNoUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 819 | |
| 820 | // Again, no change in events until tab is active. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 821 | EXPECT_EQ(1, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 822 | EXPECT_EQ(1, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 823 | |
| 824 | // Activate the tab. |
bsep | f3b00fa5 | 2017-02-11 00:06:38 | [diff] [blame] | 825 | RenderViewHostTester::For(rvh())->SimulateWasShown(); |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 826 | EXPECT_FALSE(timer_->IsRunning()); |
| 827 | context()->WaitForUpdate(); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 828 | |
| 829 | // We should have only one more reset event. |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 830 | EXPECT_EQ(1, context()->add_event_count()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 831 | EXPECT_EQ(2, context()->reset_event_count()); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 832 | } |
[email protected] | 1f371fa | 2013-01-23 00:35:14 | [diff] [blame] | 833 | |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 834 | // Tests that VisitedLink ignores renderer process creation notification for a |
[email protected] | 28a66e25 | 2013-01-25 07:54:02 | [diff] [blame] | 835 | // different context. |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 836 | TEST_F(VisitedLinkEventsTest, IgnoreRendererCreationFromDifferentContext) { |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 837 | content::TestBrowserContext different_context; |
| 838 | VisitCountingContext counting_context; |
| 839 | VisitRelayingRenderProcessHost different_process_host(&different_context, |
| 840 | &counting_context); |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 841 | |
Lukasz Anforowicz | 2b269973 | 2018-04-12 18:49:10 | [diff] [blame] | 842 | size_t old_size = counting_context.binding().size(); |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 843 | content::NotificationService::current()->Notify( |
| 844 | content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
| 845 | content::Source<content::RenderProcessHost>(&different_process_host), |
| 846 | content::NotificationService::NoDetails()); |
Lukasz Anforowicz | 2b269973 | 2018-04-12 18:49:10 | [diff] [blame] | 847 | size_t new_size = counting_context.binding().size(); |
| 848 | EXPECT_EQ(old_size, new_size); |
[email protected] | c2134fb | 2013-01-23 04:28:52 | [diff] [blame] | 849 | } |
| 850 | |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 851 | class VisitedLinkCompletelyResetEventTest : public VisitedLinkEventsTest { |
| 852 | public: |
Sylvain Defresne | 330d05c | 2019-08-07 12:36:37 | [diff] [blame] | 853 | std::unique_ptr<content::BrowserContext> CreateBrowserContext() override { |
| 854 | auto context = std::make_unique<content::TestBrowserContext>(); |
| 855 | CreateVisitedLinkFile(context.get()); |
| 856 | CreateVisitedLinkMaster(context.get()); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 857 | return context; |
| 858 | } |
| 859 | |
| 860 | void CreateVisitedLinkFile(content::BrowserContext* browser_context) { |
| 861 | base::FilePath visited_file = |
| 862 | browser_context->GetPath().Append(FILE_PATH_LITERAL("Visited Links")); |
dcheng | 3f767dc3 | 2016-04-25 22:54:22 | [diff] [blame] | 863 | std::unique_ptr<VisitedLinkMaster> master( |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 864 | new VisitedLinkMaster(new TrackingVisitedLinkEventListener(), |
| 865 | &delegate_, true, true, visited_file, 0)); |
| 866 | master->Init(); |
| 867 | // Waiting complete create the table. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 868 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 869 | |
| 870 | master.reset(); |
| 871 | // Wait for all pending file I/O to be completed. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 872 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 873 | } |
| 874 | }; |
| 875 | |
| 876 | TEST_F(VisitedLinkCompletelyResetEventTest, LoadTable) { |
| 877 | // Waiting complete loading the table. |
Gabriel Charette | 01507a2 | 2017-09-27 21:30:08 | [diff] [blame] | 878 | content::RunAllTasksUntilIdle(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 879 | |
sammc | aa22276 | 2016-09-21 07:30:42 | [diff] [blame] | 880 | context()->binding().FlushForTesting(); |
sath | af37203d | 2015-12-15 15:10:42 | [diff] [blame] | 881 | |
| 882 | // After load table expect completely reset event. |
| 883 | EXPECT_EQ(1, context()->completely_reset_event_count()); |
| 884 | } |
| 885 | |
[email protected] | ab3eaeed | 2013-05-17 00:18:44 | [diff] [blame] | 886 | } // namespace visitedlink |