#include "base/test/scoped_feature_list.h"
#include "content/browser/renderer_host/frame_tree.h"
#include "content/browser/renderer_host/navigation_controller_impl.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/features.h"
#include "content/public/test/back_forward_cache_util.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/test_navigation_observer.h"
#include "content/shell/browser/shell.h"
#include "content/shell/common/shell_switches.h"
#include "content/test/content_browser_test_utils_internal.h"
#include "content/test/render_document_feature.h"
#include "net/dns/mock_host_resolver.h"
namespace content {
namespace {
bool RendererLocationReplace(Shell* shell, const GURL& url) { … }
}
class NavigationControllerHistoryInterventionBrowserTest
: public ContentBrowserTest,
public ::testing::WithParamInterface<
std::tuple<std::string ,
bool >> { … };
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
NoUserActivationSetSkipOnBackForward) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
NoUserActivationSetSkipOnBackForwardCrossSite) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
NoUserActivationAfterReturningSetsSkippable) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
NoUserActivationSetSkippableMultipleGoBack) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
NoUserActivationSetSkippableMultipleGoForward) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
DoNotResetSkipOnBackForward) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
DoNotResetSkipOnHistoryBackAPI) { … }
namespace {
class CanGoBackNavigationStateChangedDelegate : public WebContentsDelegate { … };
}
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
TestHonorStickyActivationForHistoryIntervention) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
TestHonorStickyActivationForHistoryInterventionForward) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
HonorStickyActivationForHistoryInterventionReset) { … }
IN_PROC_BROWSER_TEST_P(
NavigationControllerHistoryInterventionBrowserTest,
HonorStickyActivationForHistoryInterventionNotResetOnReplaceState) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
TestStickyActivationOnReload) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
TestHonorStickyActivationCrossDocument) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
TestHonorStickyActivationWithChildFrame) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
TestHonorStickyActivationWithChildFrameCrossDocument) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
OnUserGestureResetSameDocumentEntriesSkipFlag) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
OnUserGestureDoNotResetDifferentDocumentEntrySkipFlag) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
UserActivationDoNotSkipOnBackForward) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
BrowserInitiatedNavigationDoNotSkipOnBackForward) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
SetSkipOnBackDoNotSkipForHistoryBackAPI) { … }
#if BUILDFLAG(IS_ANDROID)
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
GoToOffsetWithSkippingEnableHistoryIntervention) {
base::HistogramTester histograms;
GURL non_skippable_url(
embedded_test_server()->GetURL("/frame_tree/top.html"));
EXPECT_TRUE(NavigateToURL(shell(), non_skippable_url));
GURL skippable_url(embedded_test_server()->GetURL("/title1.html"));
EXPECT_TRUE(NavigateToURL(shell(), skippable_url));
FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
->GetPrimaryFrameTree()
.root();
EXPECT_FALSE(root->HasStickyUserActivation());
EXPECT_FALSE(root->HasTransientUserActivation());
GURL redirected_url(embedded_test_server()->GetURL("/title2.html"));
EXPECT_TRUE(
NavigateToURLFromRendererWithoutUserGesture(shell(), redirected_url));
GURL skippable_url2(embedded_test_server()->GetURL("/title3.html"));
EXPECT_TRUE(NavigateToURL(shell(), skippable_url2));
EXPECT_FALSE(root->HasStickyUserActivation());
EXPECT_FALSE(root->HasTransientUserActivation());
GURL redirected_url2(embedded_test_server()->GetURL("/title4.html"));
EXPECT_TRUE(
NavigateToURLFromRendererWithoutUserGesture(shell(), redirected_url2));
NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>(
shell()->web_contents()->GetController());
EXPECT_TRUE(controller.CanGoToOffset(-3));
EXPECT_TRUE(controller.CanGoToOffset(-4));
EXPECT_FALSE(controller.CanGoToOffsetWithSkipping(-3));
TestNavigationObserver nav_observer(shell()->web_contents());
controller.GoToOffset(-4);
nav_observer.Wait();
EXPECT_EQ(0, controller.GetCurrentEntryIndex());
EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
EXPECT_EQ(non_skippable_url, controller.GetLastCommittedEntry()->GetURL());
}
#endif
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
SetSkipOnBackForwardDoNotSkipForGoToOffset) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
SetSkipOnBackForwardDoSkipForGoToOffsetWithSkipping) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
SetSkipOnBackDoNotSkipForHistoryForwardAPI) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
PruneOldestSkippableEntry) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
PruneOldestWhenLastCommittedIsSkippable) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
NoUserActivationSetSkipOnBackForwardSubframe) { … }
IN_PROC_BROWSER_TEST_P(
NavigationControllerHistoryInterventionBrowserTest,
UserActivationMainFrameDoNotSetSkipOnBackForwardSubframe) { … }
IN_PROC_BROWSER_TEST_P(NavigationControllerHistoryInterventionBrowserTest,
SetSkipOnBackForwardSameDocumentEntries) { … }
INSTANTIATE_TEST_SUITE_P(…);
}