chromium/content/browser/site_per_process_sad_frame_browsertest.cc

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

#include "content/browser/site_per_process_browsertest.h"

#include "build/build_config.h"
#include "content/browser/renderer_host/cross_process_frame_connector.h"
#include "content/browser/renderer_host/frame_tree.h"
#include "content/browser/renderer_host/render_frame_proxy_host.h"
#include "content/common/features.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/fenced_frame_test_util.h"
#include "content/shell/browser/shell.h"
#include "content/test/render_document_feature.h"
#include "content/test/render_widget_host_visibility_observer.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace content {

namespace {

// Helper class to wait for the next sad frame to be shown in a specific
// FrameTreeNode.  This can be used to wait for sad frame visibility metrics to
// be logged.
class SadFrameShownObserver {};

}  // namespace

// Disable the feature to mark hidden tabs with sad frames for reload, for use
// in tests where this feature interferes with the behavior being tested.
class SitePerProcessBrowserTestWithoutSadFrameTabReload
    : public SitePerProcessBrowserTest {};

// This test is flaky on all platforms.
// TODO(crbug.com/40749527): Deflake it and enable this test back.
IN_PROC_BROWSER_TEST_P(
    SitePerProcessBrowserTestWithoutSadFrameTabReload,
    DISABLED_ChildFrameCrashMetrics_KilledWhileHiddenThenShown) {}

IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithoutSadFrameTabReload,
                       ChildFrameCrashMetrics_ScrolledIntoViewAfterTabIsShown) {}

class SitePerProcessBrowserTestWithSadFrameTabReload
    : public SitePerProcessBrowserTest {};

// Verify the feature where hidden tabs with a visible crashed subframe are
// marked for reload. This avoids showing crashed subframes if a hidden tab is
// eventually shown. See https://crbug.com/841572.
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload,
                       ReloadHiddenTabWithCrashedSubframeInViewport) {}

// Verify that when a tab is reloaded because it was previously marked for
// reload due to having a sad frame, we log the sad frame as shown during a tab
// reload, rather than being shown to the user directly, since the sad frame is
// expected to go away shortly. See https://crbug.com/1132938.
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload,
                       CrashedSubframeVisibilityMetricsDuringTabReload) {}

// Verify that a sad frame shown when its parent frame is loading is logged
// with appropriate metrics, namely as kShownWhileAncestorIsLoading rather than
// kShownAfterCrashing. See https://crbug.com/1132938.
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload,
                       CrashedSubframeVisibilityMetricsDuringParentLoad) {}

// Verify that a sad frame shown when its parent frame is loading is logged
// with appropriate metrics, namely as kShownWhileAncestorIsLoading rather than
// kShownAfterCrashing. See https://crbug.com/1132938.
IN_PROC_BROWSER_TEST_P(
    SitePerProcessBrowserTestWithSadFrameTabReload,
    // TODO(crbug.com/40839850): Re-enable this test
    DISABLED_CrashedFencedframeVisibilityMetricsDuringParentLoad) {}

// Verify the feature where hidden tabs with crashed subframes are marked for
// reload. This avoids showing crashed subframes if a hidden tab is eventually
// shown. Similar to the test above, except that the crashed subframe is
// scrolled out of view.
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload,
                       // TODO(crbug.com/40870019): Re-enable this test
                       DISABLED_ReloadHiddenTabWithCrashedSubframeOutOfView) {}

// Verify that hidden tabs with a crashed subframe are not marked for reload
// when the crashed subframe is hidden with "display:none".
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload,
                       DoNotReloadHiddenTabWithHiddenCrashedSubframe) {}

// Ensure that the sad frame reload policy doesn't trigger for a visible tab,
// even if it becomes hidden and then visible again.
IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTestWithSadFrameTabReload,
                       DoNotReloadVisibleTabWithCrashedSubframe) {}

IN_PROC_BROWSER_TEST_P(SitePerProcessBrowserTest,
                       // TODO(crbug.com/40870019): Re-enable this test
                       DISABLED_ChildFrameCrashMetrics_KilledWhileVisible) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

}  // namespace content