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

Unified Diff: chrome/browser/unload_browsertest.cc

Issue 11016023: Quickly close tabs/window with long-running unload handlers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make UnloadDetachedHandler a delegate for all detached tabs. Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/unload_browsertest.cc
diff --git a/chrome/browser/unload_browsertest.cc b/chrome/browser/unload_browsertest.cc
index 0b98a0024cc6380151b30b4d20c6726b84502183..bc1dd2609a65ab1af6d67a47b3a8248d7637abfa 100644
--- a/chrome/browser/unload_browsertest.cc
+++ b/chrome/browser/unload_browsertest.cc
@@ -11,12 +11,15 @@
#include "base/process_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/net/url_request_mock_util.h"
+#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_modal_dialogs/javascript_app_modal_dialog.h"
#include "chrome/browser/ui/app_modal_dialogs/native_app_modal_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/tab_contents/tab_contents.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
@@ -410,5 +413,143 @@ IN_PROC_BROWSER_TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) {
CheckTitle("only_one_unload");
}
+
+class FastUnloadTest : public UnloadTest {
+ public:
+ virtual void SetUpInProcessBrowserTestFixture() {
+ ASSERT_TRUE(test_server()->Start());
+ }
+
+ virtual void TearDownInProcessBrowserTestFixture() {
+ test_server()->Stop();
+ }
+
+ GURL GetUrl(const std::string& name) {
+ return GURL(test_server()->GetURL(
+ "files/fast_tab_close/" + name + ".html"));
+ }
+
+ void NavigateToPage(const char* name) {
+ ui_test_utils::NavigateToURL(browser(), GetUrl(name));
+ CheckTitle(name);
+ }
+
+ void NavigateToPageInNewTab(const char* name) {
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), GetUrl(name), NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ CheckTitle(name);
+ }
+
+ std::string GetActiveTabCookies(const char* name) {
+ TabContents* tab = chrome::GetActiveTabContents(browser());
+ return content::GetCookies(tab->profile(), GetUrl(name));
+ }
+};
+
+class FastTabCloseTabStripModelObserver : public TabStripModelObserver {
+ public:
+ FastTabCloseTabStripModelObserver(TabStripModel* model,
+ base::RunLoop* run_loop)
+ : model_(model),
+ run_loop_(run_loop) {
+ model_->AddObserver(this);
+ }
+
+ ~FastTabCloseTabStripModelObserver() {
+ model_->RemoveObserver(this);
+ }
+
+ // TabStripModelObserver:
+ virtual void TabDetachedAt(TabContents* contents, int index) {
+ run_loop_->Quit();
+ }
+
+ private:
+ TabStripModel* const model_;
+ base::RunLoop* const run_loop_;
+};
+
+
+// Test that fast-tab-close works when closing a tab (not the last one) with
+// an unload handler (http://crbug.com/142458).
+IN_PROC_BROWSER_TEST_F(FastUnloadTest, UnloadHidden) {
+ NavigateToPage("no_listeners");
+ NavigateToPageInNewTab("unload_sets_cookie");
+ EXPECT_EQ("", GetActiveTabCookies("no_listeners"));
+
+ {
+ base::RunLoop run_loop;
+ FastTabCloseTabStripModelObserver observer(
+ browser()->tab_strip_model(), &run_loop);
+ chrome::CloseTab(browser());
+ run_loop.Run();
+ }
+
+ // Check that the browser only has the original tab.
+ CheckTitle("no_listeners");
+ EXPECT_EQ(1, browser()->tab_count());
+
+ // Show that the web contents to go away after the was removed.
+ // Without unload-detached, this times-out because it happens earlier.
+ content::WindowedNotificationObserver contents_destroyed_observer(
+ content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
+ content::NotificationService::AllSources());
+ contents_destroyed_observer.Wait();
+
+ // Browser still has the same tab.
+ CheckTitle("no_listeners");
+ EXPECT_EQ(1, browser()->tab_count());
+ EXPECT_EQ("unloaded=ohyeah", GetActiveTabCookies("no_listeners"));
+}
+
+// Test that fast-tab-close does not break a solo tab.
+// Fast window close feature request: http://crbug.com/156896
+IN_PROC_BROWSER_TEST_F(FastUnloadTest, PRE_ClosingLastTabFinishesUnload) {
+ // The unload handler sleeps before setting the cookie to catch cases when
+ // unload handlers are not allowed to run to completion. (For example,
+ // using the detached handler for the tab and then closing the browser.)
+ NavigateToPage("unload_sleep_before_cookie");
+ EXPECT_EQ(1, browser()->tab_count());
+ EXPECT_EQ("", GetActiveTabCookies("unload_sleep_before_cookie"));
+
+ content::WindowedNotificationObserver window_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::NotificationService::AllSources());
+ chrome::CloseTab(browser());
+ window_observer.Wait();
+}
+IN_PROC_BROWSER_TEST_F(FastUnloadTest, ClosingLastTabFinishesUnload) {
+ // Check for cookie set in unload handler of PRE_ test.
+ NavigateToPage("no_listeners");
+ EXPECT_EQ("unloaded=ohyeah", GetActiveTabCookies("no_listeners"));
+}
+
+// Test that fast-tab-close does not break window close.
+// Fast window close feature request: http://crbug.com/156896
+IN_PROC_BROWSER_TEST_F(FastUnloadTest, PRE_WindowCloseFinishesUnload) {
+ NavigateToPage("no_listeners");
+
+ // The unload handler sleeps before setting the cookie to catch cases when
+ // unload handlers are not allowed to run to completion. Without the sleep,
+ // the cookie can get set even if the browser does not wait for
+ // the unload handler to finish.
+ NavigateToPageInNewTab("unload_sleep_before_cookie");
+ EXPECT_EQ(2, browser()->tab_count());
+ EXPECT_EQ("", GetActiveTabCookies("no_listeners"));
+
+ content::WindowedNotificationObserver window_observer(
+ chrome::NOTIFICATION_BROWSER_CLOSED,
+ content::NotificationService::AllSources());
+ chrome::CloseWindow(browser());
+ window_observer.Wait();
+}
+IN_PROC_BROWSER_TEST_F(FastUnloadTest, WindowCloseFinishesUnload) {
+ // Check for cookie set in unload during PRE_ test.
+ NavigateToPage("no_listeners");
+ EXPECT_EQ("unloaded=ohyeah", GetActiveTabCookies("no_listeners"));
+}
+
+
// TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
// and multiple windows.

Powered by Google App Engine
This is Rietveld 408576698