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

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: Rebase + addressed nit Created 4 years, 8 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 // TODO(clamy): Make the test work on Windows and on Mac. On Mac and Windows,
819 // there seem to be an issue with the ShellJavascriptDialogManager.
820 #if defined(OS_WIN) || defined(OS_MACOSX)
821 #define MAYBE_NoResetOnBeforeUnloadCanceledOnCommit \
822 DISABLED_NoResetOnBeforeUnloadCanceledOnCommit
823 #else
824 #define MAYBE_NoResetOnBeforeUnloadCanceledOnCommit \
825 NoResetOnBeforeUnloadCanceledOnCommit
826 #endif
827 // Test that if a BeforeUnload dialog is destroyed due to the commit of a
828 // cross-site navigation, it will not reset the loading state.
829 IN_PROC_BROWSER_TEST_F(WebContentsImplBrowserTest,
830 MAYBE_NoResetOnBeforeUnloadCanceledOnCommit) {
831 ASSERT_TRUE(embedded_test_server()->Start());
832 const GURL kStartURL(
833 embedded_test_server()->GetURL("/hang_before_unload.html"));
834 const GURL kCrossSiteURL(
835 embedded_test_server()->GetURL("bar.com", "/title1.html"));
836
837 // Navigate to a first web page with a BeforeUnload event listener.
838 EXPECT_TRUE(NavigateToURL(shell(), kStartURL));
839
840 // Start a cross-site navigation that will not commit for the moment.
841 TestNavigationManager cross_site_delayer(shell()->web_contents(),
842 kCrossSiteURL);
843 shell()->LoadURL(kCrossSiteURL);
844 cross_site_delayer.WaitForWillStartRequest();
845
846 // Click on a link in the page. This will show the BeforeUnload dialog.
847 // Ensure the dialog is not dismissed, which will cause it to still be
848 // present when the cross-site navigation later commits.
849 // Note: the javascript function executed will not do the link click but
850 // schedule it for afterwards. Since the BeforeUnload event is synchronous,
851 // clicking on the link right away would cause the ExecuteScript to never
852 // return.
853 SetShouldProceedOnBeforeUnload(shell(), false);
854 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), "clickLinkSoon()"));
855 WaitForAppModalDialog(shell());
856
857 // Have the cross-site navigation commit. The main RenderFrameHost should
858 // still be loading after that.
859 cross_site_delayer.ResumeNavigation();
860 cross_site_delayer.WaitForNavigationFinished();
861 EXPECT_TRUE(shell()->web_contents()->IsLoading());
862 }
863
818 } // namespace content 864 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_contents_impl.cc ('k') | content/shell/browser/shell_javascript_dialog_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698