OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #if defined(OS_POSIX) | 5 #if defined(OS_POSIX) |
6 #include <signal.h> | 6 #include <signal.h> |
7 #endif | 7 #endif |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/net/url_request_mock_util.h" | 13 #include "chrome/browser/net/url_request_mock_util.h" |
14 #include "chrome/browser/profiles/profile.h" | |
14 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" | 15 #include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h" |
15 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" | 16 #include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h" |
16 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_commands.h" | 18 #include "chrome/browser/ui/browser_commands.h" |
18 #include "chrome/browser/ui/browser_list.h" | 19 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
21 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
20 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
21 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
23 #include "chrome/test/base/ui_test_utils.h" | 26 #include "chrome/test/base/ui_test_utils.h" |
27 #include "content/browser/renderer_host/render_view_host_impl.h" | |
24 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
27 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
28 #include "content/test/net/url_request_mock_http_job.h" | 32 #include "content/test/net/url_request_mock_http_job.h" |
29 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
30 | 34 |
31 using base::TimeDelta; | 35 using base::TimeDelta; |
32 using content::BrowserThread; | 36 using content::BrowserThread; |
33 | 37 |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 | 406 |
403 content::WindowedNotificationObserver tab_close_observer( | 407 content::WindowedNotificationObserver tab_close_observer( |
404 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | 408 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
405 content::NotificationService::AllSources()); | 409 content::NotificationService::AllSources()); |
406 chrome::CloseTab(browser()); | 410 chrome::CloseTab(browser()); |
407 tab_close_observer.Wait(); | 411 tab_close_observer.Wait(); |
408 | 412 |
409 CheckTitle("only_one_unload"); | 413 CheckTitle("only_one_unload"); |
410 } | 414 } |
411 | 415 |
416 class FastTabCloseTabStripModelObserver : public TabStripModelObserver { | |
417 public: | |
418 FastTabCloseTabStripModelObserver(TabStripModel* model, | |
419 base::RunLoop* run_loop) | |
420 : model_(model), | |
421 run_loop_(run_loop) { | |
422 model_->AddObserver(this); | |
423 } | |
424 | |
425 ~FastTabCloseTabStripModelObserver() { | |
426 model_->RemoveObserver(this); | |
427 } | |
428 | |
429 // TabStripModelObserver: | |
430 virtual void TabDetachedAt(TabContents* contents, int index) { | |
431 run_loop_->Quit(); | |
432 } | |
433 | |
434 private: | |
435 TabStripModel* const model_; | |
436 base::RunLoop* const run_loop_; | |
437 }; | |
438 | |
439 // Test that fast-tab-close works when closing a tab (not the last one) with | |
ojan
2012/10/17 18:09:39
Can you also add tests for the following cases to
| |
440 // an unload handler (http://crbug.com/142458). | |
441 IN_PROC_BROWSER_TEST_F(UnloadTest, DetachedUnloadTwoTabs) { | |
442 ASSERT_TRUE(test_server()->Start()); | |
443 | |
444 GURL url = test_server()->GetURL("files/fast_tab_close/no_listeners.html"); | |
445 ui_test_utils::NavigateToURL(browser(), url); | |
446 CheckTitle("no_listeners"); | |
447 EXPECT_EQ(1, browser()->tab_count()); | |
448 | |
449 TabContents* initial_tab = chrome::GetActiveTabContents(browser()); | |
450 EXPECT_EQ("", content::GetCookies(initial_tab->profile(), url)); | |
451 | |
452 ui_test_utils::NavigateToURLWithDisposition( | |
453 browser(), | |
454 test_server()->GetURL("files/fast_tab_close/unload_sets_cookie.html"), | |
455 NEW_FOREGROUND_TAB, | |
456 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
457 CheckTitle("unload_sets_cookie"); | |
458 | |
459 content::RenderViewHostImpl *second_tab_rvh = | |
460 static_cast<content::RenderViewHostImpl*>( | |
461 chrome::GetActiveWebContents(browser())->GetRenderViewHost()); | |
462 | |
463 { | |
464 base::RunLoop run_loop; | |
465 FastTabCloseTabStripModelObserver observer( | |
466 browser()->tab_strip_model(), &run_loop); | |
467 chrome::CloseTab(browser()); | |
468 run_loop.Run(); | |
469 } | |
470 | |
471 // Check that the browser only has the original tab. | |
472 CheckTitle("no_listeners"); | |
473 EXPECT_EQ(1, browser()->tab_count()); | |
474 | |
475 // Check that unload has started, but not finished. | |
476 // We cannot check the cookie here, because is spins the run-loop and | |
477 // finishes closing the tab. | |
478 ASSERT_TRUE(second_tab_rvh->is_waiting_for_unload_ack_for_testing()); | |
479 | |
480 // Wait for the web contents to go away. | |
481 content::WindowedNotificationObserver contents_destroyed_observer( | |
482 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
483 content::NotificationService::AllSources()); | |
484 contents_destroyed_observer.Wait(); | |
485 | |
486 // Check that the unload of the second tab set a cookie on the first. | |
487 EXPECT_EQ("unloaded=ohyeah", | |
488 content::GetCookies(initial_tab->profile(), url)); | |
489 | |
490 // Browser still has the same tab. | |
491 CheckTitle("no_listeners"); | |
492 EXPECT_EQ(1, browser()->tab_count()); | |
493 } | |
494 | |
412 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 495 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
413 // and multiple windows. | 496 // and multiple windows. |
OLD | NEW |