blob: b5dfb65f2685cd1b6d17f2b64c0a7c4634cf95d3 [file] [log] [blame]
[email protected]688530682012-04-06 20:33:271// 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
3// found in the LICENSE file.
4
5#include "base/bind.h"
6#include "base/command_line.h"
[email protected]57999812013-02-24 05:40:527#include "base/files/file_path.h"
avi6846aef2015-12-26 01:09:388#include "base/macros.h"
9#include "build/build_config.h"
[email protected]fdf40f3e2013-07-11 23:55:4610#include "chrome/browser/chrome_notification_types.h"
[email protected]688530682012-04-06 20:33:2711#include "chrome/browser/profiles/profile.h"
12#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1013#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1914#include "chrome/browser/ui/browser_finder.h"
scottmg8abbff832016-01-28 22:57:3715#include "chrome/browser/ui/browser_list.h"
[email protected]59253a652012-11-20 00:17:2616#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bc44f4142013-02-12 06:15:5617#include "chrome/common/chrome_switches.h"
[email protected]688530682012-04-06 20:33:2718#include "chrome/test/base/in_process_browser_test.h"
19#include "chrome/test/base/ui_test_utils.h"
20#include "content/public/browser/browser_thread.h"
21#include "content/public/browser/notification_service.h"
[email protected]88509ab2012-08-27 15:04:1422#include "content/public/test/browser_test_utils.h"
svaldeza01f7d92015-11-18 17:47:5623#include "net/test/embedded_test_server/embedded_test_server.h"
[email protected]688530682012-04-06 20:33:2724
25using content::BrowserThread;
26
[email protected]688530682012-04-06 20:33:2727class FastShutdown : public InProcessBrowserTest {
28 protected:
29 FastShutdown() {
30 }
31
avi556c05022014-12-22 23:31:4332 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]688530682012-04-06 20:33:2733 command_line->AppendSwitch(switches::kDisablePopupBlocking);
34 }
35
36 private:
37 DISALLOW_COPY_AND_ASSIGN(FastShutdown);
38};
39
40// This tests for a previous error where uninstalling an onbeforeunload handler
41// would enable fast shutdown even if an onunload handler still existed.
42// Flaky on all platforms, http://crbug.com/89173
43#if !defined(OS_CHROMEOS) // ChromeOS opens tabs instead of windows for popups.
[email protected]86984052012-10-31 01:38:3444IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) {
[email protected]688530682012-04-06 20:33:2745 // Need to run these tests on http:// since we only allow cookies on that (and
46 // https obviously).
svaldeza01f7d92015-11-18 17:47:5647 ASSERT_TRUE(embedded_test_server()->Start());
[email protected]688530682012-04-06 20:33:2748 // This page has an unload handler.
svaldeza01f7d92015-11-18 17:47:5649 GURL url = embedded_test_server()->GetURL("/fast_shutdown/on_unloader.html");
[email protected]1f2469a2012-12-13 21:19:5550 EXPECT_EQ("", content::GetCookies(browser()->profile(), url));
[email protected]688530682012-04-06 20:33:2751
[email protected]a7fe9112012-07-20 02:34:4552 content::WindowedNotificationObserver window_observer(
53 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
54 content::NotificationService::AllSources());
[email protected]688530682012-04-06 20:33:2755 ui_test_utils::NavigateToURLWithDisposition(
nick3b04f322016-08-31 19:29:1956 browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
57 ui_test_utils::BROWSER_TEST_NONE);
[email protected]688530682012-04-06 20:33:2758 window_observer.Wait();
59
60 // Close the new window, removing the one and only beforeunload handler.
[email protected]0665ebe2013-02-13 09:53:1961 ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
scottmg8abbff832016-01-28 22:57:3762 chrome::CloseWindow(*(BrowserList::GetInstance()->begin() + 1));
[email protected]688530682012-04-06 20:33:2763
64 // Need to wait for the renderer process to shutdown to ensure that we got the
65 // set cookies IPC.
[email protected]8ffad4e2014-01-02 23:18:2666 content::RenderProcessHostWatcher renderer_shutdown_observer(
67 browser()->tab_strip_model()->GetActiveWebContents(),
68 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
[email protected]688530682012-04-06 20:33:2769 // Close the tab. This should launch the unload handler, which sets a cookie
70 // that's stored to disk.
[email protected]a37d4b02012-06-25 21:56:1071 chrome::CloseTab(browser());
[email protected]688530682012-04-06 20:33:2772 renderer_shutdown_observer.Wait();
73
[email protected]1f2469a2012-12-13 21:19:5574 EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url));
[email protected]688530682012-04-06 20:33:2775}
76#endif