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

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

Issue 6689014: GTTF: Detect browser crashes on shutdown in UI tests. (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
118 void CheckTitle(const std::wstring& expected_title) { 106 void CheckTitle(const std::wstring& expected_title) {
119 const int kCheckDelayMs = 100; 107 const int kCheckDelayMs = 100;
120 for (int max_wait_time = TestTimeouts::action_max_timeout_ms(); 108 for (int max_wait_time = TestTimeouts::action_max_timeout_ms();
121 max_wait_time > 0; max_wait_time -= kCheckDelayMs) { 109 max_wait_time > 0; max_wait_time -= kCheckDelayMs) {
122 CrashAwareSleep(kCheckDelayMs);
123 if (expected_title == GetActiveTabTitle()) 110 if (expected_title == GetActiveTabTitle())
124 break; 111 break;
112 base::PlatformThread::Sleep(kCheckDelayMs);
125 } 113 }
126 114
127 EXPECT_EQ(expected_title, GetActiveTabTitle()); 115 EXPECT_EQ(expected_title, GetActiveTabTitle());
128 } 116 }
129 117
130 void NavigateToDataURL(const std::string& html_content, 118 void NavigateToDataURL(const std::string& html_content,
131 const std::wstring& expected_title) { 119 const std::wstring& expected_title) {
132 NavigateToURL(GURL("data:text/html," + html_content)); 120 NavigateToURL(GURL("data:text/html," + html_content));
133 CheckTitle(expected_title); 121 CheckTitle(expected_title);
134 } 122 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 282
295 // Tests closing the browser with a beforeunload handler and clicking 283 // Tests closing the browser with a beforeunload handler and clicking
296 // OK in the beforeunload confirm dialog. 284 // OK in the beforeunload confirm dialog.
297 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { 285 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
298 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 286 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
299 ASSERT_TRUE(browser.get()); 287 ASSERT_TRUE(browser.get());
300 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 288 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
301 289
302 CloseBrowserAsync(browser.get()); 290 CloseBrowserAsync(browser.get());
303 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); 291 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK);
304 WaitForBrowserClosed(); 292
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.
305 } 297 }
306 298
307 // Tests closing the browser with a beforeunload handler and clicking 299 // Tests closing the browser with a beforeunload handler and clicking
308 // CANCEL in the beforeunload confirm dialog. 300 // CANCEL in the beforeunload confirm dialog.
309 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 301 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
310 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 302 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
311 ASSERT_TRUE(browser.get()); 303 ASSERT_TRUE(browser.get());
312 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 304 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
313 305
314 CloseBrowserAsync(browser.get()); 306 CloseBrowserAsync(browser.get());
315 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_CANCEL); 307 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_CANCEL);
308
316 // There's no real graceful way to wait for something _not_ to happen, so 309 // There's no real graceful way to wait for something _not_ to happen, so
317 // we just wait a short period. 310 // we just wait a short period.
318 CrashAwareSleep(500); 311 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
319 ASSERT_TRUE(IsBrowserRunning()); 312 ASSERT_TRUE(IsBrowserRunning());
320 313
321 CloseBrowserAsync(browser.get()); 314 CloseBrowserAsync(browser.get());
322 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); 315 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK);
323 WaitForBrowserClosed(); 316
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.
324 } 321 }
325 322
326 #if defined(OS_LINUX) 323 #if defined(OS_LINUX)
327 // Fails sometimes on Linux valgrind. http://crbug.com/45675 324 // Fails sometimes on Linux valgrind. http://crbug.com/45675
328 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ 325 #define MAYBE_BrowserCloseWithInnerFocusedFrame \
329 FLAKY_BrowserCloseWithInnerFocusedFrame 326 FLAKY_BrowserCloseWithInnerFocusedFrame
330 #else 327 #else
331 #define MAYBE_BrowserCloseWithInnerFocusedFrame \ 328 #define MAYBE_BrowserCloseWithInnerFocusedFrame \
332 BrowserCloseWithInnerFocusedFrame 329 BrowserCloseWithInnerFocusedFrame
333 #endif 330 #endif
334 331
335 // Tests closing the browser and clicking OK in the beforeunload confirm dialog 332 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
336 // if an inner frame has the focus. See crbug.com/32615. 333 // if an inner frame has the focus. See crbug.com/32615.
337 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) { 334 TEST_F(UnloadTest, MAYBE_BrowserCloseWithInnerFocusedFrame) {
338 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 335 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
339 ASSERT_TRUE(browser.get()); 336 ASSERT_TRUE(browser.get());
340 337
341 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus"); 338 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML, L"innerframewithfocus");
342 339
343 CloseBrowserAsync(browser.get()); 340 CloseBrowserAsync(browser.get());
344 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK); 341 ClickModalDialogButton(ui::MessageBoxFlags::DIALOGBUTTON_OK);
345 WaitForBrowserClosed(); 342
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.
346 } 347 }
347 348
348 // Tests closing the browser with a beforeunload handler that takes 349 // Tests closing the browser with a beforeunload handler that takes
349 // two seconds to run. 350 // two seconds to run.
350 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) { 351 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnload) {
351 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML, 352 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML,
352 L"twosecondbeforeunload"); 353 L"twosecondbeforeunload");
353 } 354 }
354 355
355 // Tests closing the browser on a page with an unload listener registered where 356 // 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
446 ASSERT_TRUE(browser->WaitForTabCountToBecome(1)); 447 ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
447 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); 448 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab());
448 ASSERT_TRUE(main_tab.get()); 449 ASSERT_TRUE(main_tab.get());
449 std::wstring main_title; 450 std::wstring main_title;
450 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); 451 EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
451 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); 452 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
452 } 453 }
453 454
454 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 455 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
455 // and multiple windows. 456 // and multiple windows.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698