OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/frame_host/navigation_controller_impl.h" | 5 #include "content/browser/frame_host/navigation_controller_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 5059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5070 : WebContentsObserver(web_contents) {} | 5070 : WebContentsObserver(web_contents) {} |
5071 ~RenderProcessKilledObserver() override {} | 5071 ~RenderProcessKilledObserver() override {} |
5072 | 5072 |
5073 void RenderProcessGone(base::TerminationStatus status) override { | 5073 void RenderProcessGone(base::TerminationStatus status) override { |
5074 CHECK_NE(status, | 5074 CHECK_NE(status, |
5075 base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED); | 5075 base::TerminationStatus::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
5076 } | 5076 } |
5077 }; | 5077 }; |
5078 } | 5078 } |
5079 | 5079 |
5080 // This tests a race in ReloadOriginalRequest, where a cross-origin reload was | 5080 // This tests a race in Reload with ReloadType::ORIGINAL_REQUEST_URL, where a |
5081 // causing an in-flight replaceState to look like a cross-origin navigation, | 5081 // cross-origin reload was causing an in-flight replaceState to look like a |
5082 // even though it's in-page. (The reload should not modify the underlying last | 5082 // cross-origin navigation, even though it's in-page. (The reload should not |
5083 // committed entry.) Not crashing means that the test is successful. | 5083 // modify the underlying last committed entry.) Not crashing means that the |
| 5084 // test is successful. |
5084 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { | 5085 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, ReloadOriginalRequest) { |
5085 GURL original_url(embedded_test_server()->GetURL( | 5086 GURL original_url(embedded_test_server()->GetURL( |
5086 "/navigation_controller/simple_page_1.html")); | 5087 "/navigation_controller/simple_page_1.html")); |
5087 EXPECT_TRUE(NavigateToURL(shell(), original_url)); | 5088 EXPECT_TRUE(NavigateToURL(shell(), original_url)); |
5088 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) | 5089 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) |
5089 ->GetFrameTree() | 5090 ->GetFrameTree() |
5090 ->root(); | 5091 ->root(); |
5091 RenderProcessKilledObserver kill_observer(shell()->web_contents()); | 5092 RenderProcessKilledObserver kill_observer(shell()->web_contents()); |
5092 | 5093 |
5093 // Redirect so that we can use ReloadOriginalRequest. | 5094 // Redirect so that we can use Reload with ReloadType::ORIGINAL_REQUEST_URL. |
5094 GURL redirect_url(embedded_test_server()->GetURL( | 5095 GURL redirect_url(embedded_test_server()->GetURL( |
5095 "foo.com", "/navigation_controller/simple_page_1.html")); | 5096 "foo.com", "/navigation_controller/simple_page_1.html")); |
5096 { | 5097 { |
5097 std::string script = "location.replace('" + redirect_url.spec() + "');"; | 5098 std::string script = "location.replace('" + redirect_url.spec() + "');"; |
5098 FrameNavigateParamsCapturer capturer(root); | 5099 FrameNavigateParamsCapturer capturer(root); |
5099 EXPECT_TRUE(ExecuteScript(shell(), script)); | 5100 EXPECT_TRUE(ExecuteScript(shell(), script)); |
5100 capturer.Wait(); | 5101 capturer.Wait(); |
5101 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( | 5102 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( |
5102 capturer.params().transition, | 5103 capturer.params().transition, |
5103 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | | 5104 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_LINK | |
5104 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); | 5105 ui::PAGE_TRANSITION_CLIENT_REDIRECT))); |
5105 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); | 5106 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); |
5106 } | 5107 } |
5107 | 5108 |
5108 // Modify an entry in the session history and reload the original request. | 5109 // Modify an entry in the session history and reload the original request. |
5109 { | 5110 { |
5110 // We first send a replaceState() to the renderer, which will cause the | 5111 // We first send a replaceState() to the renderer, which will cause the |
5111 // renderer to send back a DidCommitProvisionalLoad. Immediately after, | 5112 // renderer to send back a DidCommitProvisionalLoad. Immediately after, |
5112 // we send a ReloadOriginalRequest (which in this case is a different | 5113 // we send a Reload request with ReloadType::ORIGINAL_REQUEST_URL (which in |
5113 // origin) and will also cause the renderer to commit the frame. In the | 5114 // this case is a different origin) and will also cause the renderer to |
5114 // end we verify that both navigations committed and that the URLs are | 5115 // commit the frame. In the end we verify that both navigations committed |
5115 // correct. | 5116 // and that the URLs are correct. |
5116 std::string script = "history.replaceState({}, '', 'foo');"; | 5117 std::string script = "history.replaceState({}, '', 'foo');"; |
5117 root->render_manager() | 5118 root->render_manager() |
5118 ->current_frame_host() | 5119 ->current_frame_host() |
5119 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); | 5120 ->ExecuteJavaScriptWithUserGestureForTests(base::UTF8ToUTF16(script)); |
5120 EXPECT_FALSE(shell()->web_contents()->IsLoading()); | 5121 EXPECT_FALSE(shell()->web_contents()->IsLoading()); |
5121 shell()->web_contents()->GetController().ReloadOriginalRequestURL(false); | 5122 shell()->web_contents()->GetController().Reload( |
| 5123 false, ReloadType::ORIGINAL_REQUEST_URL); |
5122 EXPECT_TRUE(shell()->web_contents()->IsLoading()); | 5124 EXPECT_TRUE(shell()->web_contents()->IsLoading()); |
5123 EXPECT_EQ(redirect_url, shell()->web_contents()->GetLastCommittedURL()); | 5125 EXPECT_EQ(redirect_url, shell()->web_contents()->GetLastCommittedURL()); |
5124 | 5126 |
5125 // Wait until there's no more navigations. | 5127 // Wait until there's no more navigations. |
5126 GURL modified_url(embedded_test_server()->GetURL( | 5128 GURL modified_url(embedded_test_server()->GetURL( |
5127 "foo.com", "/navigation_controller/foo")); | 5129 "foo.com", "/navigation_controller/foo")); |
5128 FrameNavigateParamsCapturer capturer(root); | 5130 FrameNavigateParamsCapturer capturer(root); |
5129 capturer.set_wait_for_load(false); | 5131 capturer.set_wait_for_load(false); |
5130 capturer.set_navigations_remaining(2); | 5132 capturer.set_navigations_remaining(2); |
5131 capturer.Wait(); | 5133 capturer.Wait(); |
(...skipping 1566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6698 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( | 6700 NavigationControllerImpl& controller = static_cast<NavigationControllerImpl&>( |
6699 shell()->web_contents()->GetController()); | 6701 shell()->web_contents()->GetController()); |
6700 | 6702 |
6701 // Reload triggers a reload of ReloadType::NORMAL. The first reload should | 6703 // Reload triggers a reload of ReloadType::NORMAL. The first reload should |
6702 // not be counted. | 6704 // not be counted. |
6703 controller.Reload(false); | 6705 controller.Reload(false); |
6704 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 6706 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
6705 histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); | 6707 histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); |
6706 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); | 6708 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); |
6707 | 6709 |
6708 // ReloadBypassingCache triggers a reload of ReloadType::BYPASSING_CACHE. | 6710 // Reload with ReloadType::BYPASSING_CACHE. Both metrics should count the |
6709 // Both metrics should count the consecutive reloads. | 6711 // consecutive reloads. |
6710 controller.ReloadBypassingCache(false); | 6712 controller.Reload(false, ReloadType::BYPASSING_CACHE); |
6711 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 6713 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
6712 histogram.ExpectTotalCount(kReloadToReloadMetricName, 1); | 6714 histogram.ExpectTotalCount(kReloadToReloadMetricName, 1); |
6713 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 6715 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); |
6714 | 6716 |
6715 // Triggers another reload of ReloadType::BYPASSING_CACHE. | 6717 // Triggers another reload with ReloadType::BYPASSING_CACHE. |
6716 // ReloadMainResourceToReload should not be counted here. | 6718 // ReloadMainResourceToReload should not be counted here. |
6717 controller.ReloadBypassingCache(false); | 6719 controller.Reload(false, ReloadType::BYPASSING_CACHE); |
6718 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); | 6720 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
6719 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 6721 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); |
6720 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); | 6722 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); |
6721 | 6723 |
6722 // A browser-initiated navigation should reset the reload tracking | 6724 // A browser-initiated navigation should reset the reload tracking |
6723 // information. | 6725 // information. |
6724 EXPECT_TRUE( | 6726 EXPECT_TRUE( |
6725 NavigateToURL(shell(), embedded_test_server()->GetURL( | 6727 NavigateToURL(shell(), embedded_test_server()->GetURL( |
6726 "/navigation_controller/simple_page_1.html"))); | 6728 "/navigation_controller/simple_page_1.html"))); |
6727 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); | 6729 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7030 NavigationHandleCommitObserver handle_observer(shell()->web_contents(), | 7032 NavigationHandleCommitObserver handle_observer(shell()->web_contents(), |
7031 kFragmentURL); | 7033 kFragmentURL); |
7032 EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); | 7034 EXPECT_TRUE(NavigateToURL(shell(), kFragmentURL)); |
7033 | 7035 |
7034 EXPECT_TRUE(handle_observer.has_committed()); | 7036 EXPECT_TRUE(handle_observer.has_committed()); |
7035 EXPECT_TRUE(handle_observer.was_same_page()); | 7037 EXPECT_TRUE(handle_observer.was_same_page()); |
7036 EXPECT_FALSE(handle_observer.was_renderer_initiated()); | 7038 EXPECT_FALSE(handle_observer.was_renderer_initiated()); |
7037 } | 7039 } |
7038 | 7040 |
7039 } // namespace content | 7041 } // namespace content |
OLD | NEW |