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

Side by Side Diff: content/browser/web_contents/web_contents_impl_browsertest.cc

Issue 1825523002: Do not reset navigation state when BeforeUnload is cancelled by a commit (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/macros.h" 5 #include "base/macros.h"
6 #include "base/strings/utf_string_conversions.h" 6 #include "base/strings/utf_string_conversions.h"
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 #include "content/browser/frame_host/navigation_entry_impl.h" 9 #include "content/browser/frame_host/navigation_entry_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h" 10 #include "content/browser/renderer_host/render_widget_host_impl.h"
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 808
809 Shell* new_shell = new_shell_observer.GetShell(); 809 Shell* new_shell = new_shell_observer.GetShell();
810 WaitForLoadStop(new_shell->web_contents()); 810 WaitForLoadStop(new_shell->web_contents());
811 811
812 EXPECT_EQ("foo", 812 EXPECT_EQ("foo",
813 static_cast<WebContentsImpl*>(new_shell->web_contents()) 813 static_cast<WebContentsImpl*>(new_shell->web_contents())
814 ->GetFrameTree()->root()->frame_name()); 814 ->GetFrameTree()->root()->frame_name());
815 } 815 }
816 } 816 }
817 817
818 // This CL tests that if a BeforeUnload dialog is destroyed due to the commit
819 // of a cross-site navigation, it will not reset the loading state.
820 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
821 NoResetOnBeforeUnloadCanceledOnCommit) {
822 ASSERT_TRUE(embedded_test_server()->Start());
823 const GURL kStartURL(
824 embedded_test_server()->GetURL("/hang_before_unload.html"));
825 const GURL kCrossSiteURL(
826 embedded_test_server()->GetURL("bar.com", "/title1.html"));
827
828 // Navigate to a first web page with a BeforeUnload event listener.
829 EXPECT_TRUE(NavigateToURL(shell(), kStartURL));
830
831 // Start a cross-site navigation that will not commit for the moment.
832 NavigationDelayer cross_site_delayer(shell()->web_contents(), kCrossSiteURL);
833 shell()->LoadURL(kCrossSiteURL);
834 cross_site_delayer.WaitForNavigationPaused();
835
836 // Click on a link in the page. This will show the BeforeUnload dialog. Have
837 // it hang.
838 // Note: the javascript function executed will not do the link click but
839 // schedule it for afterwards. Since the BeforeUnload event is synchronous,
840 // clicking on the link right away would cause the ExecuteScript to never
841 // return.
842 SetProceedByDefaultOnBeforeUnload(shell(), false);
843 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "clickLinkSoon()"));
844 WaitForAppModalDialog(shell());
845
846 // Have the cross-site navigation commit. The main RenderFrameHost should
847 // still be loading after that.
848 cross_site_delayer.ResumeNavigation();
849 cross_site_delayer.WaitForNavigationFinished();
850 EXPECT_TRUE(shell()->web_contents()->IsLoading());
851 }
852
818 } // namespace content 853 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698