15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/bind.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 87dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h" 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_finder.h" 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_iterator.h" 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/common/chrome_switches.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/browser_thread.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_service.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::BrowserThread; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class FastShutdown : public InProcessBrowserTest { 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FastShutdown() { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) command_line->AppendSwitch(switches::kDisablePopupBlocking); 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(FastShutdown); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This tests for a previous error where uninstalling an onbeforeunload handler 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// would enable fast shutdown even if an onunload handler still existed. 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Flaky on all platforms, http://crbug.com/89173 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if !defined(OS_CHROMEOS) // ChromeOS opens tabs instead of windows for popups. 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) { 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Need to run these tests on http:// since we only allow cookies on that (and 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // https obviously). 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This page has an unload handler. 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL url = test_server()->GetURL("files/fast_shutdown/on_unloader.html"); 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ("", content::GetCookies(browser()->profile(), url)); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::WindowedNotificationObserver window_observer( 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::NOTIFICATION_BROWSER_WINDOW_READY, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationService::AllSources()); 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) browser(), url, NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) window_observer.Wait(); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Close the new window, removing the one and only beforeunload handler. 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::BrowserIterator it; 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) it.Next(); 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) chrome::CloseWindow(*it); 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Need to wait for the renderer process to shutdown to ensure that we got the 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // set cookies IPC. 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::RenderProcessHostWatcher renderer_shutdown_observer( 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(), 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Close the tab. This should launch the unload handler, which sets a cookie 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that's stored to disk. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) chrome::CloseTab(browser()); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) renderer_shutdown_observer.Wait(); 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url)); 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 75