diff options
author | creis@google.com <creis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 15:30:18 +0000 |
---|---|---|
committer | creis@google.com <creis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 15:30:18 +0000 |
commit | edb2d6413b36aaa800961010b62e7c486eec30dc (patch) | |
tree | 5b5c3c2653e9e811af6485825a3e8f9e9a2c1555 /chrome/browser/browser_browsertest.cc | |
parent | e69dc145f633aa2b92b37876ada2475752951de9 (diff) | |
download | chromium_src-edb2d6413b36aaa800961010b62e7c486eec30dc.zip chromium_src-edb2d6413b36aaa800961010b62e7c486eec30dc.tar.gz chromium_src-edb2d6413b36aaa800961010b62e7c486eec30dc.tar.bz2 |
Prevents a duplicate beforeunload dialog after window.close().
If the renderer tells the browser to close a window, we no longer
run the unload events, because the renderer already has.
BUG=11647
TEST=BrowserTest.SingleBeforeUnloadAfterWindowClose
Review URL: http://codereview.chromium.org/246080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_browsertest.cc')
-rw-r--r-- | chrome/browser/browser_browsertest.cc | 23 |
1 files changed, 23 insertions, 0 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(); +} + |