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

Side by Side Diff: chrome/browser/browser_browsertest.cc

Issue 246080: Prevents a duplicate beforeunload dialog after window.close().... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/renderer_host/render_view_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <string> 5 #include <string>
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/sys_info.h" 8 #include "base/sys_info.h"
9 #include "chrome/browser/app_modal_dialog.h" 9 #include "chrome/browser/app_modal_dialog.h"
10 #include "chrome/browser/browser.h" 10 #include "chrome/browser/browser.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/renderer_host/render_process_host.h" 12 #include "chrome/browser/renderer_host/render_process_host.h"
13 #include "chrome/browser/tab_contents/tab_contents.h" 13 #include "chrome/browser/tab_contents/tab_contents.h"
14 #include "chrome/common/page_transition_types.h" 14 #include "chrome/common/page_transition_types.h"
15 #include "chrome/test/in_process_browser_test.h" 15 #include "chrome/test/in_process_browser_test.h"
16 #include "chrome/test/ui_test_utils.h" 16 #include "chrome/test/ui_test_utils.h"
17 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
19 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
20 20
21 const std::string BEFORE_UNLOAD_HTML = 21 const std::string BEFORE_UNLOAD_HTML =
22 "<html><head><title>beforeunload</title></head><body>" 22 "<html><head><title>beforeunload</title></head><body>"
23 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 23 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
24 "</body></html>"; 24 "</body></html>";
25 25
26 const std::wstring OPEN_NEW_BEFOREUNLOAD_PAGE =
27 L"w=window.open(); w.onbeforeunload=function(e){return 'foo'};";
28
26 namespace { 29 namespace {
27 30
28 // Given a page title, returns the expected window caption string. 31 // Given a page title, returns the expected window caption string.
29 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { 32 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) {
30 #if defined(OS_WIN) || defined(OS_LINUX) 33 #if defined(OS_WIN) || defined(OS_LINUX)
31 if (page_title.empty()) 34 if (page_title.empty())
32 return l10n_util::GetString(IDS_PRODUCT_NAME); 35 return l10n_util::GetString(IDS_PRODUCT_NAME);
33 36
34 return l10n_util::GetStringF(IDS_BROWSER_WINDOW_TITLE_FORMAT, page_title); 37 return l10n_util::GetStringF(IDS_BROWSER_WINDOW_TITLE_FORMAT, page_title);
35 #elif defined(OS_MACOSX) 38 #elif defined(OS_MACOSX)
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 // the throbber stops spinning. 157 // the throbber stops spinning.
155 browser()->Reload(); 158 browser()->Reload();
156 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 159 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
157 alert->CloseModalDialog(); 160 alert->CloseModalDialog();
158 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading()); 161 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading());
159 162
160 // Clear the beforeunload handler so the test can easily exit. 163 // Clear the beforeunload handler so the test can easily exit.
161 browser()->GetSelectedTabContents()->render_view_host()-> 164 browser()->GetSelectedTabContents()->render_view_host()->
162 ExecuteJavascriptInWebFrame(L"", L"onbeforeunload=null;"); 165 ExecuteJavascriptInWebFrame(L"", L"onbeforeunload=null;");
163 } 166 }
167
168 // Test for crbug.com/11647. A page closed with window.close() should not have
169 // two beforeunload dialogs shown.
170 IN_PROC_BROWSER_TEST_F(BrowserTest, SingleBeforeUnloadAfterWindowClose) {
171 browser()->GetSelectedTabContents()->render_view_host()->
172 ExecuteJavascriptInWebFrame(L"", OPEN_NEW_BEFOREUNLOAD_PAGE);
173
174 // Close the new window with JavaScript, which should show a single
175 // beforeunload dialog. Then show another alert, to make it easy to verify
176 // that a second beforeunload dialog isn't shown.
177 browser()->GetTabContentsAt(0)->render_view_host()->
178 ExecuteJavascriptInWebFrame(L"", L"w.close(); alert('bar');");
179 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
180 alert->AcceptWindow();
181
182 alert = ui_test_utils::WaitForAppModalDialog();
183 EXPECT_FALSE(alert->is_before_unload_dialog());
184 alert->AcceptWindow();
185 }
186
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/render_view_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698