| 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" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
| 14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
| 15 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 15 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "content/public/test/browser_test_utils.h" |
| 27 #include "content/test/net/url_request_mock_http_job.h" | 28 #include "content/test/net/url_request_mock_http_job.h" |
| 28 #include "net/url_request/url_request_test_util.h" | 29 #include "net/url_request/url_request_test_util.h" |
| 29 | 30 |
| 30 using base::TimeDelta; | 31 using base::TimeDelta; |
| 31 using content::BrowserThread; | 32 using content::BrowserThread; |
| 32 | 33 |
| 33 const std::string NOLISTENERS_HTML = | 34 const std::string NOLISTENERS_HTML = |
| 34 "<html><head><title>nolisteners</title></head><body></body></html>"; | 35 "<html><head><title>nolisteners</title></head><body></body></html>"; |
| 35 | 36 |
| 36 const std::string UNLOAD_HTML = | 37 const std::string UNLOAD_HTML = |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 // If this test flakes, reopen http://crbug.com/123110 | 269 // If this test flakes, reopen http://crbug.com/123110 |
| 269 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { | 270 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { |
| 270 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 271 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
| 271 chrome::CloseWindow(browser()); | 272 chrome::CloseWindow(browser()); |
| 272 | 273 |
| 273 // We wait for the title to change after cancelling the popup to ensure that | 274 // We wait for the title to change after cancelling the popup to ensure that |
| 274 // in-flight IPCs from the renderer reach the browser. Otherwise the browser | 275 // in-flight IPCs from the renderer reach the browser. Otherwise the browser |
| 275 // won't put up the beforeunload dialog because it's waiting for an ack from | 276 // won't put up the beforeunload dialog because it's waiting for an ack from |
| 276 // the renderer. | 277 // the renderer. |
| 277 string16 expected_title = ASCIIToUTF16("cancelled"); | 278 string16 expected_title = ASCIIToUTF16("cancelled"); |
| 278 ui_test_utils::TitleWatcher title_watcher( | 279 content::TitleWatcher title_watcher( |
| 279 chrome::GetActiveWebContents(browser()), expected_title); | 280 chrome::GetActiveWebContents(browser()), expected_title); |
| 280 ClickModalDialogButton(false); | 281 ClickModalDialogButton(false); |
| 281 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 282 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
| 282 | 283 |
| 283 content::WindowedNotificationObserver window_observer( | 284 content::WindowedNotificationObserver window_observer( |
| 284 chrome::NOTIFICATION_BROWSER_CLOSED, | 285 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 285 content::NotificationService::AllSources()); | 286 content::NotificationService::AllSources()); |
| 286 chrome::CloseWindow(browser()); | 287 chrome::CloseWindow(browser()); |
| 287 ClickModalDialogButton(true); | 288 ClickModalDialogButton(true); |
| 288 window_observer.Wait(); | 289 window_observer.Wait(); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 401 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 401 content::NotificationService::AllSources()); | 402 content::NotificationService::AllSources()); |
| 402 chrome::CloseTab(browser()); | 403 chrome::CloseTab(browser()); |
| 403 tab_close_observer.Wait(); | 404 tab_close_observer.Wait(); |
| 404 | 405 |
| 405 CheckTitle("only_one_unload"); | 406 CheckTitle("only_one_unload"); |
| 406 } | 407 } |
| 407 | 408 |
| 408 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 409 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
| 409 // and multiple windows. | 410 // and multiple windows. |
| OLD | NEW |