File: fast_shutdown_browsertest.cc

package info (click to toggle)
chromium 138.0.7204.157-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,071,864 kB
  • sloc: cpp: 34,936,859; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,967; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 3,967 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/embedder_support/switches.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/spare_render_process_host_manager.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/embedded_test_server/embedded_test_server.h"

using content::BrowserThread;

class FastShutdown : public InProcessBrowserTest {
 public:
  FastShutdown(const FastShutdown&) = delete;
  FastShutdown& operator=(const FastShutdown&) = delete;

 protected:
  FastShutdown() = default;

  void SetUpCommandLine(base::CommandLine* command_line) override {
    command_line->AppendSwitch(embedder_support::kDisablePopupBlocking);
  }
};

// This tests for a previous error where uninstalling an onbeforeunload handler
// would enable fast shutdown even if an onunload handler still existed.
// Flaky on all platforms, http://crbug.com/89173
// ChromeOS opens tabs instead of windows for popups.
#if !BUILDFLAG(IS_CHROMEOS)
IN_PROC_BROWSER_TEST_F(FastShutdown, DISABLED_SlowTermination) {
  // Need to run these tests on http:// since we only allow cookies on that (and
  // https obviously).
  ASSERT_TRUE(embedded_test_server()->Start());
  // This page has an unload handler.
  GURL url = embedded_test_server()->GetURL("/fast_shutdown/on_unloader.html");
  EXPECT_EQ("", content::GetCookies(browser()->profile(), url));

  ui_test_utils::NavigateToURLWithDisposition(
      browser(), url, WindowOpenDisposition::NEW_FOREGROUND_TAB,
      ui_test_utils::BROWSER_TEST_NO_WAIT);
  ui_test_utils::WaitForBrowserToOpen();

  // Close the new window, removing the one and only beforeunload handler.
  ASSERT_EQ(2u, chrome::GetTotalBrowserCount());
  chrome::CloseWindow(*(BrowserList::GetInstance()->begin() + 1));

  // Need to wait for the renderer process to shutdown to ensure that we got the
  // set cookies IPC.
  content::RenderProcessHostWatcher renderer_shutdown_observer(
      browser()->tab_strip_model()->GetActiveWebContents(),
      content::RenderProcessHostWatcher::WATCH_FOR_HOST_DESTRUCTION);
  // Close the tab. This should launch the unload handler, which sets a cookie
  // that's stored to disk.
  chrome::CloseTab(browser());
  renderer_shutdown_observer.Wait();

  EXPECT_EQ("unloaded=ohyeah", content::GetCookies(browser()->profile(), url));
}
#endif

// Verifies that the spare renderer maintained by SpareRenderProcessHostManager
// is correctly destroyed during browser shutdown.
//
// Prior to the CL that introduced the test below, there were some problems
// encountered during the shutdown sequence specific to the //chrome layer.
// Therefore, it is important that the test below is a //chrome-level test, even
// though the test doesn't have any explicit dependencies on the //chrome layer.
IN_PROC_BROWSER_TEST_F(FastShutdown, SpareRenderProcessHostDuringShutdown) {
  content::SpareRenderProcessHostManager::Get().WarmupSpare(
      browser()->profile());

  // The verification is that there are no DCHECKs anywhere during test tear
  // down (in particular that no DCHECKs are hit inside
  // ProfileDestroyer::DestroyProfileWhenAppropriate when it tries to make sure
  // that no renderers associated with the given Profile are still alive).
}