diff options
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 23 | ||||
-rw-r--r-- | chrome/browser/renderer_host/render_view_host.cc | 4 |
2 files changed, 26 insertions, 1 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc index 30e621b..930c0b3 100644 --- a/chrome/browser/browser_browsertest.cc +++ b/chrome/browser/browser_browsertest.cc @@ -23,6 +23,9 @@ const std::string BEFORE_UNLOAD_HTML = "<script>window.onbeforeunload=function(e){return 'foo'}</script>" "</body></html>"; +const std::wstring OPEN_NEW_BEFOREUNLOAD_PAGE = + L"w=window.open(); w.onbeforeunload=function(e){return 'foo'};"; + namespace { // Given a page title, returns the expected window caption string. @@ -158,3 +161,23 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) { browser()->GetSelectedTabContents()->render_view_host()-> ExecuteJavascriptInWebFrame(L"", L"onbeforeunload=null;"); } + +// Test for crbug.com/11647. A page closed with window.close() should not have +// two beforeunload dialogs shown. +IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterWindowClose) { + browser()->GetSelectedTabContents()->render_view_host()-> + ExecuteJavascriptInWebFrame(L"", OPEN_NEW_BEFOREUNLOAD_PAGE); + + // Close the new window with JavaScript, which should show a single + // beforeunload dialog. Then show another alert, to make it easy to verify + // that a second beforeunload dialog isn't shown. + browser()->GetTabContentsAt(0)->render_view_host()-> + ExecuteJavascriptInWebFrame(L"", L"w.close(); alert('bar');"); + AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); + alert->AcceptWindow(); + + alert = ui_test_utils::WaitForAppModalDialog(); + EXPECT_FALSE(alert->is_before_unload_dialog()); + alert->AcceptWindow(); +} + diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc index 9d693df..d384fec 100644 --- a/chrome/browser/renderer_host/render_view_host.cc +++ b/chrome/browser/renderer_host/render_view_host.cc @@ -995,7 +995,9 @@ void RenderViewHost::OnUpdateInspectorSettings( } void RenderViewHost::OnMsgClose() { - delegate_->Close(this); + // If the renderer is telling us to close, it has already run the unload + // events, and we can take the fast path. + ClosePageIgnoringUnloadEvents(); } void RenderViewHost::OnMsgRequestMove(const gfx::Rect& pos) { |