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
3 // found in the LICENSE file.
9 #include "base/command_line.h"
10 #include "base/logging.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/net/url_request_mock_util.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/browser_commands.h"
16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/tabs/tab_strip_model.h"
18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "components/app_modal_dialogs/javascript_app_modal_dialog.h"
22 #include "components/app_modal_dialogs/native_app_modal_dialog.h"
23 #include "content/public/browser/browser_thread.h"
24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_contents.h"
26 #include "content/public/test/browser_test_utils.h"
27 #include "net/test/url_request/url_request_mock_http_job.h"
28 #include "net/url_request/url_request_test_util.h"
31 // For version specific disabled tests below (http://crbug.com/267597).
32 #include "base/win/windows_version.h"
35 using base::TimeDelta
;
36 using content::BrowserThread
;
38 const std::string NOLISTENERS_HTML
=
39 "<html><head><title>nolisteners</title></head><body></body></html>";
41 const std::string UNLOAD_HTML
=
42 "<html><head><title>unload</title></head><body>"
43 "<script>window.onunload=function(e){}</script></body></html>";
45 const std::string BEFORE_UNLOAD_HTML
=
46 "<html><head><title>beforeunload</title></head><body>"
47 "<script>window.onbeforeunload=function(e){"
48 "setTimeout('document.title=\"cancelled\"', 0);return 'foo'}</script>"
51 const std::string INNER_FRAME_WITH_FOCUS_HTML
=
52 "<html><head><title>innerframewithfocus</title></head><body>"
53 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
54 "<iframe src=\"data:text/html,<html><head><script>window.onload="
55 "function(){document.getElementById('box').focus()}</script>"
56 "<body><input id='box'></input></body></html>\"></iframe>"
59 const std::string TWO_SECOND_BEFORE_UNLOAD_HTML
=
60 "<html><head><title>twosecondbeforeunload</title></head><body>"
61 "<script>window.onbeforeunload=function(e){"
62 "var start = new Date().getTime();"
63 "while(new Date().getTime() - start < 2000){}"
65 "}</script></body></html>";
67 const std::string INFINITE_UNLOAD_HTML
=
68 "<html><head><title>infiniteunload</title></head><body>"
69 "<script>window.onunload=function(e){while(true){}}</script>"
72 const std::string INFINITE_BEFORE_UNLOAD_HTML
=
73 "<html><head><title>infinitebeforeunload</title></head><body>"
74 "<script>window.onbeforeunload=function(e){while(true){}}</script>"
77 const std::string INFINITE_UNLOAD_ALERT_HTML
=
78 "<html><head><title>infiniteunloadalert</title></head><body>"
79 "<script>window.onunload=function(e){"
82 "}</script></body></html>";
84 const std::string INFINITE_BEFORE_UNLOAD_ALERT_HTML
=
85 "<html><head><title>infinitebeforeunloadalert</title></head><body>"
86 "<script>window.onbeforeunload=function(e){"
89 "}</script></body></html>";
91 const std::string TWO_SECOND_UNLOAD_ALERT_HTML
=
92 "<html><head><title>twosecondunloadalert</title></head><body>"
93 "<script>window.onunload=function(e){"
94 "var start = new Date().getTime();"
95 "while(new Date().getTime() - start < 2000){}"
97 "}</script></body></html>";
99 const std::string TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML
=
100 "<html><head><title>twosecondbeforeunloadalert</title></head><body>"
101 "<script>window.onbeforeunload=function(e){"
102 "var start = new Date().getTime();"
103 "while(new Date().getTime() - start < 2000){}"
105 "}</script></body></html>";
107 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER
=
108 "<html><head><title>only_one_unload</title></head>"
109 "<body onclick=\"window.open('data:text/html,"
110 "<html><head><title>popup</title></head></body>')\" "
111 "onbeforeunload='return;'>"
114 class UnloadTest
: public InProcessBrowserTest
{
116 void SetUpCommandLine(CommandLine
* command_line
) override
{
117 const testing::TestInfo
* const test_info
=
118 testing::UnitTest::GetInstance()->current_test_info();
119 if (strcmp(test_info
->name(),
120 "BrowserCloseTabWhenOtherTabHasListener") == 0) {
121 command_line
->AppendSwitch(switches::kDisablePopupBlocking
);
122 } else if (strcmp(test_info
->name(), "BrowserTerminateBeforeUnload") == 0) {
123 #if defined(OS_POSIX)
124 DisableSIGTERMHandling();
129 void SetUpOnMainThread() override
{
130 BrowserThread::PostTask(
131 BrowserThread::IO
, FROM_HERE
,
132 base::Bind(&chrome_browser_net::SetUrlRequestMocksEnabled
, true));
135 void CheckTitle(const char* expected_title
) {
136 base::string16 expected
= base::ASCIIToUTF16(expected_title
);
138 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
141 void NavigateToDataURL(const std::string
& html_content
,
142 const char* expected_title
) {
143 ui_test_utils::NavigateToURL(browser(),
144 GURL("data:text/html," + html_content
));
145 CheckTitle(expected_title
);
148 void NavigateToNolistenersFileTwice() {
149 GURL
url(net::URLRequestMockHTTPJob::GetMockUrl(
150 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
151 ui_test_utils::NavigateToURL(browser(), url
);
152 CheckTitle("Title Of Awesomeness");
153 ui_test_utils::NavigateToURL(browser(), url
);
154 CheckTitle("Title Of Awesomeness");
157 // Navigates to a URL asynchronously, then again synchronously. The first
158 // load is purposely async to test the case where the user loads another
159 // page without waiting for the first load to complete.
160 void NavigateToNolistenersFileTwiceAsync() {
161 GURL
url(net::URLRequestMockHTTPJob::GetMockUrl(
162 base::FilePath(FILE_PATH_LITERAL("title2.html"))));
163 ui_test_utils::NavigateToURLWithDisposition(browser(), url
, CURRENT_TAB
, 0);
164 ui_test_utils::NavigateToURL(browser(), url
);
165 CheckTitle("Title Of Awesomeness");
168 void LoadUrlAndQuitBrowser(const std::string
& html_content
,
169 const char* expected_title
) {
170 NavigateToDataURL(html_content
, expected_title
);
171 content::WindowedNotificationObserver
window_observer(
172 chrome::NOTIFICATION_BROWSER_CLOSED
,
173 content::NotificationService::AllSources());
174 chrome::CloseWindow(browser());
175 window_observer
.Wait();
178 // If |accept| is true, simulates user clicking OK, otherwise simulates
180 void ClickModalDialogButton(bool accept
) {
181 AppModalDialog
* dialog
= ui_test_utils::WaitForAppModalDialog();
182 ASSERT_TRUE(dialog
->IsJavaScriptModalDialog());
183 JavaScriptAppModalDialog
* js_dialog
=
184 static_cast<JavaScriptAppModalDialog
*>(dialog
);
186 js_dialog
->native_dialog()->AcceptAppModalDialog();
188 js_dialog
->native_dialog()->CancelAppModalDialog();
192 // Navigate to a page with an infinite unload handler.
193 // Then two async crosssite requests to ensure
194 // we don't get confused and think we're closing the tab.
196 // This test is flaky on the valgrind UI bots. http://crbug.com/39057
197 IN_PROC_BROWSER_TEST_F(UnloadTest
, CrossSiteInfiniteUnloadAsync
) {
198 // Tests makes no sense in single-process mode since the renderer is hung.
199 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
202 NavigateToDataURL(INFINITE_UNLOAD_HTML
, "infiniteunload");
203 // Must navigate to a non-data URL to trigger cross-site codepath.
204 NavigateToNolistenersFileTwiceAsync();
207 // Navigate to a page with an infinite unload handler.
208 // Then two sync crosssite requests to ensure
209 // we correctly nav to each one.
210 IN_PROC_BROWSER_TEST_F(UnloadTest
, CrossSiteInfiniteUnloadSync
) {
211 // Tests makes no sense in single-process mode since the renderer is hung.
212 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
215 NavigateToDataURL(INFINITE_UNLOAD_HTML
, "infiniteunload");
216 // Must navigate to a non-data URL to trigger cross-site codepath.
217 NavigateToNolistenersFileTwice();
220 // Navigate to a page with an infinite beforeunload handler.
221 // Then two two async crosssite requests to ensure
222 // we don't get confused and think we're closing the tab.
223 // This test is flaky on the valgrind UI bots. http://crbug.com/39057 and
224 // http://crbug.com/86469
225 IN_PROC_BROWSER_TEST_F(UnloadTest
, CrossSiteInfiniteBeforeUnloadAsync
) {
226 // Tests makes no sense in single-process mode since the renderer is hung.
227 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
230 NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML
, "infinitebeforeunload");
231 // Must navigate to a non-data URL to trigger cross-site codepath.
232 NavigateToNolistenersFileTwiceAsync();
235 // Navigate to a page with an infinite beforeunload handler.
236 // Then two two sync crosssite requests to ensure
237 // we correctly nav to each one.
238 // If this flakes, see bug http://crbug.com/86469.
239 IN_PROC_BROWSER_TEST_F(UnloadTest
, CrossSiteInfiniteBeforeUnloadSync
) {
240 // Tests makes no sense in single-process mode since the renderer is hung.
241 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
244 NavigateToDataURL(INFINITE_BEFORE_UNLOAD_HTML
, "infinitebeforeunload");
245 // Must navigate to a non-data URL to trigger cross-site codepath.
246 NavigateToNolistenersFileTwice();
249 // Tests closing the browser on a page with no unload listeners registered.
250 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseNoUnloadListeners
) {
251 LoadUrlAndQuitBrowser(NOLISTENERS_HTML
, "nolisteners");
254 // Tests closing the browser on a page with an unload listener registered.
255 // Test marked as flaky in http://crbug.com/51698
256 IN_PROC_BROWSER_TEST_F(UnloadTest
, DISABLED_BrowserCloseUnload
) {
257 LoadUrlAndQuitBrowser(UNLOAD_HTML
, "unload");
260 // Tests closing the browser with a beforeunload handler and clicking
261 // OK in the beforeunload confirm dialog.
262 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseBeforeUnloadOK
) {
263 NavigateToDataURL(BEFORE_UNLOAD_HTML
, "beforeunload");
265 content::WindowedNotificationObserver
window_observer(
266 chrome::NOTIFICATION_BROWSER_CLOSED
,
267 content::NotificationService::AllSources());
268 chrome::CloseWindow(browser());
269 ClickModalDialogButton(true);
270 window_observer
.Wait();
273 // Tests closing the browser with a beforeunload handler and clicking
274 // CANCEL in the beforeunload confirm dialog.
275 // If this test flakes, reopen http://crbug.com/123110
276 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseBeforeUnloadCancel
) {
277 NavigateToDataURL(BEFORE_UNLOAD_HTML
, "beforeunload");
278 chrome::CloseWindow(browser());
280 // We wait for the title to change after cancelling the popup to ensure that
281 // in-flight IPCs from the renderer reach the browser. Otherwise the browser
282 // won't put up the beforeunload dialog because it's waiting for an ack from
284 base::string16 expected_title
= base::ASCIIToUTF16("cancelled");
285 content::TitleWatcher
title_watcher(
286 browser()->tab_strip_model()->GetActiveWebContents(), expected_title
);
287 ClickModalDialogButton(false);
288 ASSERT_EQ(expected_title
, title_watcher
.WaitAndGetTitle());
290 content::WindowedNotificationObserver
window_observer(
291 chrome::NOTIFICATION_BROWSER_CLOSED
,
292 content::NotificationService::AllSources());
293 chrome::CloseWindow(browser());
294 ClickModalDialogButton(true);
295 window_observer
.Wait();
298 // Tests terminating the browser with a beforeunload handler.
299 // Currently only ChromeOS shuts down gracefully.
300 #if defined(OS_CHROMEOS)
301 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserTerminateBeforeUnload
) {
302 NavigateToDataURL(BEFORE_UNLOAD_HTML
, "beforeunload");
303 EXPECT_EQ(kill(base::GetCurrentProcessHandle(), SIGTERM
), 0);
307 // Tests closing the browser and clicking OK in the beforeunload confirm dialog
308 // if an inner frame has the focus.
309 // If this flakes, use http://crbug.com/32615 and http://crbug.com/45675
310 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseWithInnerFocusedFrame
) {
311 NavigateToDataURL(INNER_FRAME_WITH_FOCUS_HTML
, "innerframewithfocus");
313 content::WindowedNotificationObserver
window_observer(
314 chrome::NOTIFICATION_BROWSER_CLOSED
,
315 content::NotificationService::AllSources());
316 chrome::CloseWindow(browser());
317 ClickModalDialogButton(true);
318 window_observer
.Wait();
321 // Tests closing the browser with a beforeunload handler that takes
322 // two seconds to run.
323 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseTwoSecondBeforeUnload
) {
324 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_HTML
,
325 "twosecondbeforeunload");
328 // Tests closing the browser on a page with an unload listener registered where
329 // the unload handler has an infinite loop.
330 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseInfiniteUnload
) {
331 // Tests makes no sense in single-process mode since the renderer is hung.
332 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
335 LoadUrlAndQuitBrowser(INFINITE_UNLOAD_HTML
, "infiniteunload");
338 // Tests closing the browser with a beforeunload handler that hangs.
339 // If this flakes, use http://crbug.com/78803 and http://crbug.com/86469
340 IN_PROC_BROWSER_TEST_F(UnloadTest
, DISABLED_BrowserCloseInfiniteBeforeUnload
) {
341 // Tests makes no sense in single-process mode since the renderer is hung.
342 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
345 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_HTML
, "infinitebeforeunload");
348 // Tests closing the browser on a page with an unload listener registered where
349 // the unload handler has an infinite loop followed by an alert.
350 // If this flakes, use http://crbug.com/86469
351 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseInfiniteUnloadAlert
) {
352 // Tests makes no sense in single-process mode since the renderer is hung.
353 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
356 LoadUrlAndQuitBrowser(INFINITE_UNLOAD_ALERT_HTML
, "infiniteunloadalert");
359 // Tests closing the browser with a beforeunload handler that hangs then
361 // If this flakes, use http://crbug.com/78803 and http://crbug.com/86469.
362 IN_PROC_BROWSER_TEST_F(UnloadTest
,
363 DISABLED_BrowserCloseInfiniteBeforeUnloadAlert
) {
364 // Tests makes no sense in single-process mode since the renderer is hung.
365 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
368 LoadUrlAndQuitBrowser(INFINITE_BEFORE_UNLOAD_ALERT_HTML
,
369 "infinitebeforeunloadalert");
372 // Tests closing the browser on a page with an unload listener registered where
373 // the unload handler has an 2 second long loop followed by an alert.
374 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseTwoSecondUnloadAlert
) {
375 LoadUrlAndQuitBrowser(TWO_SECOND_UNLOAD_ALERT_HTML
, "twosecondunloadalert");
378 // Tests closing the browser with a beforeunload handler that takes
379 // two seconds to run then pops up an alert.
380 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseTwoSecondBeforeUnloadAlert
) {
381 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML
,
382 "twosecondbeforeunloadalert");
385 // Tests that if there's a renderer process with two tabs, one of which has an
386 // unload handler, and the other doesn't, the tab that doesn't have an unload
387 // handler can be closed.
388 // If this flakes, see http://crbug.com/45162, http://crbug.com/45281 and
389 // http://crbug.com/86769.
390 IN_PROC_BROWSER_TEST_F(UnloadTest
, BrowserCloseTabWhenOtherTabHasListener
) {
391 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER
, "only_one_unload");
393 // Simulate a click to force user_gesture to true; if we don't, the resulting
394 // popup will be constrained, which isn't what we want to test.
396 content::WindowedNotificationObserver
observer(
397 chrome::NOTIFICATION_TAB_ADDED
,
398 content::NotificationService::AllSources());
399 content::WindowedNotificationObserver
load_stop_observer(
400 content::NOTIFICATION_LOAD_STOP
,
401 content::NotificationService::AllSources());
402 content::SimulateMouseClick(
403 browser()->tab_strip_model()->GetActiveWebContents(), 0,
404 blink::WebMouseEvent::ButtonLeft
);
406 load_stop_observer
.Wait();
409 content::WebContentsDestroyedWatcher
destroyed_watcher(
410 browser()->tab_strip_model()->GetActiveWebContents());
411 chrome::CloseTab(browser());
412 destroyed_watcher
.Wait();
414 CheckTitle("only_one_unload");
417 class FastUnloadTest
: public UnloadTest
{
419 void SetUpCommandLine(CommandLine
* command_line
) override
{
420 UnloadTest::SetUpCommandLine(command_line
);
421 command_line
->AppendSwitch(switches::kEnableFastUnload
);
424 void SetUpInProcessBrowserTestFixture() override
{
425 ASSERT_TRUE(test_server()->Start());
428 void TearDownInProcessBrowserTestFixture() override
{ test_server()->Stop(); }
430 GURL
GetUrl(const std::string
& name
) {
431 return GURL(test_server()->GetURL(
432 "files/fast_tab_close/" + name
+ ".html"));
435 void NavigateToPage(const char* name
) {
436 ui_test_utils::NavigateToURL(browser(), GetUrl(name
));
440 void NavigateToPageInNewTab(const char* name
) {
441 ui_test_utils::NavigateToURLWithDisposition(
442 browser(), GetUrl(name
), NEW_FOREGROUND_TAB
,
443 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
447 std::string
GetCookies(const char* name
) {
448 content::WebContents
* contents
=
449 browser()->tab_strip_model()->GetActiveWebContents();
450 return content::GetCookies(contents
->GetBrowserContext(), GetUrl(name
));
454 class FastTabCloseTabStripModelObserver
: public TabStripModelObserver
{
456 FastTabCloseTabStripModelObserver(TabStripModel
* model
,
457 base::RunLoop
* run_loop
)
459 run_loop_(run_loop
) {
460 model_
->AddObserver(this);
463 ~FastTabCloseTabStripModelObserver() override
{
464 model_
->RemoveObserver(this);
467 // TabStripModelObserver:
468 void TabDetachedAt(content::WebContents
* contents
, int index
) override
{
473 TabStripModel
* const model_
;
474 base::RunLoop
* const run_loop_
;
478 // Test that fast-tab-close works when closing a tab with an unload handler
479 // (http://crbug.com/142458).
480 // Flaky on Windows bots (http://crbug.com/267597).
482 #define MAYBE_UnloadHidden \
483 DISABLED_UnloadHidden
485 #define MAYBE_UnloadHidden \
488 IN_PROC_BROWSER_TEST_F(FastUnloadTest
, MAYBE_UnloadHidden
) {
489 NavigateToPage("no_listeners");
490 NavigateToPageInNewTab("unload_sets_cookie");
491 EXPECT_EQ("", GetCookies("no_listeners"));
493 content::WebContentsDestroyedWatcher
destroyed_watcher(
494 browser()->tab_strip_model()->GetActiveWebContents());
497 base::RunLoop run_loop
;
498 FastTabCloseTabStripModelObserver
observer(
499 browser()->tab_strip_model(), &run_loop
);
500 chrome::CloseTab(browser());
504 // Check that the browser only has the original tab.
505 CheckTitle("no_listeners");
506 EXPECT_EQ(1, browser()->tab_strip_model()->count());
508 // Wait for the actual destruction.
509 destroyed_watcher
.Wait();
511 // Verify that the destruction had the desired effect.
512 EXPECT_EQ("unloaded=ohyeah", GetCookies("no_listeners"));
515 // Test that fast-tab-close does not break a solo tab.
516 IN_PROC_BROWSER_TEST_F(FastUnloadTest
, PRE_ClosingLastTabFinishesUnload
) {
517 // The unload handler sleeps before setting the cookie to catch cases when
518 // unload handlers are not allowed to run to completion. (For example,
519 // using the detached handler for the tab and then closing the browser.)
520 NavigateToPage("unload_sleep_before_cookie");
521 EXPECT_EQ(1, browser()->tab_strip_model()->count());
522 EXPECT_EQ("", GetCookies("unload_sleep_before_cookie"));
524 content::WindowedNotificationObserver
window_observer(
525 chrome::NOTIFICATION_BROWSER_CLOSED
,
526 content::NotificationService::AllSources());
527 chrome::CloseTab(browser());
528 window_observer
.Wait();
531 // Fails on Mac, Linux, Win7 (http://crbug.com/301173).
532 IN_PROC_BROWSER_TEST_F(FastUnloadTest
, DISABLED_ClosingLastTabFinishesUnload
) {
534 // Flaky on Win7+ bots (http://crbug.com/267597).
535 if (base::win::GetVersion() >= base::win::VERSION_WIN7
)
538 // Check for cookie set in unload handler of PRE_ test.
539 NavigateToPage("no_listeners");
540 EXPECT_EQ("unloaded=ohyeah", GetCookies("no_listeners"));
543 // Test that fast-tab-close does not break window close.
544 IN_PROC_BROWSER_TEST_F(FastUnloadTest
, PRE_WindowCloseFinishesUnload
) {
545 NavigateToPage("no_listeners");
547 // The unload handler sleeps before setting the cookie to catch cases when
548 // unload handlers are not allowed to run to completion. Without the sleep,
549 // the cookie can get set even if the browser does not wait for
550 // the unload handler to finish.
551 NavigateToPageInNewTab("unload_sleep_before_cookie");
552 EXPECT_EQ(2, browser()->tab_strip_model()->count());
553 EXPECT_EQ("", GetCookies("no_listeners"));
555 content::WindowedNotificationObserver
window_observer(
556 chrome::NOTIFICATION_BROWSER_CLOSED
,
557 content::NotificationService::AllSources());
558 chrome::CloseWindow(browser());
559 window_observer
.Wait();
562 // Flaky on Windows bots (http://crbug.com/279267) and fails on Mac / Linux bots
563 // (http://crbug.com/301173).
564 IN_PROC_BROWSER_TEST_F(FastUnloadTest
, DISABLED_WindowCloseFinishesUnload
) {
565 // Check for cookie set in unload during PRE_ test.
566 NavigateToPage("no_listeners");
567 EXPECT_EQ("unloaded=ohyeah", GetCookies("no_listeners"));
570 // Test that a tab crash during unload does not break window close.
572 // Hits assertion on Linux and Mac:
573 // [FATAL:profile_destroyer.cc(46)] Check failed:
575 // profile->IsOffTheRecord() ||
576 // content::RenderProcessHost::run_renderer_in_process().
577 // More details: The renderer process host matches the closed, crashed tab.
578 // The |UnloadController| receives |NOTIFICATION_WEB_CONTENTS_DISCONNECTED|
579 // and proceeds with the close.
580 IN_PROC_BROWSER_TEST_F(FastUnloadTest
, DISABLED_WindowCloseAfterUnloadCrash
) {
581 NavigateToPage("no_listeners");
582 NavigateToPageInNewTab("unload_sets_cookie");
583 content::WebContents
* unload_contents
=
584 browser()->tab_strip_model()->GetActiveWebContents();
585 EXPECT_EQ("", GetCookies("no_listeners"));
588 base::RunLoop run_loop
;
589 FastTabCloseTabStripModelObserver
observer(
590 browser()->tab_strip_model(), &run_loop
);
591 chrome::CloseTab(browser());
595 // Check that the browser only has the original tab.
596 CheckTitle("no_listeners");
597 EXPECT_EQ(1, browser()->tab_strip_model()->count());
599 CrashTab(unload_contents
);
601 // Check that the browser only has the original tab.
602 CheckTitle("no_listeners");
603 EXPECT_EQ(1, browser()->tab_strip_model()->count());
605 content::WindowedNotificationObserver
window_observer(
606 chrome::NOTIFICATION_BROWSER_CLOSED
,
607 content::NotificationService::AllSources());
608 chrome::CloseWindow(browser());
609 window_observer
.Wait();
612 // Times out on Windows and Linux.
613 #if defined(OS_WIN) || defined(OS_LINUX)
614 #define MAYBE_WindowCloseAfterBeforeUnloadCrash \
615 DISABLED_WindowCloseAfterBeforeUnloadCrash
617 #define MAYBE_WindowCloseAfterBeforeUnloadCrash \
618 WindowCloseAfterBeforeUnloadCrash
620 IN_PROC_BROWSER_TEST_F(FastUnloadTest
,
621 MAYBE_WindowCloseAfterBeforeUnloadCrash
) {
622 // Tests makes no sense in single-process mode since the renderer is hung.
623 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess
))
626 NavigateToDataURL(BEFORE_UNLOAD_HTML
, "beforeunload");
627 content::WebContents
* beforeunload_contents
=
628 browser()->tab_strip_model()->GetActiveWebContents();
630 content::WindowedNotificationObserver
window_observer(
631 chrome::NOTIFICATION_BROWSER_CLOSED
,
632 content::NotificationService::AllSources());
633 chrome::CloseWindow(browser());
634 CrashTab(beforeunload_contents
);
635 window_observer
.Wait();
638 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
639 // and multiple windows.