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

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

Issue 2901833002: Create NavigationHandle after beforeunload with PlzNavigate. (Closed)
Patch Set: Rewrote BeforeUnload test Created 3 years, 7 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/weak_ptr.h" 6 #include "base/memory/weak_ptr.h"
7 #include "content/browser/frame_host/navigation_handle_impl.h" 7 #include "content/browser/frame_host/navigation_handle_impl.h"
8 #include "content/browser/web_contents/web_contents_impl.h" 8 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
10 #include "content/public/browser/web_contents_observer.h" 10 #include "content/public/browser/web_contents_observer.h"
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 std::string("/server-redirect?") + kChromeUINetworkErrorsListingURL); 1060 std::string("/server-redirect?") + kChromeUINetworkErrorsListingURL);
1061 NavigationHandleObserver observer(shell()->web_contents(), redirect_url); 1061 NavigationHandleObserver observer(shell()->web_contents(), redirect_url);
1062 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1); 1062 TestNavigationObserver same_tab_observer(shell()->web_contents(), 1);
1063 EXPECT_TRUE( 1063 EXPECT_TRUE(
1064 ExecuteScript(shell(), base::StringPrintf("location.href = '%s';", 1064 ExecuteScript(shell(), base::StringPrintf("location.href = '%s';",
1065 redirect_url.spec().c_str()))); 1065 redirect_url.spec().c_str())));
1066 same_tab_observer.Wait(); 1066 same_tab_observer.Wait();
1067 EXPECT_EQ(net::ERR_ABORTED, observer.net_error_code()); 1067 EXPECT_EQ(net::ERR_ABORTED, observer.net_error_code());
1068 } 1068 }
1069 1069
1070 // Tests that when a navigation is aborted (i.e. because of beforeunload), the
1071 // right error code is set on the NavigationHandle.
1072 IN_PROC_BROWSER_TEST_F(NavigationHandleImplBrowserTest,
1073 ErrorCodeOnAbortedNavigation) {
1074 // Without PlzNavigate, NavigationHandles aren't created until after the
1075 // beforeunload handler runs.
1076 if (!IsBrowserSideNavigationEnabled())
1077 return;
1078 GURL url(
1079 embedded_test_server()->GetURL("/render_frame_host/beforeunload.html"));
1080 EXPECT_TRUE(NavigateToURL(shell(), url));
1081
1082 GURL new_url("/title1.html");
1083 NavigationHandleObserver observer(shell()->web_contents(), new_url);
1084 TestNavigationManager navigation_waiter(shell()->web_contents(), new_url);
1085 PrepContentsForBeforeUnloadTest(shell()->web_contents());
1086 SetShouldProceedOnBeforeUnload(shell(), false);
1087
1088 shell()->LoadURL(new_url);
1089 WaitForAppModalDialog(shell());
1090 static_cast<WebContentsImpl*>(shell()->web_contents())
1091 ->CancelModalDialogsForRenderManager();
1092 navigation_waiter.WaitForNavigationFinished();
1093 EXPECT_EQ(net::ERR_ABORTED, observer.net_error_code());
1094 }
1095
1096 // This class allows running tests with PlzNavigate enabled, regardless of 1070 // This class allows running tests with PlzNavigate enabled, regardless of
1097 // default test configuration. 1071 // default test configuration.
1098 class PlzNavigateNavigationHandleImplBrowserTest : public ContentBrowserTest { 1072 class PlzNavigateNavigationHandleImplBrowserTest : public ContentBrowserTest {
1099 public: 1073 public:
1100 PlzNavigateNavigationHandleImplBrowserTest() {} 1074 PlzNavigateNavigationHandleImplBrowserTest() {}
1101 1075
1102 void SetUpCommandLine(base::CommandLine* command_line) override { 1076 void SetUpCommandLine(base::CommandLine* command_line) override {
1103 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation); 1077 command_line->AppendSwitch(switches::kEnableBrowserSideNavigation);
1104 } 1078 }
1105 1079
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 NavigationHandleObserver observer(shell()->web_contents(), error_url); 1199 NavigationHandleObserver observer(shell()->web_contents(), error_url);
1226 EXPECT_FALSE(NavigateToURL(shell(), error_url)); 1200 EXPECT_FALSE(NavigateToURL(shell(), error_url));
1227 EXPECT_TRUE(observer.has_committed()); 1201 EXPECT_TRUE(observer.has_committed());
1228 EXPECT_TRUE(observer.is_error()); 1202 EXPECT_TRUE(observer.is_error());
1229 EXPECT_NE(site_instance, 1203 EXPECT_NE(site_instance,
1230 shell()->web_contents()->GetMainFrame()->GetSiteInstance()); 1204 shell()->web_contents()->GetMainFrame()->GetSiteInstance());
1231 } 1205 }
1232 } 1206 }
1233 1207
1234 } // namespace content 1208 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698