fast_shutdown_browsertest.cc 3.9 KB

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