OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "app/message_box_flags.h" | |
6 #include "base/file_util.h" | 5 #include "base/file_util.h" |
7 #include "chrome/browser/net/url_request_mock_http_job.h" | 6 #include "chrome/browser/net/url_request_mock_http_job.h" |
8 #include "chrome/browser/ui/view_ids.h" | 7 #include "chrome/browser/ui/view_ids.h" |
9 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/test/automation/browser_proxy.h" | 9 #include "chrome/test/automation/browser_proxy.h" |
11 #include "chrome/test/automation/tab_proxy.h" | 10 #include "chrome/test/automation/tab_proxy.h" |
12 #include "chrome/test/automation/window_proxy.h" | 11 #include "chrome/test/automation/window_proxy.h" |
13 #include "chrome/test/ui/ui_test.h" | 12 #include "chrome/test/ui/ui_test.h" |
14 #include "net/url_request/url_request_unittest.h" | 13 #include "net/url_request/url_request_unittest.h" |
| 14 #include "ui/base/message_box_flags.h" |
15 #include "views/event.h" | 15 #include "views/event.h" |
16 | 16 |
17 const std::string NOLISTENERS_HTML = | 17 const std::string NOLISTENERS_HTML = |
18 "<html><head><title>nolisteners</title></head><body></body></html>"; | 18 "<html><head><title>nolisteners</title></head><body></body></html>"; |
19 | 19 |
20 const std::string UNLOAD_HTML = | 20 const std::string UNLOAD_HTML = |
21 "<html><head><title>unload</title></head><body>" | 21 "<html><head><title>unload</title></head><body>" |
22 "<script>window.onunload=function(e){}</script></body></html>"; | 22 "<script>window.onunload=function(e){}</script></body></html>"; |
23 | 23 |
24 const std::string BEFORE_UNLOAD_HTML = | 24 const std::string BEFORE_UNLOAD_HTML = |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 157 |
158 void LoadUrlAndQuitBrowser(const std::string& html_content, | 158 void LoadUrlAndQuitBrowser(const std::string& html_content, |
159 const std::wstring& expected_title = L"") { | 159 const std::wstring& expected_title = L"") { |
160 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 160 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
161 ASSERT_TRUE(browser.get()); | 161 ASSERT_TRUE(browser.get()); |
162 NavigateToDataURL(html_content, expected_title); | 162 NavigateToDataURL(html_content, expected_title); |
163 bool application_closed = false; | 163 bool application_closed = false; |
164 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); | 164 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); |
165 } | 165 } |
166 | 166 |
167 void ClickModalDialogButton(MessageBoxFlags::DialogButton button) { | 167 void ClickModalDialogButton(ui::MessageBoxFlags::DialogButton button) { |
168 bool modal_dialog_showing = false; | 168 bool modal_dialog_showing = false; |
169 MessageBoxFlags::DialogButton available_buttons; | 169 ui::MessageBoxFlags::DialogButton available_buttons; |
170 EXPECT_TRUE(automation()->WaitForAppModalDialog()); | 170 EXPECT_TRUE(automation()->WaitForAppModalDialog()); |
171 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, | 171 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, |
172 &available_buttons)); | 172 &available_buttons)); |
173 ASSERT_TRUE(modal_dialog_showing); | 173 ASSERT_TRUE(modal_dialog_showing); |
174 EXPECT_TRUE((button & available_buttons) != 0); | 174 EXPECT_TRUE((button & available_buttons) != 0); |
175 EXPECT_TRUE(automation()->ClickAppModalDialogButton(button)); | 175 EXPECT_TRUE(automation()->ClickAppModalDialogButton(button)); |
176 } | 176 } |
177 }; | 177 }; |
178 | 178 |
179 // Navigate to a page with an infinite unload handler. | 179 // Navigate to a page with an infinite unload handler. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 } | 292 } |
293 | 293 |
294 // Tests closing the browser with a beforeunload handler and clicking | 294 // Tests closing the browser with a beforeunload handler and clicking |
295 // OK in the beforeunload confirm dialog. | 295 // OK in the beforeunload confirm dialog. |
296 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { | 296 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { |
297 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 297 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
298 ASSERT_TRUE(browser.get()); | 298 ASSERT_TRUE(browser.get()); |
299 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); | 299 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); |
300 | 300 |
301 CloseBrowserAsync(browser.get()); | 301 CloseBrowserAsync(browser.get()); |
302 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); | 302 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); |
303 WaitForBrowserClosed(); | 303 WaitForBrowserClosed(); |
304 } | 304 } |
305 | 305 |
306 // Tests closing the browser with a beforeunload handler and clicking | 306 // Tests closing the browser with a beforeunload handler and clicking |
307 // CANCEL in the beforeunload confirm dialog. | 307 // CANCEL in the beforeunload confirm dialog. |
308 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { | 308 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { |
309 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 309 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
310 ASSERT_TRUE(browser.get()); | 310 ASSERT_TRUE(browser.get()); |
311 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); | 311 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); |
312 | 312 |
313 CloseBrowserAsync(browser.get()); | 313 CloseBrowserAsync(browser.get()); |
314 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_CANCEL); | 314 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_CANCEL); |
315 // There's no real graceful way to wait for something _not_ to happen, so | 315 // There's no real graceful way to wait for something _not_ to happen, so |
316 // we just wait a short period. | 316 // we just wait a short period. |
317 CrashAwareSleep(500); | 317 CrashAwareSleep(500); |
318 ASSERT_TRUE(IsBrowserRunning()); | 318 ASSERT_TRUE(IsBrowserRunning()); |
319 | 319 |
320 CloseBrowserAsync(browser.get()); | 320 CloseBrowserAsync(browser.get()); |
321 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); | 321 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); |
322 WaitForBrowserClosed(); | 322 WaitForBrowserClosed(); |
323 } | 323 } |
324 | 324 |
325 #if defined(OS_LINUX) | 325 #if defined(OS_LINUX) |
326 // Fails sometimes on Linux valgrind. http://crbug.com/45675 | 326 // Fails sometimes on Linux valgrind. http://crbug.com/45675 |
327 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ | 327 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ |
328 FLAKY_BrowserCloseWithInnerFocusedFrame | 328 FLAKY_BrowserCloseWithInnerFocusedFrame |
329 #else | 329 #else |
330 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ | 330 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ |
331 BrowserCloseWithInnerFocusedFrame | 331 BrowserCloseWithInnerFocusedFrame |
332 #endif | 332 #endif |
333 | 333 |
334 // Tests closing the browser and clicking OK in the beforeunload confirm dialog | 334 // Tests closing the browser and clicking OK in the beforeunload confirm dialog |
335 // if an inner frame has the focus. See crbug.com/32615. | 335 // if an inner frame has the focus. See crbug.com/32615. |
336 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) { | 336 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) { |
337 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 337 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
338 ASSERT_TRUE(browser.get()); | 338 ASSERT_TRUE(browser.get()); |
339 | 339 |
340 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus"); | 340 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus"); |
341 | 341 |
342 CloseBrowserAsync(browser.get()); | 342 CloseBrowserAsync(browser.get()); |
343 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); | 343 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); |
344 WaitForBrowserClosed(); | 344 WaitForBrowserClosed(); |
345 } | 345 } |
346 | 346 |
347 // Tests closing the browser with a beforeunload handler that takes | 347 // Tests closing the browser with a beforeunload handler that takes |
348 // two seconds to run. | 348 // two seconds to run. |
349 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { | 349 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { |
350 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML, | 350 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML, |
351 L"twosecondbeforeunload"); | 351 L"twosecondbeforeunload"); |
352 } | 352 } |
353 | 353 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 ASSERT_TRUE(browser->WaitForTabCountToBecome(1)); | 449 ASSERT_TRUE(browser->WaitForTabCountToBecome(1)); |
450 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); | 450 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); |
451 ASSERT_TRUE(main_tab.get()); | 451 ASSERT_TRUE(main_tab.get()); |
452 std::wstring main_title; | 452 std::wstring main_title; |
453 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); | 453 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); |
454 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); | 454 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); |
455 } | 455 } |
456 | 456 |
457 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 457 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
458 // and multiple windows. | 458 // and multiple windows. |
OLD | NEW |