chromium/chrome/browser/preloading/latency_ablation_browsertest.cc

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

#include <memory>

#include "base/feature_list.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/chrome_test_utils.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/search_test_utils.h"
#include "components/search_engines/template_url_data.h"
#include "components/search_engines/template_url_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_mock_cert_verifier.h"
#include "content/public/test/prerender_test_util.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"

namespace {

BasicHttpResponse;
HttpRequest;
HttpResponse;

constexpr static char kSearchDomain[] =;
constexpr static char kSuggestionDomain[] =;
constexpr static char16_t kSearchDomain16[] =;

// Copy of the feature here to test the actual feature string.
BASE_FEATURE();

std::unique_ptr<HttpResponse> ReturnOKResponseForAllRequests(
    const HttpRequest& request) {}

}  // namespace

class LatencyAblationBrowserTest : public InProcessBrowserTest {};

// Check that the default behavior is that there is no ablation.
IN_PROC_BROWSER_TEST_F(LatencyAblationBrowserTest, DenyIPAddress) {}

class LatencyAblationDisabledBrowserTest : public LatencyAblationBrowserTest {};

// Check that when the feature is off, there is no ablation.
IN_PROC_BROWSER_TEST_F(LatencyAblationDisabledBrowserTest, DenyIPAddress) {}

class LatencyAblationEnabledBrowserTest : public LatencyAblationBrowserTest {};

// Check that IP navigations are not ablated when there is a duration
// configured. Use the histogram as a proxy for actual ablation.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledBrowserTest, DontAblateIPAddress) {}

// Check that prerender navigations and activations are not ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledBrowserTest, DontAblatePrerender) {}

// Search query navigations should be ablated by default.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledBrowserTest, AblateNonSearch) {}

// Search navigations should be ablated by default.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledBrowserTest, AblateSearchHost) {}

// Search hosts that are not search queries should be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledBrowserTest,
                       AblateSearchRealtedHost) {}

// Search queries should be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledBrowserTest, AblateSearchQuery) {}

class LatencyAblationEnabledSearchQueryDisabledBrowserTest
    : public LatencyAblationBrowserTest {};

// Non search queries should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchQueryDisabledBrowserTest,
                       AblateNonSearch) {}

// Search hosts that aren't queries should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchQueryDisabledBrowserTest,
                       AblateSearchHost) {}

// Search related hosts should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchQueryDisabledBrowserTest,
                       AblateSearchRealtedHost) {}

// With "ablate_default_search_queries" set to "false" search queries should not
// be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchQueryDisabledBrowserTest,
                       DoNotAblateSearchQuery) {}

class LatencyAblationEnabledSearchHostDisabledBrowserTest
    : public LatencyAblationBrowserTest {};

// Non search navigations should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchHostDisabledBrowserTest,
                       AblateNonSearch) {}

// With "ablate_default_search_host" set to "false", search hosts that aren't
// queries should be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchHostDisabledBrowserTest,
                       DoNotAblateSearchHost) {}

// With "ablate_default_search_host" set to "false", search related hosts that
// aren't queries should be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchHostDisabledBrowserTest,
                       DoNotAblateSearchRealtedHost) {}

// With "ablate_default_search_host" set to "false", search queries should still
// be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledSearchHostDisabledBrowserTest,
                       AblateSearchQuery) {}

class LatencyAblationEnabledNonSearchDisabledBrowserTest
    : public LatencyAblationBrowserTest {};

// With "ablate_non_default_search_host" set to "false", non search should not
// be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledNonSearchDisabledBrowserTest,
                       DoNotAblateNonSearch) {}

// Search host should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledNonSearchDisabledBrowserTest,
                       DoNotAblateSearchHost) {}

// Search related hosts should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledNonSearchDisabledBrowserTest,
                       AblateSearchRealtedHost) {}

// Search queries should still be ablated.
IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledNonSearchDisabledBrowserTest,
                       AblateSearchQuery) {}

// Test Latency Ablation based on pattern.
class LatencyAblationEnabledPatternBrowserTest
    : public LatencyAblationBrowserTest {};

IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledPatternBrowserTest,
                       AblatePattern) {}

IN_PROC_BROWSER_TEST_F(LatencyAblationEnabledPatternBrowserTest,
                       DoNotAblateIfNotMatch) {}