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

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

Issue 6627063: Ignore JavaScript messages (alert/confirm/prompt) during unload handlers. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Added a browsertest Created 9 years, 9 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/extensions/extension_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) 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 ASCIIToUTF16("w.close(); alert('bar');")); 297 ASCIIToUTF16("w.close(); alert('bar');"));
298 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog(); 298 AppModalDialog* alert = ui_test_utils::WaitForAppModalDialog();
299 alert->native_dialog()->AcceptAppModalDialog(); 299 alert->native_dialog()->AcceptAppModalDialog();
300 300
301 alert = ui_test_utils::WaitForAppModalDialog(); 301 alert = ui_test_utils::WaitForAppModalDialog();
302 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)-> 302 EXPECT_FALSE(static_cast<JavaScriptAppModalDialog*>(alert)->
303 is_before_unload_dialog()); 303 is_before_unload_dialog());
304 alert->native_dialog()->AcceptAppModalDialog(); 304 alert->native_dialog()->AcceptAppModalDialog();
305 } 305 }
306 306
307 // Test for crbug.com/68780. JavaScript messages (alert/confirm/prompt) should
308 // be ignored (i.e., no dialogs shown) during onunload() and onbeforeunload().
309 IN_PROC_BROWSER_TEST_F(BrowserTest, NoAlertsDuringUnload) {
310 // Register an observer to watch for dialogs.
311 ui_test_utils::TestNotificationObserver observer;
312 NotificationRegistrar registrar;
313 registrar.Add(&observer, NotificationType::APP_MODAL_DIALOG_SHOWN,
314 NotificationService::AllSources());
315
316 // Load a page that will try to show various modal dialogs when unloaded.
317 ui_test_utils::NavigateToURL(browser(), GURL("data:text/html,<html><head>"
318 "<title>1</title></head><body><script>onbeforeunload=onunload=function(){"
319 "alert(1);confirm(2);prompt(3)}</script></body></html>"));
320
321 // Unload the page and verify that no dialogs were spotted.
322 ui_test_utils::NavigateToURL(browser(), GURL("about:blank"));
323 EXPECT_FALSE(Source<AppModalDialog>(observer.source()).ptr());
324 }
325
307 // Test that get_process_idle_time() returns reasonable values when compared 326 // Test that get_process_idle_time() returns reasonable values when compared
308 // with time deltas measured locally. 327 // with time deltas measured locally.
309 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) { 328 IN_PROC_BROWSER_TEST_F(BrowserTest, RenderIdleTime) {
310 base::TimeTicks start = base::TimeTicks::Now(); 329 base::TimeTicks start = base::TimeTicks::Now();
311 ui_test_utils::NavigateToURL(browser(), 330 ui_test_utils::NavigateToURL(browser(),
312 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 331 ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
313 FilePath(kTitle1File))); 332 FilePath(kTitle1File)));
314 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); 333 RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
315 for (; !it.IsAtEnd(); it.Advance()) { 334 for (; !it.IsAtEnd(); it.Advance()) {
316 base::TimeDelta renderer_td = 335 base::TimeDelta renderer_td =
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 817
799 // The normal browser should now have four. 818 // The normal browser should now have four.
800 EXPECT_EQ(4, browser()->tab_count()); 819 EXPECT_EQ(4, browser()->tab_count());
801 820
802 // Close the additional browsers. 821 // Close the additional browsers.
803 popup_browser->CloseAllTabs(); 822 popup_browser->CloseAllTabs();
804 app_browser->CloseAllTabs(); 823 app_browser->CloseAllTabs();
805 app_popup_browser->CloseAllTabs(); 824 app_popup_browser->CloseAllTabs();
806 } 825 }
807 #endif 826 #endif
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698