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