chromium/content/browser/attribution_reporting/source_declaration_browsertest.cc

// Copyright 2020 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/json/json_writer.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "base/threading/platform_thread.h"
#include "base/values.h"
#include "build/build_config.h"
#include "content/browser/attribution_reporting/attribution_manager_impl.h"
#include "content/browser/attribution_reporting/attribution_test_utils.h"
#include "content/browser/attribution_reporting/test/source_observer.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/features.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/context_menu_interceptor.h"
#include "content/public/test/hit_test_region_observer.h"
#include "content/shell/browser/shell.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 "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/input/web_mouse_event.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "url/gurl.h"

namespace content {

namespace {

ElementsAre;
Field;
IsEmpty;
Pair;
Pointee;
UnorderedElementsAre;

class AttributionSourceBrowserTest : public ContentBrowserTest {};

class AttributionSourceDisabledBrowserTest : public AttributionSourceBrowserTest {};

// Verifies that impressions are not logged when the Runtime feature isn't
// enabled.
IN_PROC_BROWSER_TEST_F(AttributionSourceDisabledBrowserTest,
                       ImpressionWithoutFeatureEnabled_NotReceived) {}

class AttributionSourceDeclarationBrowserTest
    : public AttributionSourceBrowserTest {};

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionTagNavigatesRemoteFrame_ImpressionReceived) {}

// Flaky: crbug.com/1077216
IN_PROC_BROWSER_TEST_F(
    AttributionSourceDeclarationBrowserTest,
    DISABLED_ImpressionTagNavigatesExistingRemoteFrame_ImpressionReceived) {}

IN_PROC_BROWSER_TEST_F(
    AttributionSourceDeclarationBrowserTest,
    ImpressionTagNavigatesFromMiddleClick_ImpressionReceived) {}

// See https://crbug.com/1186077.
IN_PROC_BROWSER_TEST_F(
    AttributionSourceDeclarationBrowserTest,
    TagNavigatesFromMiddleClickInSubframe_ImpressionReceived) {}

// https://crbug.com/1219907 started flaking after Field Trial Testing Config
// was enabled for content_browsertests.
IN_PROC_BROWSER_TEST_F(
    AttributionSourceDeclarationBrowserTest,
    DISABLED_ImpressionTagNavigatesFromEnterPress_ImpressionReceived) {}

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionOnInsecureSite_NotRegistered) {}

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionWithInsecureReportingOrigin_ReceivesToken) {}

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionWithPermissionsPolicyDisabled_NotRegistered) {}

IN_PROC_BROWSER_TEST_F(
    AttributionSourceDeclarationBrowserTest,
    ImpressionInSubframeWithoutPermissionsPolicy_Registered) {}

IN_PROC_BROWSER_TEST_F(
    AttributionSourceDeclarationBrowserTest,
    ImpressionInSubframeWithPermissionsPolicyDisabled_NotRegistered) {}

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionInSubframeWithPermissionsPolicy_Registered) {}

// Tests that when a context menu is shown, there is an impression attached to
// the ContextMenu data forwarded to the browser process.

// TODO(johnidel): SimulateMouseClickAt() does not work on Android, find a
// different way to invoke the context menu that works on Android.
// https://crbug.com/1219907 started flaking after Field Trial Testing Config
// was enabled for content_browsertests.
#if !BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       DISABLED_ContextMenuShownForImpression_ImpressionSet) {}
#endif  // !BUILDFLAG(IS_ANDROID)

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionNavigationReloads_NoImpression) {}

// Same as the above test but via a renderer initiated reload.
IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       RendererReloadImpressionNavigation_NoImpression) {}

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       BackNavigateToImpressionNavigation_NoImpression) {}

IN_PROC_BROWSER_TEST_F(AttributionSourceDeclarationBrowserTest,
                       ImpressionInSubframeInInsecureContext_NotRegistered) {}

}  // namespace
}  // namespace content