blob: 4fbaabd726abcaf580e593b4e6b6b2fdebe5db95 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2012 The Chromium Authors
[email protected]bb36d822011-09-30 20:55:092// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]7d855a12012-06-04 06:08:095#include "content/public/test/test_launcher.h"
[email protected]bb36d822011-09-30 20:55:096
[email protected]96f503fe2013-05-16 19:41:517#include "base/base_paths.h"
8#include "base/command_line.h"
[email protected]49f8a922014-06-11 14:35:579#include "base/i18n/icu_util.h"
[email protected]a88f6362014-03-18 04:25:3510#include "base/process/memory.h"
Sebastien Marchand75a7cdf2018-11-13 23:47:0311#include "base/system/sys_info.h"
Mostyn Bramley-Moored5588cf2017-07-01 12:57:1812#include "base/test/launcher/test_launcher.h"
[email protected]96f503fe2013-05-16 19:41:5113#include "base/test/test_suite.h"
[email protected]a88f6362014-03-18 04:25:3514#include "base/test/test_timeouts.h"
avi66a07722015-12-25 23:38:1215#include "build/build_config.h"
[email protected]96f503fe2013-05-16 19:41:5116#include "content/public/common/content_switches.h"
danakj1b980fd2021-01-21 14:59:1417#include "content/public/test/content_browser_test_shell_main_delegate.h"
[email protected]96f503fe2013-05-16 19:41:5118#include "content/public/test/content_test_suite_base.h"
[email protected]96f503fe2013-05-16 19:41:5119#include "content/shell/common/shell_switches.h"
[email protected]96f503fe2013-05-16 19:41:5120#include "testing/gtest/include/gtest/gtest.h"
Scott Violetb72577d2019-01-09 22:18:1821#include "ui/base/buildflags.h"
Sadrul Habib Chowdhuryeeb5a942017-11-28 21:17:2322#include "ui/base/ui_base_switches.h"
[email protected]96f503fe2013-05-16 19:41:5123
Xiaohan Wanga10d5bf2022-01-15 17:32:5424#if BUILDFLAG(IS_WIN)
Cliff Smolinskyf1006d0082019-06-03 19:12:4125#include "base/win/win_util.h"
Xiaohan Wanga10d5bf2022-01-15 17:32:5426#endif // BUILDFLAG(IS_WIN)
Cliff Smolinskyf1006d0082019-06-03 19:12:4127
[email protected]96f503fe2013-05-16 19:41:5128namespace content {
29
[email protected]96f503fe2013-05-16 19:41:5130class ContentBrowserTestSuite : public ContentTestSuiteBase {
31 public:
32 ContentBrowserTestSuite(int argc, char** argv)
33 : ContentTestSuiteBase(argc, argv) {
34 }
Peter Boström828b9022021-09-21 02:28:4335
36 ContentBrowserTestSuite(const ContentBrowserTestSuite&) = delete;
37 ContentBrowserTestSuite& operator=(const ContentBrowserTestSuite&) = delete;
38
dchenge933b3e2014-10-21 11:44:0939 ~ContentBrowserTestSuite() override {}
[email protected]96f503fe2013-05-16 19:41:5140
41 protected:
dchenge933b3e2014-10-21 11:44:0942 void Initialize() override {
Etienne Bergeron80a2bd32020-06-25 20:20:1443 // Browser tests are expected not to tear-down various globals.
Wez318901082018-08-24 23:57:4244 base::TestSuite::DisableCheckForLeakedGlobals();
45
[email protected]96f503fe2013-05-16 19:41:5146 ContentTestSuiteBase::Initialize();
[email protected]96f503fe2013-05-16 19:41:5147
Xiaohan Wanga10d5bf2022-01-15 17:32:5448#if BUILDFLAG(IS_ANDROID)
danakj4115ec732019-05-13 18:34:2249 RegisterInProcessThreads();
[email protected]a88f6362014-03-18 04:25:3550#endif
danakj4115ec732019-05-13 18:34:2251 }
[email protected]96f503fe2013-05-16 19:41:5152};
53
54class ContentTestLauncherDelegate : public TestLauncherDelegate {
55 public:
56 ContentTestLauncherDelegate() {}
Peter Boström828b9022021-09-21 02:28:4357
58 ContentTestLauncherDelegate(const ContentTestLauncherDelegate&) = delete;
59 ContentTestLauncherDelegate& operator=(const ContentTestLauncherDelegate&) =
60 delete;
61
dchenge933b3e2014-10-21 11:44:0962 ~ContentTestLauncherDelegate() override {}
[email protected]96f503fe2013-05-16 19:41:5163
dchenge933b3e2014-10-21 11:44:0964 int RunTestSuite(int argc, char** argv) override {
[email protected]96f503fe2013-05-16 19:41:5165 return ContentBrowserTestSuite(argc, argv).Run();
66 }
67
Scott Violeted612402020-01-23 23:55:1368 std::string GetUserDataDirectoryCommandLineSwitch() override {
69 return switches::kContentShellDataPath;
[email protected]96f503fe2013-05-16 19:41:5170 }
71
72 protected:
Xiaohan Wanga10d5bf2022-01-15 17:32:5473#if !BUILDFLAG(IS_ANDROID)
dchenge933b3e2014-10-21 11:44:0974 ContentMainDelegate* CreateContentMainDelegate() override {
danakj1b980fd2021-01-21 14:59:1475 return new ContentBrowserTestShellMainDelegate();
[email protected]96f503fe2013-05-16 19:41:5176 }
danakj6e6186d2019-05-10 21:37:1677#endif
[email protected]96f503fe2013-05-16 19:41:5178};
79
80} // namespace content
81
[email protected]bb36d822011-09-30 20:55:0982int main(int argc, char** argv) {
Mostyn Bramley-Moored5588cf2017-07-01 12:57:1883 base::CommandLine::Init(argc, argv);
Fergal Daly903473ed2020-07-02 04:04:4984 size_t parallel_jobs = base::NumParallelJobs(/*cores_per_job=*/2);
85 if (parallel_jobs == 0U)
86 return 1;
87
Xiaohan Wanga10d5bf2022-01-15 17:32:5488#if BUILDFLAG(IS_WIN)
Cliff Smolinskyf1006d0082019-06-03 19:12:4189 // Load and pin user32.dll to avoid having to load it once tests start while
90 // on the main thread loop where blocking calls are disallowed.
91 base::win::PinUser32();
Xiaohan Wanga10d5bf2022-01-15 17:32:5492#endif // BUILDFLAG(IS_WIN)
[email protected]bdcf9152012-07-19 17:43:2193 content::ContentTestLauncherDelegate launcher_delegate;
Mostyn Bramley-Moored5588cf2017-07-01 12:57:1894 return LaunchTests(&launcher_delegate, parallel_jobs, argc, argv);
[email protected]76df8e362011-09-30 21:23:5895}