| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(OS_POSIX) | 5 #if defined(OS_POSIX) |
| 6 #include <signal.h> | 6 #include <signal.h> |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 "</body></html>"; | 52 "</body></html>"; |
| 53 | 53 |
| 54 const std::string INNER_FRAME_WITH_FOCUS_HTML = | 54 const std::string INNER_FRAME_WITH_FOCUS_HTML = |
| 55 "<html><head><title>innerframewithfocus</title></head><body>" | 55 "<html><head><title>innerframewithfocus</title></head><body>" |
| 56 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" | 56 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" |
| 57 "<iframe src=\"data:text/html,<html><head><script>window.onload=" | 57 "<iframe src=\"data:text/html,<html><head><script>window.onload=" |
| 58 "function(){document.getElementById('box').focus()}</script>" | 58 "function(){document.getElementById('box').focus()}</script>" |
| 59 "<body><input id='box'></input></body></html>\"></iframe>" | 59 "<body><input id='box'></input></body></html>\"></iframe>" |
| 60 "</body></html>"; | 60 "</body></html>"; |
| 61 | 61 |
| 62 const std::string TWO_SECOND_BEFORE_UNLOAD_HTML = | |
| 63 "<html><head><title>twosecondbeforeunload</title></head><body>" | |
| 64 "<script>window.onbeforeunload=function(e){" | |
| 65 "var start = new Date().getTime();" | |
| 66 "while(new Date().getTime() - start < 2000){}" | |
| 67 "return 'foo';" | |
| 68 "}</script></body></html>"; | |
| 69 | |
| 70 const std::string INFINITE_UNLOAD_HTML = | 62 const std::string INFINITE_UNLOAD_HTML = |
| 71 "<html><head><title>infiniteunload</title></head><body>" | 63 "<html><head><title>infiniteunload</title></head><body>" |
| 72 "<script>window.onunload=function(e){while(true){}}</script>" | 64 "<script>window.onunload=function(e){while(true){}}</script>" |
| 73 "</body></html>"; | 65 "</body></html>"; |
| 74 | 66 |
| 75 const std::string INFINITE_BEFORE_UNLOAD_HTML = | 67 const std::string INFINITE_BEFORE_UNLOAD_HTML = |
| 76 "<html><head><title>infinitebeforeunload</title></head><body>" | 68 "<html><head><title>infinitebeforeunload</title></head><body>" |
| 77 "<script>window.onbeforeunload=function(e){while(true){}}</script>" | 69 "<script>window.onbeforeunload=function(e){while(true){}}</script>" |
| 78 "</body></html>"; | 70 "</body></html>"; |
| 79 | 71 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); | 308 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, "innerframewithfocus"); |
| 317 | 309 |
| 318 content::WindowedNotificationObserver window_observer( | 310 content::WindowedNotificationObserver window_observer( |
| 319 chrome::NOTIFICATION_BROWSER_CLOSED, | 311 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 320 content::NotificationService::AllSources()); | 312 content::NotificationService::AllSources()); |
| 321 chrome::CloseWindow(browser()); | 313 chrome::CloseWindow(browser()); |
| 322 ClickModalDialogButton(true); | 314 ClickModalDialogButton(true); |
| 323 window_observer.Wait(); | 315 window_observer.Wait(); |
| 324 } | 316 } |
| 325 | 317 |
| 326 // Tests closing the browser with a beforeunload handler that takes | 318 // Tests closing the browser with a beforeunload handler that takes forever |
| 327 // two seconds to run. | 319 // by running an infinite loop. |
| 328 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { | 320 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteBeforeUnload) { |
| 329 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML, | 321 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_HTML, |
| 330 "twosecondbeforeunload"); | 322 "infinitebeforeunload"); |
| 331 } | 323 } |
| 332 | 324 |
| 333 // Tests closing the browser on a page with an unload listener registered where | 325 // Tests closing the browser on a page with an unload listener registered where |
| 334 // the unload handler has an infinite loop. | 326 // the unload handler has an infinite loop. |
| 335 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteUnload) { | 327 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseInfiniteUnload) { |
| 336 // Tests makes no sense in single-process mode since the renderer is hung. | 328 // Tests makes no sense in single-process mode since the renderer is hung. |
| 337 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 329 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 338 switches::kSingleProcess)) | 330 switches::kSingleProcess)) |
| 339 return; | 331 return; |
| 340 | 332 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 638 content::WindowedNotificationObserver window_observer( | 630 content::WindowedNotificationObserver window_observer( |
| 639 chrome::NOTIFICATION_BROWSER_CLOSED, | 631 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 640 content::NotificationService::AllSources()); | 632 content::NotificationService::AllSources()); |
| 641 chrome::CloseWindow(browser()); | 633 chrome::CloseWindow(browser()); |
| 642 CrashTab(beforeunload_contents); | 634 CrashTab(beforeunload_contents); |
| 643 window_observer.Wait(); | 635 window_observer.Wait(); |
| 644 } | 636 } |
| 645 | 637 |
| 646 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 638 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
| 647 // and multiple windows. | 639 // and multiple windows. |
| OLD | NEW |