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

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

Issue 256015: Stops the throbber from spinning if the user cancels a beforeunload dialog,... (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.h » ('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 =
22 "<html><head><title>beforeunload</title></head><body>"
23 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
24 "</body></html>";
25
21 namespace { 26 namespace {
22 27
23 // Given a page title, returns the expected window caption string. 28 // Given a page title, returns the expected window caption string.
24 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { 29 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) {
25 #if defined(OS_WIN) || defined(OS_LINUX) 30 #if defined(OS_WIN) || defined(OS_LINUX)
26 if (page_title.empty()) 31 if (page_title.empty())
27 return l10n_util::GetString(IDS_PRODUCT_NAME); 32 return l10n_util::GetString(IDS_PRODUCT_NAME);
28 33
29 return l10n_util::GetStringF(IDS_BROWSER_WINDOW_TITLE_FORMAT, page_title); 34 return l10n_util::GetStringF(IDS_BROWSER_WINDOW_TITLE_FORMAT, page_title);
30 #elif defined(OS_MACOSX) 35 #elif defined(OS_MACOSX)
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 EXPECT_EQ(34, browser()->tab_count()); 136 EXPECT_EQ(34, browser()->tab_count());
132 137
133 // See browser\renderer_host\render_process_host.cc for the algorithm to 138 // See browser\renderer_host\render_process_host.cc for the algorithm to
134 // decide how many processes to create. 139 // decide how many processes to create.
135 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) { 140 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) {
136 EXPECT_GE(CountRenderProcessHosts(), 24); 141 EXPECT_GE(CountRenderProcessHosts(), 24);
137 } else { 142 } else {
138 EXPECT_LE(CountRenderProcessHosts(), 23); 143 EXPECT_LE(CountRenderProcessHosts(), 23);
139 } 144 }
140 } 145 }
146
147 // Test for crbug.com/22004. Reloading a page with a before unload handler and
148 // then canceling the dialog should not leave the throbber spinning.
149 IN_PROC_BROWSER_TEST_F(BrowserTest, ReloadThenCancelBeforeUnload) {
150 GURL url("data:text/html," + BEFORE_UNLOAD_HTML);
151 ui_test_utils::NavigateToURL(browser(), url);
152
153 // Navigate to another page, but click cancel in the dialog. Make sure that
154 // the throbber stops spinning.
155 browser()->Reload();
156 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
157 alert->CloseModalDialog();
158 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading());
159
160 // Clear the beforeunload handler so the test can easily exit.
161 browser()->GetSelectedTabContents()->render_view_host()->
162 ExecuteJavascriptInWebFrame(L"", L"onbeforeunload=null;");
163 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/renderer_host/render_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698