blob: 33481c37a53ecd90f879f3c70806c55e0746f8d6 [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"
[email protected]fdf40f3e2013-07-11 23:55:468#include "chrome/browser/chrome_notification_types.h"
[email protected]688530682012-04-06 20:33:279#include "chrome/browser/profiles/profile.h"
10#include "chrome/browser/ui/browser.h"
[email protected]a37d4b02012-06-25 21:56:1011#include "chrome/browser/ui/browser_commands.h"
[email protected]0665ebe2013-02-13 09:53:1912#include "chrome/browser/ui/browser_finder.h"
[email protected]bc44f4142013-02-12 06:15:5613#include "chrome/browser/ui/browser_iterator.h"
[email protected]59253a652012-11-20 00:17:2614#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]bc44f4142013-02-12 06:15:5615#include "chrome/common/chrome_switches.h"
[email protected]688530682012-04-06 20:33:2716#include "chrome/test/base/in_process_browser_test.h"
17#include "chrome/test/base/ui_test_utils.h"
18#include "content/public/browser/browser_thread.h"
19#include "content/public/browser/notification_service.h"
[email protected]88509ab2012-08-27 15:04:1420#include "content/public/test/browser_test_utils.h"
[email protected]688530682012-04-06 20:33:2721
22using content::BrowserThread;
23
[email protected]688530682012-04-06 20:33:2724class FastShutdown : public InProcessBrowserTest {
25 protected:
26 FastShutdown() {
27 }
28
avi556c05022014-12-22 23:31:4329 void SetUpCommandLine(base::CommandLine* command_line) override {
[email protected]688530682012-04-06 20:33:2730 command_line->AppendSwitch(switches::kDisablePopupBlocking);
31 }
32
33 private:
34 DISALLOW_COPY_AND_ASSIGN(FastShutdown);
35};
36
37// This tests for a previous error where uninstalling an onbeforeunload handler
38// would enable fast shutdown even if an onunload handler still existed.
39// Flaky on all platforms, http://crbug.com/89173
40#if !defined(OS_CHROMEOS) // ChromeOS opens tabs instead of windows for popups.
[email protected]86984052012-10-31 01:38:3441IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) {
[email protected]688530682012-04-06 20:33:2742 // Need to run these tests on http:// since we only allow cookies on that (and
43 // https obviously).
44 ASSERT_TRUE(test_server()->Start());
45 // This page has an unload handler.
46 GURL url = test_server()->GetURL("files/fast_shutdown/on_unloader.html");
[email protected]1f2469a2012-12-13 21:19:5547 EXPECT_EQ("", content::GetCookies(browser()->profile(), url));
[email protected]688530682012-04-06 20:33:2748
[email protected]a7fe9112012-07-20 02:34:4549 content::WindowedNotificationObserver window_observer(
50 chrome::NOTIFICATION_BROWSER_WINDOW_READY,
51 content::NotificationService::AllSources());
[email protected]688530682012-04-06 20:33:2752 ui_test_utils::NavigateToURLWithDisposition(
53 browser(), url, NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_NONE);
54 window_observer.Wait();
55
56 // Close the new window, removing the one and only beforeunload handler.
[email protected]0665ebe2013-02-13 09:53:1957 ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
[email protected]bc44f4142013-02-12 06:15:5658 chrome::BrowserIterator it;
59 it.Next();
60 chrome::CloseWindow(*it);
[email protected]688530682012-04-06 20:33:2761
62 // Need to wait for the renderer process to shutdown to ensure that we got the
63 // set cookies IPC.
[email protected]8ffad4e2014-01-02 23:18:2664 content::RenderProcessHostWatcher renderer_shutdown_observer(
65 browser()->tab_strip_model()->GetActiveWebContents(),
66 content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
[email protected]688530682012-04-06 20:33:2767 // Close the tab. This should launch the unload handler, which sets a cookie
68 // that's stored to disk.
[email protected]a37d4b02012-06-25 21:56:1069 chrome::CloseTab(browser());
[email protected]688530682012-04-06 20:33:2770 renderer_shutdown_observer.Wait();
71
[email protected]1f2469a2012-12-13 21:19:5572 EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url));
[email protected]688530682012-04-06 20:33:2773}
74#endif