#include "content/browser/renderer_host/navigation_controller_impl.h"
#include <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <memory>
#include <string>
#include <tuple>
#include <utility>
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "content/browser/browser_url_handler_impl.h"
#include "content/browser/renderer_host/frame_navigation_entry.h"
#include "content/browser/renderer_host/navigation_entry_impl.h"
#include "content/browser/renderer_host/navigation_entry_restore_context_impl.h"
#include "content/browser/renderer_host/navigation_request.h"
#include "content/browser/renderer_host/navigator.h"
#include "content/browser/site_instance_impl.h"
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/content_navigation_policy.h"
#include "content/common/frame.mojom.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/page_type.h"
#include "content/public/common/url_constants.h"
#include "content/public/test/back_forward_cache_util.h"
#include "content/public/test/fake_local_frame.h"
#include "content/public/test/mock_render_process_host.h"
#include "content/public/test/navigation_simulator.h"
#include "content/public/test/scoped_web_ui_controller_factory_registration.h"
#include "content/public/test/test_navigation_ui_data.h"
#include "content/public/test/test_utils.h"
#include "content/test/navigation_simulator_impl.h"
#include "content/test/test_render_frame_host.h"
#include "content/test/test_render_view_host.h"
#include "content/test/test_web_contents.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "services/network/public/cpp/resource_request_body.h"
#include "skia/ext/platform_canvas.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/frame/frame_policy.h"
#include "third_party/blink/public/common/page/browsing_context_group_info.h"
#include "third_party/blink/public/common/page_state/page_state.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
#include "third_party/blink/public/mojom/frame/remote_frame.mojom.h"
#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
Time;
namespace {
base::Time InMicrosecondsSinceEpoch(int64_t us) { … }
gfx::Image CreateImage(SkColor color) { … }
bool DoImagesMatch(const gfx::Image& a, const gfx::Image& b) { … }
class MockPageBroadcast : public blink::mojom::PageBroadcast { … };
}
namespace content {
TEST(TimeSmoother, Basic) { … }
TEST(TimeSmoother, SingleDuplicate) { … }
TEST(TimeSmoother, ManyDuplicates) { … }
TEST(TimeSmoother, ClockBackwardsJump) { … }
class NavigationControllerTest : public RenderViewHostImplTestHarness,
public WebContentsObserver { … };
class TestWebContentsDelegate : public WebContentsDelegate { … };
class LoadCommittedDetailsObserver : public WebContentsObserver { … };
class NavigationControllerTestWithBrowserSideNavigation
: public NavigationControllerTest { … };
TEST_F(NavigationControllerTest, Defaults) { … }
TEST_F(NavigationControllerTest, GoToOffset) { … }
TEST_F(NavigationControllerTest, LoadURL) { … }
namespace {
base::Time GetFixedTime(base::Time time) { … }
}
TEST_F(NavigationControllerTest, LoadURLSameTime) { … }
void CheckNavigationEntryMatchLoadParams(
const NavigationController::LoadURLParams& load_params,
NavigationEntryImpl* entry) { … }
TEST_F(NavigationControllerTest, LoadURLWithParams) { … }
TEST_F(NavigationControllerTest, LoadURLWithParams_Reload) { … }
TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data) { … }
#if BUILDFLAG(IS_ANDROID)
TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Data_Android) {
NavigationControllerImpl& controller = controller_impl();
GURL url("data:,");
auto navigation =
NavigationSimulatorImpl::CreateBrowserInitiated(url, contents());
NavigationController::LoadURLParams load_url_params(url);
load_url_params.load_type = NavigationController::LOAD_TYPE_DATA;
load_url_params.base_url_for_data_url = GURL("http://foo");
load_url_params.virtual_url_for_special_cases = GURL(url::kAboutBlankURL);
load_url_params.data_url_as_string =
base::MakeRefCounted<base::RefCountedString>(std::string("data:,data"));
load_url_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
navigation->SetLoadURLParams(&load_url_params);
navigation->Start();
NavigationEntryImpl* entry = controller.GetPendingEntry();
CheckNavigationEntryMatchLoadParams(load_url_params, entry);
}
TEST_F(NavigationControllerTest, LoadURLWithExtraParams_Pdf_Android) {
NavigationControllerImpl& controller = controller_impl();
GURL url("chrome-native://pdf/link?url=https%3A%2F%2Ffoo");
auto navigation =
NavigationSimulatorImpl::CreateBrowserInitiated(url, contents());
NavigationController::LoadURLParams load_url_params(url);
load_url_params.load_type = NavigationController::LOAD_TYPE_PDF_ANDROID;
load_url_params.virtual_url_for_special_cases = GURL("https://foo");
load_url_params.override_user_agent = NavigationController::UA_OVERRIDE_FALSE;
navigation->SetLoadURLParams(&load_url_params);
navigation->Start();
NavigationEntryImpl* entry = controller.GetPendingEntry();
CheckNavigationEntryMatchLoadParams(load_url_params, entry);
}
#endif
TEST_F(NavigationControllerTest, KeepReloadTypeWhenCancelRepost) { … }
TEST_F(NavigationControllerTest, LoadURLWithExtraParams_HttpPost) { … }
TEST_F(NavigationControllerTest, LoadURL_SamePage) { … }
TEST_F(NavigationControllerTest, LoadURL_Discarded) { … }
TEST_F(NavigationControllerTest, LoadURL_NoPending) { … }
TEST_F(NavigationControllerTest, LoadURL_NewPending) { … }
TEST_F(NavigationControllerTest, LoadURL_ExistingPending) { … }
TEST_F(NavigationControllerTest, LoadURL_PrivilegedPending) { … }
TEST_F(NavigationControllerTest, LoadURL_BackPreemptsPending) { … }
TEST_F(NavigationControllerTest, LoadURL_IgnorePreemptsPending) { … }
TEST_F(NavigationControllerTest, LoadURL_AbortDoesntCancelPending) { … }
TEST_F(NavigationControllerTest, LoadURL_RedirectAbortDoesntShowPendingURL) { … }
TEST_F(NavigationControllerTest, Reload) { … }
TEST_F(NavigationControllerTest, Reload_GeneratesNewPage) { … }
TEST_F(NavigationControllerTest, ReloadWithGuest) { … }
TEST_F(NavigationControllerTest, ReloadOriginalRequestURL) { … }
TEST_F(NavigationControllerTest, ResetEntryValuesAfterCommit) { … }
TEST_F(NavigationControllerTest, RedirectsAreNotResetByCommit) { … }
TEST_F(NavigationControllerTest, GoBackWithUserAgentOverrideChange) { … }
TEST_F(NavigationControllerTest, Back) { … }
TEST_F(NavigationControllerTest, Back_GeneratesNewPage) { … }
TEST_F(NavigationControllerTest, Back_NewPending) { … }
TEST_F(NavigationControllerTest, Forward) { … }
TEST_F(NavigationControllerTest, Forward_GeneratesNewPage) { … }
TEST_F(NavigationControllerTest, ImmediateRedirect) { … }
TEST_F(NavigationControllerTest,
NavigationTypeClassification_ExistingEntryRace) { … }
TEST_F(NavigationControllerTest, NewSubframe) { … }
TEST_F(NavigationControllerTest, AutoSubframe) { … }
TEST_F(NavigationControllerTest, BackSubframe) { … }
TEST_F(NavigationControllerTest, LinkClick) { … }
TEST_F(NavigationControllerTest, SameDocument) { … }
TEST_F(NavigationControllerTest, SameDocument_Replace) { … }
TEST_F(NavigationControllerTest, PushStateWithOnlyInitialEntry) { … }
TEST_F(NavigationControllerTest, EnforceMaxNavigationCount) { … }
TEST_F(NavigationControllerTest, RestoreNavigate) { … }
TEST_F(NavigationControllerTest, RestoreNavigateAfterFailure) { … }
TEST_F(NavigationControllerTest, RemoveEntry) { … }
TEST_F(NavigationControllerTest, RemoveEntryWithPending) { … }
TEST_F(NavigationControllerTest, RendererInitiatedPendingEntries) { … }
TEST_F(NavigationControllerTest, DontShowRendererURLUntilCommit) { … }
TEST_F(NavigationControllerTest, ShowRendererURLInNewTabUntilModified) { … }
TEST_F(NavigationControllerTest, ShowBrowserURLAfterFailUntilModified) { … }
TEST_F(NavigationControllerTest, ShowRendererURLAfterFailUntilModified) { … }
TEST_F(NavigationControllerTest, ShowRendererURLAfterCancelUntilModified) { … }
TEST_F(NavigationControllerTest, DontShowRendererURLInNewTabAfterCommit) { … }
TEST_F(NavigationControllerTest, SameSubframe) { … }
TEST_F(NavigationControllerTest, CloneAndGoBack) { … }
TEST_F(NavigationControllerTest, CloneAndReload) { … }
TEST_F(NavigationControllerTest, LazyReload) { … }
TEST_F(NavigationControllerTest, LazyReloadWithOnlyInitialEntry) { … }
TEST_F(NavigationControllerTest, LazyReloadWithOnlyInitialAndPendingEntry) { … }
TEST_F(NavigationControllerTest, SubframeWhilePending) { … }
TEST_F(NavigationControllerTest, CopyStateFrom) { … }
TEST_F(NavigationControllerTest, DeleteNavigationEntries) { … }
TEST_F(NavigationControllerTest, HistoryNavigate) { … }
TEST_F(NavigationControllerTest, PruneAllButLastCommittedForSingle) { … }
TEST_F(NavigationControllerTest, PruneAllButLastCommittedForFirst) { … }
TEST_F(NavigationControllerTest, PruneAllButLastCommittedForIntermediate) { … }
TEST_F(NavigationControllerTest, PruneAllButLastCommittedForPendingNotInList) { … }
TEST_F(NavigationControllerTest, StopOnHistoryNavigationToCurrentPage) { … }
TEST_F(NavigationControllerTest, IsInitialNavigation) { … }
TEST_F(NavigationControllerTest, ClearFaviconOnRedirect) { … }
TEST_F(NavigationControllerTest, BackNavigationDoesNotClearFavicon) { … }
TEST_F(NavigationControllerTest, PushStateUpdatesTitleAndFavicon) { … }
TEST_F(NavigationControllerTest, ClearHistoryList) { … }
TEST_F(NavigationControllerTest, StaleNavigationsResurrected) { … }
TEST_F(NavigationControllerTest, MultipleNavigationsAndReload) { … }
TEST_F(NavigationControllerTest, MainFrameNavigationUIData) { … }
TEST_F(NavigationControllerTest, MainFrameNavigationReloadType) { … }
TEST_F(NavigationControllerTest, SubFrameNavigationUIData) { … }
bool SrcDocRewriter(GURL* url, BrowserContext* browser_context) { … }
TEST_F(NavigationControllerTest, NoURLRewriteForSubframes) { … }
TEST_F(NavigationControllerTest,
NavigateFromFrameProxyWithReplacementWithOnlyInitialEntry) { … }
TEST_F(NavigationControllerTest, PruneForwardEntries) { … }
TEST_F(NavigationControllerTest, PruneForwardEntriesAfterClone) { … }
TEST_F(NavigationControllerTest,
NavigateToNavigationApiKey_DifferentSiteInstance) { … }
TEST_F(NavigationControllerTest, NavigateToNavigationApiKey_KeyForWrongFrame) { … }
class FakeLocalFrameWithDisposedEntries : public content::FakeLocalFrame { … };
TEST_F(NavigationControllerTest, NavigationApiDisposedEntries) { … }
class PageBroadcastMockInserter : public WebContentsObserver { … };
TEST_F(NavigationControllerTest, BrowsingContextGroupUpdate) { … }
class NavigationControllerFencedFrameTest : public NavigationControllerTest { … };
TEST_F(NavigationControllerFencedFrameTest, NoURLRewriteForFencedFrames) { … }
}