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/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
20 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/ui_test_utils.h" | 23 #include "chrome/test/base/ui_test_utils.h" |
23 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
26 #include "content/test/net/url_request_mock_http_job.h" | 27 #include "content/test/net/url_request_mock_http_job.h" |
27 #include "net/url_request/url_request_test_util.h" | 28 #include "net/url_request/url_request_test_util.h" |
28 | 29 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } | 122 } |
122 | 123 |
123 virtual void SetUpOnMainThread() OVERRIDE { | 124 virtual void SetUpOnMainThread() OVERRIDE { |
124 BrowserThread::PostTask( | 125 BrowserThread::PostTask( |
125 BrowserThread::IO, FROM_HERE, | 126 BrowserThread::IO, FROM_HERE, |
126 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); | 127 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled, true)); |
127 } | 128 } |
128 | 129 |
129 void CheckTitle(const char* expected_title) { | 130 void CheckTitle(const char* expected_title) { |
130 string16 expected = ASCIIToUTF16(expected_title); | 131 string16 expected = ASCIIToUTF16(expected_title); |
131 EXPECT_EQ(expected, browser()->GetActiveWebContents()->GetTitle()); | 132 EXPECT_EQ(expected, chrome::GetActiveWebContents(browser())->GetTitle()); |
132 } | 133 } |
133 | 134 |
134 void NavigateToDataURL(const std::string& html_content, | 135 void NavigateToDataURL(const std::string& html_content, |
135 const char* expected_title) { | 136 const char* expected_title) { |
136 ui_test_utils::NavigateToURL(browser(), | 137 ui_test_utils::NavigateToURL(browser(), |
137 GURL("data:text/html," + html_content)); | 138 GURL("data:text/html," + html_content)); |
138 CheckTitle(expected_title); | 139 CheckTitle(expected_title); |
139 } | 140 } |
140 | 141 |
141 void NavigateToNolistenersFileTwice() { | 142 void NavigateToNolistenersFileTwice() { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { | 269 IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { |
269 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); | 270 NavigateToDataURL(BEFORE_UNLOAD_HTML, "beforeunload"); |
270 chrome::CloseWindow(browser()); | 271 chrome::CloseWindow(browser()); |
271 | 272 |
272 // We wait for the title to change after cancelling the popup to ensure that | 273 // We wait for the title to change after cancelling the popup to ensure that |
273 // in-flight IPCs from the renderer reach the browser. Otherwise the browser | 274 // in-flight IPCs from the renderer reach the browser. Otherwise the browser |
274 // won't put up the beforeunload dialog because it's waiting for an ack from | 275 // won't put up the beforeunload dialog because it's waiting for an ack from |
275 // the renderer. | 276 // the renderer. |
276 string16 expected_title = ASCIIToUTF16("cancelled"); | 277 string16 expected_title = ASCIIToUTF16("cancelled"); |
277 ui_test_utils::TitleWatcher title_watcher( | 278 ui_test_utils::TitleWatcher title_watcher( |
278 browser()->GetActiveWebContents(), expected_title); | 279 chrome::GetActiveWebContents(browser()), expected_title); |
279 ClickModalDialogButton(false); | 280 ClickModalDialogButton(false); |
280 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); | 281 ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); |
281 | 282 |
282 ui_test_utils::WindowedNotificationObserver window_observer( | 283 ui_test_utils::WindowedNotificationObserver window_observer( |
283 chrome::NOTIFICATION_BROWSER_CLOSED, | 284 chrome::NOTIFICATION_BROWSER_CLOSED, |
284 content::NotificationService::AllSources()); | 285 content::NotificationService::AllSources()); |
285 chrome::CloseWindow(browser()); | 286 chrome::CloseWindow(browser()); |
286 ClickModalDialogButton(true); | 287 ClickModalDialogButton(true); |
287 window_observer.Wait(); | 288 window_observer.Wait(); |
288 } | 289 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 | 384 |
384 // Simulate a click to force user_gesture to true; if we don't, the resulting | 385 // Simulate a click to force user_gesture to true; if we don't, the resulting |
385 // popup will be constrained, which isn't what we want to test. | 386 // popup will be constrained, which isn't what we want to test. |
386 | 387 |
387 ui_test_utils::WindowedNotificationObserver observer( | 388 ui_test_utils::WindowedNotificationObserver observer( |
388 chrome::NOTIFICATION_TAB_ADDED, | 389 chrome::NOTIFICATION_TAB_ADDED, |
389 content::NotificationService::AllSources()); | 390 content::NotificationService::AllSources()); |
390 ui_test_utils::WindowedNotificationObserver load_stop_observer( | 391 ui_test_utils::WindowedNotificationObserver load_stop_observer( |
391 content::NOTIFICATION_LOAD_STOP, | 392 content::NOTIFICATION_LOAD_STOP, |
392 content::NotificationService::AllSources()); | 393 content::NotificationService::AllSources()); |
393 ui_test_utils::SimulateMouseClick(browser()->GetActiveWebContents()); | 394 ui_test_utils::SimulateMouseClick(chrome::GetActiveWebContents(browser())); |
394 observer.Wait(); | 395 observer.Wait(); |
395 load_stop_observer.Wait(); | 396 load_stop_observer.Wait(); |
396 CheckTitle("popup"); | 397 CheckTitle("popup"); |
397 | 398 |
398 ui_test_utils::WindowedNotificationObserver tab_close_observer( | 399 ui_test_utils::WindowedNotificationObserver tab_close_observer( |
399 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 400 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
400 content::NotificationService::AllSources()); | 401 content::NotificationService::AllSources()); |
401 chrome::CloseTab(browser()); | 402 chrome::CloseTab(browser()); |
402 tab_close_observer.Wait(); | 403 tab_close_observer.Wait(); |
403 | 404 |
404 CheckTitle("only_one_unload"); | 405 CheckTitle("only_one_unload"); |
405 } | 406 } |
406 | 407 |
407 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 408 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
408 // and multiple windows. | 409 // and multiple windows. |
OLD | NEW |