// Copyright 2014 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/renderer_host/navigator.h" #include <stdint.h> #include "base/feature_list.h" #include "base/test/test_simple_task_runner.h" #include "base/time/time.h" #include "build/build_config.h" #include "content/browser/renderer_host/navigation_controller_impl.h" #include "content/browser/renderer_host/navigation_entry_impl.h" #include "content/browser/renderer_host/navigation_request.h" #include "content/browser/renderer_host/navigation_request_info.h" #include "content/browser/renderer_host/render_frame_host_manager.h" #include "content/browser/site_info.h" #include "content/browser/site_instance_impl.h" #include "content/common/content_navigation_policy.h" #include "content/common/frame.mojom.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/common/content_features.h" #include "content/public/common/url_constants.h" #include "content/public/common/url_utils.h" #include "content/public/test/back_forward_cache_util.h" #include "content/public/test/mock_render_process_host.h" #include "content/public/test/navigation_simulator.h" #include "content/public/test/test_navigation_throttle_inserter.h" #include "content/public/test/test_utils.h" #include "content/test/navigation_simulator_impl.h" #include "content/test/task_runner_deferring_throttle.h" #include "content/test/test_navigation_url_loader.h" #include "content/test/test_render_frame_host.h" #include "content/test/test_web_contents.h" #include "net/base/load_flags.h" #include "net/http/http_response_headers.h" #include "net/url_request/redirect_info.h" #include "ui/base/page_transition_types.h" #include "url/url_constants.h" namespace content { namespace { // Helper function that determines if a test should expect a cross-site // navigation to trigger a SiteInstance change based on the current process // model. bool ExpectSiteInstanceChange(SiteInstanceImpl* site_instance) { … } // Same as above but does not return true if back/forward cache is the only // trigger for SiteInstance change. This function is useful if, e.g. the test // intends to disable back/forward cache. bool ExpectSiteInstanceChangeWithoutBackForwardCache( SiteInstanceImpl* site_instance) { … } } // namespace class NavigatorTest : public RenderViewHostImplTestHarness { … }; // Tests a complete browser-initiated navigation starting with a non-live // renderer. TEST_F(NavigatorTest, SimpleBrowserInitiatedNavigationFromNonLiveRenderer) { … } // Tests a complete renderer-initiated same-site navigation. TEST_F(NavigatorTest, SimpleRendererInitiatedSameSiteNavigation) { … } // Tests a complete renderer-initiated navigation that should be // cross-site but does not result in a SiteInstance swap because its // renderer-initiated. TEST_F(NavigatorTest, SimpleRendererInitiatedCrossSiteNavigation) { … } // Tests that when a navigation to about:blank is renderer-aborted, // after another cross-site navigation has been initiated, that the // second navigation is undisturbed. TEST_F(NavigatorTest, RendererAbortedAboutBlankNavigation) { … } // Tests that when a navigation to about:blank is renderer-aborted, // after another cross-site navigation has been initiated, that the // second navigation is undisturbed. In this variation, the second // navigation is initially same-site, then redirects cross-site, // and a throttle DEFERs during WillProcessResponse(). The initial // navigation gets aborted during this defer. TEST_F(NavigatorTest, RedirectedRendererAbortedAboutBlankNavigationwithDeferredCommit) { … } // Tests that a beforeUnload denial cancels the navigation. TEST_F(NavigatorTest, BeforeUnloadDenialCancelNavigation) { … } // Test that a proper NavigationRequest is created at navigation start. TEST_F(NavigatorTest, BeginNavigation) { … } // Tests that committing an HTTP 204 or HTTP 205 response cancels // the navigation. TEST_F(NavigatorTest, NoContent) { … } // Test that a new RenderFrameHost is created when doing a cross site // navigation. TEST_F(NavigatorTest, CrossSiteNavigation) { … } // Test that redirects are followed and the speculative RenderFrameHost logic // behaves as expected. TEST_F(NavigatorTest, RedirectCrossSite) { … } // Test that a navigation is canceled if another browser-initiated request has // been issued in the meantime. Also confirms that the speculative // RenderFrameHost is correctly updated in the process. TEST_F(NavigatorTest, BrowserInitiatedNavigationCancel) { … } // Test that a browser-initiated navigation is canceled if a renderer-initiated // user-initiated request has been issued in the meantime. TEST_F(NavigatorTest, RendererUserInitiatedNavigationCancel) { … } // Tests that a renderer-initiated user-initiated navigation is // canceled if a renderer-initiated non-user-initiated request is issued in the // meantime. TEST_F(NavigatorTest, RendererNonUserInitiatedNavigationCancelsRendererUserInitiated) { … } // PlzNavigate: Test that a browser-initiated navigation is NOT canceled if a // renderer-initiated non-user-initiated request is issued in the meantime. TEST_F(NavigatorTest, RendererNonUserInitiatedNavigationDoesntCancelBrowserInitiated) { … } // PlzNavigate: Test that a renderer-initiated non-user-initiated navigation is // canceled if a another similar request is issued in the meantime. TEST_F(NavigatorTest, RendererNonUserInitiatedNavigationCancelSimilarNavigation) { … } // PlzNavigate: Test that a reload navigation is properly signaled to the // RenderFrame when the navigation can commit. A speculative RenderFrameHost // should not be created at any step, unless RenderDocument is enabled. TEST_F(NavigatorTest, Reload) { … } // PlzNavigate: Confirm that a speculative RenderFrameHost is used when // navigating from one site to another. TEST_F(NavigatorTest, SpeculativeRendererWorksBaseCase) { … } // PlzNavigate: Confirm that a speculative RenderFrameHost is thrown away when // the final URL's site differs from the initial one due to redirects. TEST_F(NavigatorTest, SpeculativeRendererDiscardedAfterRedirectToAnotherSite) { … } // PlzNavigate: Verify that data urls are properly handled. TEST_F(NavigatorTest, DataUrls) { … } // Tests several cases for converting SiteInstanceDescriptors into // SiteInstances: // 1) Pointer to the current SiteInstance. // 2) Pointer to an unrelated SiteInstance. // 3) Same-site URL, related. // 4) Cross-site URL, related. // 5) Same-site URL, unrelated (with and without candidate SiteInstances). // 6) Cross-site URL, unrelated (with candidate SiteInstance). TEST_F(NavigatorTest, SiteInstanceDescriptionConversion) { … } // A renderer process might try and claim that a cross site navigation was // within the same document by setting was_within_same_document = true in // DidCommitProvisionalLoadParams. Such case should be detected on the browser // side and the renderer process should be killed. TEST_F(NavigatorTest, CrossSiteClaimWithinPage) { … } // Permissions Policy: Test that the permissions policy is reset when navigating // pages within a site. TEST_F(NavigatorTest, PermissionsPolicySameSiteNavigation) { … } // Permissions Policy: Test that the permissions policy is not reset when // navigating within a page. TEST_F(NavigatorTest, PermissionsPolicyFragmentNavigation) { … } // Permissions Policy: Test that the permissions policy is set correctly when // inserting a new child frame. TEST_F(NavigatorTest, PermissionsPolicyNewChild) { … } TEST_F(NavigatorTest, TwoNavigationsRacingCommit) { … } } // namespace content