[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 1 | // 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] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 7 | #include "base/files/file_path.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 8 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 9 | #include "chrome/browser/profiles/profile.h" |
| 10 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 11 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 12 | #include "chrome/browser/ui/browser_finder.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_iterator.h" |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 14 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 15 | #include "chrome/common/chrome_switches.h" |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 16 | #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] | 88509ab | 2012-08-27 15:04:14 | [diff] [blame] | 20 | #include "content/public/test/browser_test_utils.h" |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 21 | |
| 22 | using content::BrowserThread; |
| 23 | |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 24 | class FastShutdown : public InProcessBrowserTest { |
| 25 | protected: |
| 26 | FastShutdown() { |
| 27 | } |
| 28 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 29 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 30 | 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] | 8698405 | 2012-10-31 01:38:34 | [diff] [blame] | 41 | IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) { |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 42 | // 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] | 1f2469a | 2012-12-13 21:19:55 | [diff] [blame] | 47 | EXPECT_EQ("", content::GetCookies(browser()->profile(), url)); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 48 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 49 | content::WindowedNotificationObserver window_observer( |
| 50 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 51 | content::NotificationService::AllSources()); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 52 | 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] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 57 | ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 58 | chrome::BrowserIterator it; |
| 59 | it.Next(); |
| 60 | chrome::CloseWindow(*it); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 61 | |
| 62 | // Need to wait for the renderer process to shutdown to ensure that we got the |
| 63 | // set cookies IPC. |
[email protected] | 8ffad4e | 2014-01-02 23:18:26 | [diff] [blame] | 64 | content::RenderProcessHostWatcher renderer_shutdown_observer( |
| 65 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 66 | content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 67 | // Close the tab. This should launch the unload handler, which sets a cookie |
| 68 | // that's stored to disk. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 69 | chrome::CloseTab(browser()); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 70 | renderer_shutdown_observer.Wait(); |
| 71 | |
[email protected] | 1f2469a | 2012-12-13 21:19:55 | [diff] [blame] | 72 | EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url)); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 73 | } |
| 74 | #endif |