Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(278)

Side by Side Diff: chrome/browser/unload_uitest.cc

Issue 6794056: Revert 80472 - GTTF: Detect browser crashes on shutdown in UI tests.Previously the automation fra... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "chrome/browser/net/url_request_mock_http_job.h" 7 #include "chrome/browser/net/url_request_mock_http_job.h"
8 #include "chrome/browser/ui/view_ids.h" 8 #include "chrome/browser/ui/view_ids.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/automation/browser_proxy.h" 10 #include "chrome/test/automation/browser_proxy.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const testing::TestInfo* const test_info = 96 const testing::TestInfo* const test_info =
97 testing::UnitTest::GetInstance()->current_test_info(); 97 testing::UnitTest::GetInstance()->current_test_info();
98 if (strcmp(test_info->name(), 98 if (strcmp(test_info->name(),
99 "BrowserCloseTabWhenOtherTabHasListener") == 0) { 99 "BrowserCloseTabWhenOtherTabHasListener") == 0) {
100 launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking); 100 launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking);
101 } 101 }
102 102
103 UITest::SetUp(); 103 UITest::SetUp();
104 } 104 }
105 105
106 void WaitForBrowserClosed() {
107 const int kCheckDelayMs = 100;
108 for (int max_wait_time = TestTimeouts::action_max_timeout_ms();
109 max_wait_time > 0; max_wait_time -= kCheckDelayMs) {
110 CrashAwareSleep(kCheckDelayMs);
111 if (!IsBrowserRunning())
112 break;
113 }
114
115 EXPECT_FALSE(IsBrowserRunning());
116 }
117
106 void CheckTitle(const std::wstring& expected_title) { 118 void CheckTitle(const std::wstring& expected_title) {
107 const int kCheckDelayMs = 100; 119 const int kCheckDelayMs = 100;
108 for (int max_wait_time = TestTimeouts::action_max_timeout_ms(); 120 for (int max_wait_time = TestTimeouts::action_max_timeout_ms();
109 max_wait_time > 0; max_wait_time -= kCheckDelayMs) { 121 max_wait_time > 0; max_wait_time -= kCheckDelayMs) {
122 CrashAwareSleep(kCheckDelayMs);
110 if (expected_title == GetActiveTabTitle()) 123 if (expected_title == GetActiveTabTitle())
111 break; 124 break;
112 base::PlatformThread::Sleep(kCheckDelayMs);
113 } 125 }
114 126
115 EXPECT_EQ(expected_title, GetActiveTabTitle()); 127 EXPECT_EQ(expected_title, GetActiveTabTitle());
116 } 128 }
117 129
118 void NavigateToDataURL(const std::string& html_content, 130 void NavigateToDataURL(const std::string& html_content,
119 const std::wstring& expected_title) { 131 const std::wstring& expected_title) {
120 NavigateToURL(GURL("data:text/html," + html_content)); 132 NavigateToURL(GURL("data:text/html," + html_content));
121 CheckTitle(expected_title); 133 CheckTitle(expected_title);
122 } 134 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 294
283 // Tests closing the browser with a beforeunload handler and clicking 295 // Tests closing the browser with a beforeunload handler and clicking
284 // OK in the beforeunload confirm dialog. 296 // OK in the beforeunload confirm dialog.
285 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { 297 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
286 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 298 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
287 ASSERT_TRUE(browser.get()); 299 ASSERT_TRUE(browser.get());
288 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 300 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
289 301
290 CloseBrowserAsync(browser.get()); 302 CloseBrowserAsync(browser.get());
291 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); 303 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK);
292 304 WaitForBrowserClosed();
293 int exit_code = -1;
294 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit(
295 TestTimeouts::action_max_timeout_ms(), &exit_code));
296 EXPECT_EQ(0, exit_code); // Expect a clean shutown.
297 } 305 }
298 306
299 // Tests closing the browser with a beforeunload handler and clicking 307 // Tests closing the browser with a beforeunload handler and clicking
300 // CANCEL in the beforeunload confirm dialog. 308 // CANCEL in the beforeunload confirm dialog.
301 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 309 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
302 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 310 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
303 ASSERT_TRUE(browser.get()); 311 ASSERT_TRUE(browser.get());
304 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 312 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
305 313
306 CloseBrowserAsync(browser.get()); 314 CloseBrowserAsync(browser.get());
307 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_CANCEL); 315 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_CANCEL);
308
309 // There's no real graceful way to wait for something _not_ to happen, so 316 // There's no real graceful way to wait for something _not_ to happen, so
310 // we just wait a short period. 317 // we just wait a short period.
311 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); 318 CrashAwareSleep(500);
312 ASSERT_TRUE(IsBrowserRunning()); 319 ASSERT_TRUE(IsBrowserRunning());
313 320
314 CloseBrowserAsync(browser.get()); 321 CloseBrowserAsync(browser.get());
315 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); 322 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK);
316 323 WaitForBrowserClosed();
317 int exit_code = -1;
318 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit(
319 TestTimeouts::action_max_timeout_ms(), &exit_code));
320 EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
321 } 324 }
322 325
323 #if defined(OS_LINUX) 326 #if defined(OS_LINUX)
324 // Fails sometimes on Linux valgrind. http://crbug.com/45675 327 // Fails sometimes on Linux valgrind. http://crbug.com/45675
325 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ 328 #define MAYBE_BrowserCloseWithInnerFocusedFrame \
326 FLAKY_BrowserCloseWithInnerFocusedFrame 329 FLAKY_BrowserCloseWithInnerFocusedFrame
327 #else 330 #else
328 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ 331 #define MAYBE_BrowserCloseWithInnerFocusedFrame \
329 BrowserCloseWithInnerFocusedFrame 332 BrowserCloseWithInnerFocusedFrame
330 #endif 333 #endif
331 334
332 // Tests closing the browser and clicking OK in the beforeunload confirm dialog 335 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
333 // if an inner frame has the focus. See crbug.com/32615. 336 // if an inner frame has the focus. See crbug.com/32615.
334 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) { 337 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) {
335 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 338 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
336 ASSERT_TRUE(browser.get()); 339 ASSERT_TRUE(browser.get());
337 340
338 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus"); 341 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus");
339 342
340 CloseBrowserAsync(browser.get()); 343 CloseBrowserAsync(browser.get());
341 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); 344 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK);
342 345 WaitForBrowserClosed();
343 int exit_code = -1;
344 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit(
345 TestTimeouts::action_max_timeout_ms(), &exit_code));
346 EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
347 } 346 }
348 347
349 // Tests closing the browser with a beforeunload handler that takes 348 // Tests closing the browser with a beforeunload handler that takes
350 // two seconds to run. 349 // two seconds to run.
351 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { 350 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) {
352 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML, 351 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML,
353 L"twosecondbeforeunload"); 352 L"twosecondbeforeunload");
354 } 353 }
355 354
356 // Tests closing the browser on a page with an unload listener registered where 355 // Tests closing the browser on a page with an unload listener registered where
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 ASSERT_TRUE(browser->WaitForTabCountToBecome(1)); 446 ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
448 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); 447 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab());
449 ASSERT_TRUE(main_tab.get()); 448 ASSERT_TRUE(main_tab.get());
450 std::wstring main_title; 449 std::wstring main_title;
451 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); 450 EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
452 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); 451 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
453 } 452 }
454 453
455 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 454 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
456 // and multiple windows. 455 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/process_singleton_linux_uitest.cc ('k') | chrome/common/service_process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698