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