chromium/components/visitedlink/test/visitedlink_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <stddef.h>
#include <stdint.h>

#include <cstdio>
#include <memory>
#include <string>
#include <vector>

#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/process/process_handle.h"
#include "base/run_loop.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/scoped_feature_list.h"
#include "base/time/time.h"
#include "base/timer/mock_timer.h"
#include "components/visitedlink/browser/partitioned_visitedlink_writer.h"
#include "components/visitedlink/browser/visitedlink_delegate.h"
#include "components/visitedlink/browser/visitedlink_event_listener.h"
#include "components/visitedlink/browser/visitedlink_writer.h"
#include "components/visitedlink/common/visitedlink.mojom.h"
#include "components/visitedlink/common/visitedlink_common.h"
#include "components/visitedlink/core/visited_link.h"
#include "components/visitedlink/renderer/visitedlink_reader.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_renderer_host.h"
#include "content/public/test/test_utils.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver_set.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"

BrowserThread;
MockRenderProcessHost;
RenderViewHostTester;

namespace content {
class SiteInstance;
}

namespace visitedlink {

namespace {

URLs;

// a nice long URL that we can append numbers to to get new URLs
const char kTestPrefix[] =;
constexpr int kTestCount =;

// Returns a test URL for index |i|
GURL TestURL(int i) {}

std::vector<VisitedLinkReader*> g_readers;

class TestVisitedLinkDelegate : public VisitedLinkDelegate {};

void TestVisitedLinkDelegate::RebuildTable(
    const scoped_refptr<URLEnumerator>& enumerator) {}

void TestVisitedLinkDelegate::BuildVisitedLinkTable(
    const scoped_refptr<VisitedLinkEnumerator>& enumerator) {}

void TestVisitedLinkDelegate::AddURLForRebuild(const GURL& url) {}

void TestVisitedLinkDelegate::AddVisitedLinkForRebuild(
    const VisitedLink& link) {}

class TestURLIterator : public VisitedLinkWriter::URLIterator {};

TestURLIterator::TestURLIterator(const URLs& urls)
    :{}

const GURL& TestURLIterator::NextURL() {}

bool TestURLIterator::HasNextURL() const {}

class TestVisitedLinkIterator
    : public PartitionedVisitedLinkWriter::VisitedLinkIterator {};

TestVisitedLinkIterator::TestVisitedLinkIterator(
    const std::vector<VisitedLink>& links)
    :{}

const VisitedLink& TestVisitedLinkIterator::NextVisitedLink() {}

bool TestVisitedLinkIterator::HasNextVisitedLink() const {}

}  // namespace

class TrackingVisitedLinkEventListener
    : public PartitionedVisitedLinkWriter::Listener,
      public VisitedLinkWriter::Listener {};

class VisitedLinkTest : public testing::Test {};

// This test creates and reads some databases to make sure the data is
// preserved throughout those operations.
TEST_F(VisitedLinkTest, DatabaseIO) {}

// This test fills a database using AddURLs() and verifies that it can be read
// back correctly.
TEST_F(VisitedLinkTest, DatabaseIOAddURLs) {}

// Checks that we can delete things properly when there are collisions.
TEST_F(VisitedLinkTest, Delete) {}

// When we delete more than kBulkOperationThreshold we trigger different
// behavior where the entire file is rewritten.
TEST_F(VisitedLinkTest, BigDelete) {}

TEST_F(VisitedLinkTest, DeleteAll) {}

// This tests that the writer correctly resizes its tables when it gets too
// full, notifies its readers of the change, and updates the disk.
TEST_F(VisitedLinkTest, Resizing) {}

// Tests that if the database doesn't exist, it will be rebuilt from history.
TEST_F(VisitedLinkTest, Rebuild) {}

// Test that importing a large number of URLs will work
TEST_F(VisitedLinkTest, BigImport) {}

TEST_F(VisitedLinkTest, Listener) {}

TEST_F(VisitedLinkTest, HashRangeWraparound) {}

TEST_F(VisitedLinkTest, ResizeErrorHandling) {}

enum TestMode {};

class PartitionedVisitedLinkTest
    : public testing::Test,
      public ::testing::WithParamInterface<TestMode> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(PartitionedVisitedLinkTest, BuildPartitionedTable) {}

TEST_P(PartitionedVisitedLinkTest, BuildPartitionedTableWithSelfLinks) {}

TEST_P(PartitionedVisitedLinkTest, NotVisitedEmptyDB) {}

TEST_P(PartitionedVisitedLinkTest, NotVisitedSomeFieldsMatch) {}

TEST_P(PartitionedVisitedLinkTest, AddAndDelete) {}

TEST_P(PartitionedVisitedLinkTest, AddAndDeleteSelfLink) {}

TEST_P(PartitionedVisitedLinkTest, DoesNotAddSubframeSelfLinks) {}

// Checks that we can delete things properly when there are collisions.
TEST_P(PartitionedVisitedLinkTest, DeleteWithCollisions) {}

TEST_P(PartitionedVisitedLinkTest, DeleteAll) {}

TEST_P(PartitionedVisitedLinkTest, Resizing) {}

TEST_P(PartitionedVisitedLinkTest, HashRangeWraparound) {}

TEST_P(PartitionedVisitedLinkTest, Listener) {}

class VisitCountingContext : public mojom::VisitedLinkNotificationSink {};

// Stub out as little as possible, borrowing from RenderProcessHost.
class VisitRelayingRenderProcessHost : public MockRenderProcessHost {};

class VisitedLinkRenderProcessHostFactory
    : public content::RenderProcessHostFactory {};

class VisitedLinkEventsTest : public content::RenderViewHostTestHarness {};

TEST_F(VisitedLinkEventsTest, Coalescence) {}

TEST_F(VisitedLinkEventsTest, Basics) {}

TEST_F(VisitedLinkEventsTest, TabVisibility) {}

// Tests that VisitedLink ignores renderer process creation notification for a
// different context.
TEST_F(VisitedLinkEventsTest, IgnoreRendererCreationFromDifferentContext) {}

// This class allows us to test PartitionedVisitedLinkWriter's inter-process
// communication via the VisitedLinkNotificationSink interface. We also test
// whether the VisitedLinkEventListener is able to connect the
// PartitionedVisitedLinkWriter's updates with each RenderProcessHost.
class PartitionedVisitedLinkEventsTest
    : public content::RenderViewHostTestHarness {};

TEST_F(PartitionedVisitedLinkEventsTest, Coalescence) {}

TEST_F(PartitionedVisitedLinkEventsTest, Basics) {}

TEST_F(PartitionedVisitedLinkEventsTest, TabVisibility) {}

// Tests that VisitedLink ignores renderer process creation notification for a
// different context.
TEST_F(PartitionedVisitedLinkEventsTest,
       IgnoreRendererCreationFromDifferentContext) {}

class VisitedLinkCompletelyResetEventTest : public VisitedLinkEventsTest {};

TEST_F(VisitedLinkCompletelyResetEventTest, LoadTable) {}

}  // namespace visitedlink