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

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

Issue 6904039: Update the URL if the user cancels a beforeunload handler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add missing file. Created 9 years, 7 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/test/data/beforeunload.html » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/sys_info.h" 9 #include "base/sys_info.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 17 matching lines...) Expand all
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/extensions/extension.h" 30 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
32 #include "chrome/test/in_process_browser_test.h" 32 #include "chrome/test/in_process_browser_test.h"
33 #include "chrome/test/ui_test_utils.h" 33 #include "chrome/test/ui_test_utils.h"
34 #include "content/browser/renderer_host/render_process_host.h" 34 #include "content/browser/renderer_host/render_process_host.h"
35 #include "content/browser/renderer_host/render_view_host.h" 35 #include "content/browser/renderer_host/render_view_host.h"
36 #include "content/browser/tab_contents/tab_contents.h" 36 #include "content/browser/tab_contents/tab_contents.h"
37 #include "content/common/notification_source.h" 37 #include "content/common/notification_source.h"
38 #include "content/common/notification_type.h"
38 #include "content/common/page_transition_types.h" 39 #include "content/common/page_transition_types.h"
39 #include "grit/chromium_strings.h" 40 #include "grit/chromium_strings.h"
40 #include "grit/generated_resources.h" 41 #include "grit/generated_resources.h"
41 #include "net/base/mock_host_resolver.h" 42 #include "net/base/mock_host_resolver.h"
42 #include "net/test/test_server.h" 43 #include "net/test/test_server.h"
43 #include "ui/base/l10n/l10n_util.h" 44 #include "ui/base/l10n/l10n_util.h"
44 45
45 #if defined(OS_WIN) 46 #if defined(OS_WIN)
46 #include "base/i18n/rtl.h" 47 #include "base/i18n/rtl.h"
47 #include "chrome/browser/browser_process.h" 48 #include "chrome/browser/browser_process.h"
48 #endif 49 #endif
49 50
50 namespace { 51 namespace {
51 52
52 const char* kBeforeUnloadHTML = 53 const char* kBeforeUnloadHTML =
53 "<html><head><title>beforeunload</title></head><body>" 54 "<html><head><title>beforeunload</title></head><body>"
54 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 55 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
55 "</body></html>"; 56 "</body></html>";
56 57
57 const char* kOpenNewBeforeUnloadPage = 58 const char* kOpenNewBeforeUnloadPage =
58 "w=window.open(); w.onbeforeunload=function(e){return 'foo'};"; 59 "w=window.open(); w.onbeforeunload=function(e){return 'foo'};";
59 60
61 const FilePath::CharType* kBeforeUnloadFile =
62 FILE_PATH_LITERAL("beforeunload.html");
63
60 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); 64 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
61 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html"); 65 const FilePath::CharType* kTitle2File = FILE_PATH_LITERAL("title2.html");
62 66
63 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 67 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
64 68
65 // Given a page title, returns the expected window caption string. 69 // Given a page title, returns the expected window caption string.
66 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) { 70 std::wstring WindowCaptionFromPageTitle(std::wstring page_title) {
67 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) 71 #if defined(OS_MACOSX) || defined(OS_CHROMEOS)
68 // On Mac or ChromeOS, we don't want to suffix the page title with 72 // On Mac or ChromeOS, we don't want to suffix the page title with
69 // the application name. 73 // the application name.
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 272 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
269 alert->CloseModalDialog(); 273 alert->CloseModalDialog();
270 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading()); 274 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading());
271 275
272 // Clear the beforeunload handler so the test can easily exit. 276 // Clear the beforeunload handler so the test can easily exit.
273 browser()->GetSelectedTabContents()->render_view_host()-> 277 browser()->GetSelectedTabContents()->render_view_host()->
274 ExecuteJavascriptInWebFrame(string16(), 278 ExecuteJavascriptInWebFrame(string16(),
275 ASCIIToUTF16("onbeforeunload=null;")); 279 ASCIIToUTF16("onbeforeunload=null;"));
276 } 280 }
277 281
282 // Test for crbug.com/80401. Canceling a before unload dialog should reset
283 // the URL to the previous page's URL.
284 IN_PROC_BROWSER_TEST_F(BrowserTest, CancelBeforeUnloadResetsURL) {
285 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
286 FilePath(kBeforeUnloadFile)));
287 ui_test_utils::NavigateToURL(browser(), url);
288
289 // Navigate to a page that triggers a cross-site transition.
290 ASSERT_TRUE(test_server()->Start());
291 GURL url2(test_server()->GetURL("files/title1.html"));
292 browser()->OpenURL(url2, GURL(), CURRENT_TAB, PageTransition::TYPED);
293
294 // Cancel the dialog.
295 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
296 alert->CloseModalDialog();
297 EXPECT_FALSE(browser()->GetSelectedTabContents()->is_loading());
298
299 // Wait for the ShouldClose_ACK to arrive. We can detect it by waiting for
300 // the pending RVH to be destroyed.
301 ui_test_utils::WaitForNotification(
302 NotificationType::RENDER_WIDGET_HOST_DESTROYED);
303 EXPECT_EQ(url.spec(), WideToUTF8(browser()->toolbar_model()->GetText()));
304
305 // Clear the beforeunload handler so the test can easily exit.
306 browser()->GetSelectedTabContents()->render_view_host()->
307 ExecuteJavascriptInWebFrame(string16(),
308 ASCIIToUTF16("onbeforeunload=null;"));
309 }
310
278 // Crashy on mac. http://crbug.com/38522 311 // Crashy on mac. http://crbug.com/38522
279 #if defined(OS_MACOSX) 312 #if defined(OS_MACOSX)
280 #define MAYBE_SingleBeforeUnloadAfterWindowClose \ 313 #define MAYBE_SingleBeforeUnloadAfterWindowClose \
281 DISABLED_SingleBeforeUnloadAfterWindowClose 314 DISABLED_SingleBeforeUnloadAfterWindowClose
282 #else 315 #else
283 #define MAYBE_SingleBeforeUnloadAfterWindowClose \ 316 #define MAYBE_SingleBeforeUnloadAfterWindowClose \
284 SingleBeforeUnloadAfterWindowClose 317 SingleBeforeUnloadAfterWindowClose
285 #endif 318 #endif
286 319
287 // Test for crbug.com/11647. A page closed with window.close() should not have 320 // Test for crbug.com/11647. A page closed with window.close() should not have
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 837
805 // The normal browser should now have four. 838 // The normal browser should now have four.
806 EXPECT_EQ(4, browser()->tab_count()); 839 EXPECT_EQ(4, browser()->tab_count());
807 840
808 // Close the additional browsers. 841 // Close the additional browsers.
809 popup_browser->CloseAllTabs(); 842 popup_browser->CloseAllTabs();
810 app_browser->CloseAllTabs(); 843 app_browser->CloseAllTabs();
811 app_popup_browser->CloseAllTabs(); 844 app_popup_browser->CloseAllTabs();
812 } 845 }
813 #endif 846 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/beforeunload.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698