chromium/chrome/browser/tpcd/http_error_observer/http_error_tab_helper_browsertest.cc

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

#include "chrome/browser/tpcd/http_error_observer/http_error_tab_helper.h"

#include <string_view>

#include "base/feature_list.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/ukm/test_ukm_recorder.h"
#include "content/public/common/content_paths.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/controllable_http_response.h"
#include "net/test/embedded_test_server/default_handlers.h"
#include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"

constexpr char kHostA[] =;
constexpr char kHostB[] =;

namespace {
// Handles Favicon requests so they don't produce a 404 and augment http error
// metrics during a test
std::unique_ptr<net::test_server::HttpResponse> HandleFaviconRequest(
    const net::test_server::HttpRequest& request) {}
}  // namespace

class HTTPErrProcBrowserTest : public InProcessBrowserTest {};

// Verify that Metric only registers HTTP errors
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, NoErr) {}

// Check that the ThirdPartyCookieBreakageIndicator UKM is sent on HTTP Error
// without cookies blocked
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, WithCookiesWithErr) {}

// Check that the ThirdPartyCookieBreakageIndicator UKM is sent on HTTP Error
// with cookies blocked in settings
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, TPCBlockedInSettings4xxErr) {}

// Check that the ThirdPartyCookieBreakageIndicator UKM works with image
// subresources
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, TPCBlockedImageErr) {}

// Check that the ThirdPartyCookieBreakageIndicator UKM works with fetches
// TODO(crbug.com/40938887): Fix flakiness and re-enable.
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, DISABLED_TPCBlockedFetchErr) {}

// Check that ThirdPartyCookieBreakageIndicator UKM works with subresource loads
// within iframes
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, TPCBlockedIframeErr) {}

// Check that the ThirdPartyCookieBreakageIndicator UKM is sent on Server Error.
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, TPCBlocked5xxErr) {}

// Verify that ThirdPartyCookieBreakageIndicator UKM has correct value
// when TPC are blocked in settings and by site
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, TPCBlocked4xxErr) {}

// Check that multiple entries are entered correctly.
// TODO(crbug.com/40287588): Fix flakiness and re-enable.
IN_PROC_BROWSER_TEST_F(HTTPErrProcBrowserTest, DISABLED_MultiErrs) {}