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" | 5 #include "app/message_box_flags.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/platform_thread.h" | 7 #include "base/platform_thread.h" |
8 #include "chrome/browser/net/url_request_mock_http_job.h" | 8 #include "chrome/browser/net/url_request_mock_http_job.h" |
9 #include "chrome/browser/view_ids.h" | 9 #include "chrome/browser/view_ids.h" |
10 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 void LoadUrlAndQuitBrowser(const std::string& html_content, | 159 void LoadUrlAndQuitBrowser(const std::string& html_content, |
160 const std::wstring& expected_title = L"") { | 160 const std::wstring& expected_title = L"") { |
161 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 161 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
162 ASSERT_TRUE(browser.get()); | 162 ASSERT_TRUE(browser.get()); |
163 NavigateToDataURL(html_content, expected_title); | 163 NavigateToDataURL(html_content, expected_title); |
164 bool application_closed = false; | 164 bool application_closed = false; |
165 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); | 165 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); |
166 } | 166 } |
167 | 167 |
168 void ClickModalDialogButton(MessageBoxFlags::DialogButton button) { | 168 void ClickModalDialogButton(MessageBoxFlags::DialogButton button) { |
169 #if defined(OS_WIN) || defined(OS_LINUX) | |
170 bool modal_dialog_showing = false; | 169 bool modal_dialog_showing = false; |
171 MessageBoxFlags::DialogButton available_buttons; | 170 MessageBoxFlags::DialogButton available_buttons; |
172 EXPECT_TRUE(automation()->WaitForAppModalDialog()); | 171 EXPECT_TRUE(automation()->WaitForAppModalDialog()); |
173 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, | 172 EXPECT_TRUE(automation()->GetShowingAppModalDialog(&modal_dialog_showing, |
174 &available_buttons)); | 173 &available_buttons)); |
175 ASSERT_TRUE(modal_dialog_showing); | 174 ASSERT_TRUE(modal_dialog_showing); |
176 EXPECT_TRUE((button & available_buttons) != 0); | 175 EXPECT_TRUE((button & available_buttons) != 0); |
177 EXPECT_TRUE(automation()->ClickAppModalDialogButton(button)); | 176 EXPECT_TRUE(automation()->ClickAppModalDialogButton(button)); |
178 #else | |
179 // TODO(port): port this function to Mac. | |
180 NOTIMPLEMENTED(); | |
181 #endif | |
182 } | 177 } |
183 }; | 178 }; |
184 | 179 |
185 // Navigate to a page with an infinite unload handler. | 180 // Navigate to a page with an infinite unload handler. |
186 // Then two async crosssite requests to ensure | 181 // Then two async crosssite requests to ensure |
187 // we don't get confused and think we're closing the tab. | 182 // we don't get confused and think we're closing the tab. |
188 // | 183 // |
189 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 | 184 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 |
190 TEST_F(UnloadTest, DISABLED_CrossSiteInfiniteUnloadAsync) { | 185 TEST_F(UnloadTest, DISABLED_CrossSiteInfiniteUnloadAsync) { |
191 // Tests makes no sense in single-process mode since the renderer is hung. | 186 // Tests makes no sense in single-process mode since the renderer is hung. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // Tests closing the browser on a page with no unload listeners registered. | 273 // Tests closing the browser on a page with no unload listeners registered. |
279 TEST_F(UnloadTest, BrowserCloseNoUnloadListeners) { | 274 TEST_F(UnloadTest, BrowserCloseNoUnloadListeners) { |
280 LoadUrlAndQuitBrowser(NOLISTENERS_HTML, L"nolisteners"); | 275 LoadUrlAndQuitBrowser(NOLISTENERS_HTML, L"nolisteners"); |
281 } | 276 } |
282 | 277 |
283 // Tests closing the browser on a page with an unload listener registered. | 278 // Tests closing the browser on a page with an unload listener registered. |
284 TEST_F(UnloadTest, BrowserCloseUnload) { | 279 TEST_F(UnloadTest, BrowserCloseUnload) { |
285 LoadUrlAndQuitBrowser(UNLOAD_HTML, L"unload"); | 280 LoadUrlAndQuitBrowser(UNLOAD_HTML, L"unload"); |
286 } | 281 } |
287 | 282 |
288 #if defined(OS_MACOSX) | |
289 // ClickModalDialogButton doesn't work on Mac: http://crbug.com/45031 | |
290 #define MAYBE_BrowserCloseBeforeUnloadOK DISABLED_BrowserCloseBeforeUnloadOK | |
291 #define MAYBE_BrowserCloseBeforeUnloadCancel \ | |
292 DISABLED_BrowserCloseBeforeUnloadCancel | |
293 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ | |
294 DISABLED_BrowserCloseWithInnerFocusedFrame | |
295 #elif defined(OS_LINUX) | |
296 #define MAYBE_BrowserCloseBeforeUnloadOK BrowserCloseBeforeUnloadOK | |
297 #define MAYBE_BrowserCloseBeforeUnloadCancel BrowserCloseBeforeUnloadCancel | |
298 // Fails sometimes on Linux valgrind. | |
299 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ | |
300 FLAKY_BrowserCloseWithInnerFocusedFrame | |
301 #else | |
302 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ | |
303 BrowserCloseWithInnerFocusedFrame | |
304 #define MAYBE_BrowserCloseBeforeUnloadOK BrowserCloseBeforeUnloadOK | |
305 #define MAYBE_BrowserCloseBeforeUnloadCancel BrowserCloseBeforeUnloadCancel | |
306 #endif | |
307 | |
308 // Tests closing the browser with a beforeunload handler and clicking | 283 // Tests closing the browser with a beforeunload handler and clicking |
309 // OK in the beforeunload confirm dialog. | 284 // OK in the beforeunload confirm dialog. |
310 TEST_F(UnloadTest, MAYBE_BrowserCloseBeforeUnloadOK) { | 285 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { |
311 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 286 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
312 ASSERT_TRUE(browser.get()); | 287 ASSERT_TRUE(browser.get()); |
313 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); | 288 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); |
314 | 289 |
315 CloseBrowserAsync(browser.get()); | 290 CloseBrowserAsync(browser.get()); |
316 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); | 291 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); |
317 WaitForBrowserClosed(); | 292 WaitForBrowserClosed(); |
318 } | 293 } |
319 | 294 |
320 // Tests closing the browser with a beforeunload handler and clicking | 295 // Tests closing the browser with a beforeunload handler and clicking |
321 // CANCEL in the beforeunload confirm dialog. | 296 // CANCEL in the beforeunload confirm dialog. |
322 TEST_F(UnloadTest, MAYBE_BrowserCloseBeforeUnloadCancel) { | 297 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { |
323 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 298 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
324 ASSERT_TRUE(browser.get()); | 299 ASSERT_TRUE(browser.get()); |
325 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); | 300 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); |
326 | 301 |
327 CloseBrowserAsync(browser.get()); | 302 CloseBrowserAsync(browser.get()); |
328 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_CANCEL); | 303 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_CANCEL); |
329 // There's no real graceful way to wait for something _not_ to happen, so | 304 // There's no real graceful way to wait for something _not_ to happen, so |
330 // we just wait a short period. | 305 // we just wait a short period. |
331 CrashAwareSleep(500); | 306 CrashAwareSleep(500); |
332 ASSERT_TRUE(IsBrowserRunning()); | 307 ASSERT_TRUE(IsBrowserRunning()); |
333 | 308 |
334 CloseBrowserAsync(browser.get()); | 309 CloseBrowserAsync(browser.get()); |
335 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); | 310 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); |
336 WaitForBrowserClosed(); | 311 WaitForBrowserClosed(); |
337 } | 312 } |
338 | 313 |
| 314 #if defined(OS_LINUX) |
| 315 // Fails sometimes on Linux valgrind. http://crbug.com/32615 |
| 316 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ |
| 317 FLAKY_BrowserCloseWithInnerFocusedFrame |
| 318 #else |
| 319 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ |
| 320 BrowserCloseWithInnerFocusedFrame |
| 321 #endif |
| 322 |
339 // Tests closing the browser and clicking OK in the beforeunload confirm dialog | 323 // Tests closing the browser and clicking OK in the beforeunload confirm dialog |
340 // if an inner frame has the focus. See crbug.com/32615. | 324 // if an inner frame has the focus. See crbug.com/32615. |
341 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) { | 325 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) { |
342 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 326 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
343 ASSERT_TRUE(browser.get()); | 327 ASSERT_TRUE(browser.get()); |
344 | 328 |
345 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus"); | 329 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus"); |
346 | 330 |
347 CloseBrowserAsync(browser.get()); | 331 CloseBrowserAsync(browser.get()); |
348 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); | 332 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 ASSERT_TRUE(browser->WaitForTabCountToBecome(1, action_timeout_ms())); | 437 ASSERT_TRUE(browser->WaitForTabCountToBecome(1, action_timeout_ms())); |
454 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); | 438 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); |
455 ASSERT_TRUE(main_tab.get()); | 439 ASSERT_TRUE(main_tab.get()); |
456 std::wstring main_title; | 440 std::wstring main_title; |
457 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); | 441 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); |
458 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); | 442 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); |
459 } | 443 } |
460 | 444 |
461 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 445 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
462 // and multiple windows. | 446 // and multiple windows. |
OLD | NEW |