[M120][Tizen][Onscreen] Fix build errors for TV profile
[platform/framework/web/chromium-efl.git] / chrome / browser / fast_shutdown_browsertest.cc
1 // Copyright 2011 The Chromium Authors
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/command_line.h"
6 #include "base/files/file_path.h"
7 #include "base/functional/bind.h"
8 #include "build/build_config.h"
9 #include "build/chromeos_buildflags.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_commands.h"
13 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/browser_list.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "components/embedder_support/switches.h"
19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/render_process_host.h"
21 #include "content/public/test/browser_test.h"
22 #include "content/public/test/browser_test_utils.h"
23 #include "net/test/embedded_test_server/embedded_test_server.h"
24
25 using content::BrowserThread;
26
27 class FastShutdown : public InProcessBrowserTest {
28  public:
29   FastShutdown(const FastShutdown&) = delete;
30   FastShutdown& operator=(const FastShutdown&) = delete;
31
32  protected:
33   FastShutdown() {
34   }
35
36   void SetUpCommandLine(base::CommandLine* command_line) override {
37     command_line->AppendSwitch(embedder_support::kDisablePopupBlocking);
38   }
39 };
40
41 // This tests for a previous error where uninstalling an onbeforeunload handler
42 // would enable fast shutdown even if an onunload handler still existed.
43 // Flaky on all platforms, http://crbug.com/89173
44 #if !BUILDFLAG( \
45     IS_CHROMEOS_ASH)  // ChromeOS opens tabs instead of windows for popups.
46 IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) {
47   // Need to run these tests on http:// since we only allow cookies on that (and
48   // https obviously).
49   ASSERT_TRUE(embedded_test_server()->Start());
50   // This page has an unload handler.
51   GURL url = embedded_test_server()->GetURL("/fast_shutdown/on_unloader.html");
52   EXPECT_EQ("", content::GetCookies(browser()->profile(), url));
53
54   ui_test_utils::NavigateToURLWithDisposition(
55       browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
56       ui_test_utils::BROWSER_TEST_NO_WAIT);
57   ui_test_utils::WaitForBrowserToOpen();
58
59   // Close the new window, removing the one and only beforeunload handler.
60   ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
61   chrome::CloseWindow(*(BrowserList::GetInstance()->begin() + 1));
62
63   // Need to wait for the renderer process to shutdown to ensure that we got the
64   // set cookies IPC.
65   content::RenderProcessHostWatcher renderer_shutdown_observer(
66       browser()->tab_strip_model()->GetActiveWebContents(),
67       content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
68   // Close the tab. This should launch the unload handler, which sets a cookie
69   // that's stored to disk.
70   chrome::CloseTab(browser());
71   renderer_shutdown_observer.Wait();
72
73   EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url));
74 }
75 #endif
76
77 // Verifies that the spare renderer maintained by SpareRenderProcessHostManager
78 // is correctly destroyed during browser shutdown.
79 //
80 // Prior to the CL that introduced the test below, there were some problems
81 // encountered during the shutdown sequence specific to the //chrome layer.
82 // Therefore, it is important that the test below is a //chrome-level test, even
83 // though the test doesn't have any explicit dependencies on the //chrome layer.
84 IN_PROC_BROWSER_TEST_F(FastShutdown, SpareRenderProcessHostDuringShutdown) {
85   content::RenderProcessHost::WarmupSpareRenderProcessHost(
86       browser()->profile());
87
88   // The verification is that there are no DCHECKs anywhere during test tear
89   // down (in particular that no DCHECKs are hit inside
90   // ProfileDestroyer::DestroyProfileWhenAppropriate when it tries to make sure
91   // that no renderers associated with the given Profile are still alive).
92 }