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