[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" |
avi | 6846aef | 2015-12-26 01:09:38 | [diff] [blame] | 8 | #include "base/macros.h" |
| 9 | #include "build/build_config.h" |
[email protected] | fdf40f3e | 2013-07-11 23:55:46 | [diff] [blame] | 10 | #include "chrome/browser/chrome_notification_types.h" |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile.h" |
| 12 | #include "chrome/browser/ui/browser.h" |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 13 | #include "chrome/browser/ui/browser_commands.h" |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 14 | #include "chrome/browser/ui/browser_finder.h" |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 15 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 59253a65 | 2012-11-20 00:17:26 | [diff] [blame] | 16 | #include "chrome/browser/ui/tabs/tab_strip_model.h" |
[email protected] | bc44f414 | 2013-02-12 06:15:56 | [diff] [blame] | 17 | #include "chrome/common/chrome_switches.h" |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 18 | #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] | 88509ab | 2012-08-27 15:04:14 | [diff] [blame] | 22 | #include "content/public/test/browser_test_utils.h" |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 23 | #include "net/test/embedded_test_server/embedded_test_server.h" |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 24 | |
| 25 | using content::BrowserThread; |
| 26 | |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 27 | class FastShutdown : public InProcessBrowserTest { |
| 28 | protected: |
| 29 | FastShutdown() { |
| 30 | } |
| 31 | |
avi | 556c0502 | 2014-12-22 23:31:43 | [diff] [blame] | 32 | void SetUpCommandLine(base::CommandLine* command_line) override { |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 33 | 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] | 8698405 | 2012-10-31 01:38:34 | [diff] [blame] | 44 | IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) { |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 45 | // Need to run these tests on http:// since we only allow cookies on that (and |
| 46 | // https obviously). |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 47 | ASSERT_TRUE(embedded_test_server()->Start()); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 48 | // This page has an unload handler. |
svaldez | a01f7d9 | 2015-11-18 17:47:56 | [diff] [blame] | 49 | GURL url = embedded_test_server()->GetURL("/fast_shutdown/on_unloader.html"); |
[email protected] | 1f2469a | 2012-12-13 21:19:55 | [diff] [blame] | 50 | EXPECT_EQ("", content::GetCookies(browser()->profile(), url)); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 51 | |
[email protected] | a7fe911 | 2012-07-20 02:34:45 | [diff] [blame] | 52 | content::WindowedNotificationObserver window_observer( |
| 53 | chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 54 | content::NotificationService::AllSources()); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 55 | ui_test_utils::NavigateToURLWithDisposition( |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 56 | browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 57 | ui_test_utils::BROWSER_TEST_NONE); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 58 | window_observer.Wait(); |
| 59 | |
| 60 | // Close the new window, removing the one and only beforeunload handler. |
[email protected] | 0665ebe | 2013-02-13 09:53:19 | [diff] [blame] | 61 | ASSERT_EQ(2u, chrome::GetTotalBrowserCount()); |
scottmg | 8abbff83 | 2016-01-28 22:57:37 | [diff] [blame] | 62 | chrome::CloseWindow(*(BrowserList::GetInstance()->begin() + 1)); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 63 | |
| 64 | // Need to wait for the renderer process to shutdown to ensure that we got the |
| 65 | // set cookies IPC. |
[email protected] | 8ffad4e | 2014-01-02 23:18:26 | [diff] [blame] | 66 | content::RenderProcessHostWatcher renderer_shutdown_observer( |
| 67 | browser()->tab_strip_model()->GetActiveWebContents(), |
| 68 | content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 69 | // Close the tab. This should launch the unload handler, which sets a cookie |
| 70 | // that's stored to disk. |
[email protected] | a37d4b0 | 2012-06-25 21:56:10 | [diff] [blame] | 71 | chrome::CloseTab(browser()); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 72 | renderer_shutdown_observer.Wait(); |
| 73 | |
[email protected] | 1f2469a | 2012-12-13 21:19:55 | [diff] [blame] | 74 | EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url)); |
[email protected] | 68853068 | 2012-04-06 20:33:27 | [diff] [blame] | 75 | } |
| 76 | #endif |