Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 2561983002: NavigationController: Reload methods migration (Closed)
Patch Set: one more mac build fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED | 1176 ui::PageTransitionFromInt(ui::PAGE_TRANSITION_TYPED |
1177 ui::PAGE_TRANSITION_FORWARD_BACK | 1177 ui::PAGE_TRANSITION_FORWARD_BACK |
1178 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR))); 1178 ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)));
1179 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 1179 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
1180 EXPECT_FALSE(capturer.details().is_in_page); 1180 EXPECT_FALSE(capturer.details().is_in_page);
1181 } 1181 }
1182 1182
1183 { 1183 {
1184 // Reload from the browser side. 1184 // Reload from the browser side.
1185 FrameNavigateParamsCapturer capturer(root); 1185 FrameNavigateParamsCapturer capturer(root);
1186 shell()->web_contents()->GetController().Reload(false); 1186 shell()->web_contents()->GetController().Reload(ReloadType::NORMAL, false);
Takashi Toyoshima 2016/12/15 06:21:52 all callers in this file are for testing.
1187 capturer.Wait(); 1187 capturer.Wait();
1188 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( 1188 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
1189 capturer.params().transition, ui::PAGE_TRANSITION_RELOAD)); 1189 capturer.params().transition, ui::PAGE_TRANSITION_RELOAD));
1190 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 1190 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
1191 EXPECT_FALSE(capturer.details().is_in_page); 1191 EXPECT_FALSE(capturer.details().is_in_page);
1192 } 1192 }
1193 1193
1194 { 1194 {
1195 // Reload from the renderer side. 1195 // Reload from the renderer side.
1196 FrameNavigateParamsCapturer capturer(root); 1196 FrameNavigateParamsCapturer capturer(root);
(...skipping 3124 matching lines...) Expand 10 before | Expand all | Expand 10 after
4321 } 4321 }
4322 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { 4322 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) {
4323 FrameNavigationEntry* subframe_entry = 4323 FrameNavigationEntry* subframe_entry =
4324 controller.GetLastCommittedEntry()->GetFrameEntry(subframe); 4324 controller.GetLastCommittedEntry()->GetFrameEntry(subframe);
4325 EXPECT_EQ(frame_url, subframe_entry->url()); 4325 EXPECT_EQ(frame_url, subframe_entry->url());
4326 } 4326 }
4327 4327
4328 // 3. Reload the main frame. 4328 // 3. Reload the main frame.
4329 { 4329 {
4330 FrameNavigateParamsCapturer capturer(root); 4330 FrameNavigateParamsCapturer capturer(root);
4331 controller.Reload(false); 4331 controller.Reload(ReloadType::NORMAL, false);
4332 capturer.Wait(); 4332 capturer.Wait();
4333 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs( 4333 EXPECT_TRUE(ui::PageTransitionTypeIncludingQualifiersIs(
4334 capturer.params().transition, ui::PAGE_TRANSITION_RELOAD)); 4334 capturer.params().transition, ui::PAGE_TRANSITION_RELOAD));
4335 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type); 4335 EXPECT_EQ(NAVIGATION_TYPE_EXISTING_PAGE, capturer.details().type);
4336 EXPECT_FALSE(capturer.details().is_in_page); 4336 EXPECT_FALSE(capturer.details().is_in_page);
4337 } 4337 }
4338 4338
4339 // 4. Add the iframe again. 4339 // 4. Add the iframe again.
4340 { 4340 {
4341 LoadCommittedCapturer capturer(shell()->web_contents()); 4341 LoadCommittedCapturer capturer(shell()->web_contents());
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ReloadType::ORIGINAL_REQUEST_URL, false);
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 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after
6693 shell(), embedded_test_server()->GetURL( 6695 shell(), embedded_test_server()->GetURL(
6694 "/navigation_controller/page_with_links.html"))); 6696 "/navigation_controller/page_with_links.html")));
6695 histogram.ExpectTotalCount(kReloadToReloadMetricName, 0); 6697 histogram.ExpectTotalCount(kReloadToReloadMetricName, 0);
6696 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0); 6698 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 0);
6697 6699
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(ReloadType::NORMAL, 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(ReloadType::BYPASSING_CACHE, false);
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(ReloadType::BYPASSING_CACHE, false);
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);
6728 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); 6730 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1);
6729 6731
6730 // Then, the next reload should be assumed as the first reload. Metrics 6732 // Then, the next reload should be assumed as the first reload. Metrics
6731 // should not be changed for the first reload. 6733 // should not be changed for the first reload.
6732 controller.Reload(false); 6734 controller.Reload(ReloadType::NORMAL, false);
6733 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 6735 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
6734 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2); 6736 histogram.ExpectTotalCount(kReloadToReloadMetricName, 2);
6735 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1); 6737 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 1);
6736 6738
6737 // Another reload of ReloadType::NORMAL should be counted by both metrics 6739 // Another reload of ReloadType::NORMAL should be counted by both metrics
6738 // again. 6740 // again.
6739 controller.Reload(false); 6741 controller.Reload(ReloadType::NORMAL, false);
6740 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 6742 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
6741 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); 6743 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3);
6742 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); 6744 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2);
6743 6745
6744 // A renderer-initiated navigations with no user gesture don't reset reload 6746 // A renderer-initiated navigations with no user gesture don't reset reload
6745 // tracking information, and the following reload will be counted by metrics. 6747 // tracking information, and the following reload will be counted by metrics.
6746 ExecuteJavaScriptAndWaitForLoadStop( 6748 ExecuteJavaScriptAndWaitForLoadStop(
6747 shell()->web_contents(), 6749 shell()->web_contents(),
6748 "history.pushState({}, 'page 1', 'simple_page_1.html')"); 6750 "history.pushState({}, 'page 1', 'simple_page_1.html')");
6749 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); 6751 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3);
6750 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); 6752 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2);
6751 ExecuteJavaScriptAndWaitForLoadStop(shell()->web_contents(), 6753 ExecuteJavaScriptAndWaitForLoadStop(shell()->web_contents(),
6752 "location.href='simple_page_2.html'"); 6754 "location.href='simple_page_2.html'");
6753 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3); 6755 histogram.ExpectTotalCount(kReloadToReloadMetricName, 3);
6754 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2); 6756 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 2);
6755 6757
6756 controller.Reload(false); 6758 controller.Reload(ReloadType::NORMAL, false);
6757 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 6759 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
6758 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); 6760 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4);
6759 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); 6761 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3);
6760 6762
6761 // Go back to the first page. Reload tracking information should be reset. 6763 // Go back to the first page. Reload tracking information should be reset.
6762 shell()->web_contents()->GetController().GoBack(); 6764 shell()->web_contents()->GetController().GoBack();
6763 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 6765 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
6764 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); 6766 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4);
6765 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); 6767 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3);
6766 6768
6767 controller.Reload(false); 6769 controller.Reload(ReloadType::NORMAL, false);
6768 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 6770 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
6769 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4); 6771 histogram.ExpectTotalCount(kReloadToReloadMetricName, 4);
6770 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3); 6772 histogram.ExpectTotalCount(kReloadMainResourceToReloadMetricName, 3);
6771 } 6773 }
6772 6774
6773 // Check that the referrer is stored inside FrameNavigationEntry for subframes. 6775 // Check that the referrer is stored inside FrameNavigationEntry for subframes.
6774 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 6776 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
6775 RefererStoredForSubFrame) { 6777 RefererStoredForSubFrame) {
6776 if (!SiteIsolationPolicy::UseSubframeNavigationEntries()) 6778 if (!SiteIsolationPolicy::UseSubframeNavigationEntries())
6777 return; 6779 return;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698