Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame^] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 7d855a1 | 2012-06-04 06:08:09 | [diff] [blame] | 5 | #include "content/public/test/test_launcher.h" |
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 6 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 7 | #include "base/base_paths.h" |
8 | #include "base/command_line.h" | ||||
[email protected] | 49f8a92 | 2014-06-11 14:35:57 | [diff] [blame] | 9 | #include "base/i18n/icu_util.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 10 | #include "base/process/memory.h" |
Sebastien Marchand | 75a7cdf | 2018-11-13 23:47:03 | [diff] [blame] | 11 | #include "base/system/sys_info.h" |
Mostyn Bramley-Moore | d5588cf | 2017-07-01 12:57:18 | [diff] [blame] | 12 | #include "base/test/launcher/test_launcher.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 13 | #include "base/test/test_suite.h" |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 14 | #include "base/test/test_timeouts.h" |
avi | 66a0772 | 2015-12-25 23:38:12 | [diff] [blame] | 15 | #include "build/build_config.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 16 | #include "content/public/common/content_switches.h" |
danakj | 1b980fd | 2021-01-21 14:59:14 | [diff] [blame] | 17 | #include "content/public/test/content_browser_test_shell_main_delegate.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 18 | #include "content/public/test/content_test_suite_base.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 19 | #include "content/shell/common/shell_switches.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 20 | #include "testing/gtest/include/gtest/gtest.h" |
Scott Violet | b72577d | 2019-01-09 22:18:18 | [diff] [blame] | 21 | #include "ui/base/buildflags.h" |
Sadrul Habib Chowdhury | eeb5a94 | 2017-11-28 21:17:23 | [diff] [blame] | 22 | #include "ui/base/ui_base_switches.h" |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 23 | |
Xiaohan Wang | a10d5bf | 2022-01-15 17:32:54 | [diff] [blame] | 24 | #if BUILDFLAG(IS_WIN) |
Cliff Smolinsky | f1006d008 | 2019-06-03 19:12:41 | [diff] [blame] | 25 | #include "base/win/win_util.h" |
Xiaohan Wang | a10d5bf | 2022-01-15 17:32:54 | [diff] [blame] | 26 | #endif // BUILDFLAG(IS_WIN) |
Cliff Smolinsky | f1006d008 | 2019-06-03 19:12:41 | [diff] [blame] | 27 | |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 28 | namespace content { |
29 | |||||
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 30 | class ContentBrowserTestSuite : public ContentTestSuiteBase { |
31 | public: | ||||
32 | ContentBrowserTestSuite(int argc, char** argv) | ||||
33 | : ContentTestSuiteBase(argc, argv) { | ||||
34 | } | ||||
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 35 | |
36 | ContentBrowserTestSuite(const ContentBrowserTestSuite&) = delete; | ||||
37 | ContentBrowserTestSuite& operator=(const ContentBrowserTestSuite&) = delete; | ||||
38 | |||||
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 39 | ~ContentBrowserTestSuite() override {} |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 40 | |
41 | protected: | ||||
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 42 | void Initialize() override { |
Etienne Bergeron | 80a2bd3 | 2020-06-25 20:20:14 | [diff] [blame] | 43 | // Browser tests are expected not to tear-down various globals. |
Wez | 31890108 | 2018-08-24 23:57:42 | [diff] [blame] | 44 | base::TestSuite::DisableCheckForLeakedGlobals(); |
45 | |||||
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 46 | ContentTestSuiteBase::Initialize(); |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 47 | |
Xiaohan Wang | a10d5bf | 2022-01-15 17:32:54 | [diff] [blame] | 48 | #if BUILDFLAG(IS_ANDROID) |
danakj | 4115ec73 | 2019-05-13 18:34:22 | [diff] [blame] | 49 | RegisterInProcessThreads(); |
[email protected] | a88f636 | 2014-03-18 04:25:35 | [diff] [blame] | 50 | #endif |
danakj | 4115ec73 | 2019-05-13 18:34:22 | [diff] [blame] | 51 | } |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 52 | }; |
53 | |||||
54 | class ContentTestLauncherDelegate : public TestLauncherDelegate { | ||||
55 | public: | ||||
56 | ContentTestLauncherDelegate() {} | ||||
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 57 | |
58 | ContentTestLauncherDelegate(const ContentTestLauncherDelegate&) = delete; | ||||
59 | ContentTestLauncherDelegate& operator=(const ContentTestLauncherDelegate&) = | ||||
60 | delete; | ||||
61 | |||||
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 62 | ~ContentTestLauncherDelegate() override {} |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 63 | |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 64 | int RunTestSuite(int argc, char** argv) override { |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 65 | return ContentBrowserTestSuite(argc, argv).Run(); |
66 | } | ||||
67 | |||||
Scott Violet | ed61240 | 2020-01-23 23:55:13 | [diff] [blame] | 68 | std::string GetUserDataDirectoryCommandLineSwitch() override { |
69 | return switches::kContentShellDataPath; | ||||
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 70 | } |
71 | |||||
72 | protected: | ||||
Xiaohan Wang | a10d5bf | 2022-01-15 17:32:54 | [diff] [blame] | 73 | #if !BUILDFLAG(IS_ANDROID) |
dcheng | e933b3e | 2014-10-21 11:44:09 | [diff] [blame] | 74 | ContentMainDelegate* CreateContentMainDelegate() override { |
danakj | 1b980fd | 2021-01-21 14:59:14 | [diff] [blame] | 75 | return new ContentBrowserTestShellMainDelegate(); |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 76 | } |
danakj | 6e6186d | 2019-05-10 21:37:16 | [diff] [blame] | 77 | #endif |
[email protected] | 96f503fe | 2013-05-16 19:41:51 | [diff] [blame] | 78 | }; |
79 | |||||
80 | } // namespace content | ||||
81 | |||||
[email protected] | bb36d82 | 2011-09-30 20:55:09 | [diff] [blame] | 82 | int main(int argc, char** argv) { |
Mostyn Bramley-Moore | d5588cf | 2017-07-01 12:57:18 | [diff] [blame] | 83 | base::CommandLine::Init(argc, argv); |
Fergal Daly | 903473ed | 2020-07-02 04:04:49 | [diff] [blame] | 84 | size_t parallel_jobs = base::NumParallelJobs(/*cores_per_job=*/2); |
85 | if (parallel_jobs == 0U) | ||||
86 | return 1; | ||||
87 | |||||
Xiaohan Wang | a10d5bf | 2022-01-15 17:32:54 | [diff] [blame] | 88 | #if BUILDFLAG(IS_WIN) |
Cliff Smolinsky | f1006d008 | 2019-06-03 19:12:41 | [diff] [blame] | 89 | // 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 Wang | a10d5bf | 2022-01-15 17:32:54 | [diff] [blame] | 92 | #endif // BUILDFLAG(IS_WIN) |
[email protected] | bdcf915 | 2012-07-19 17:43:21 | [diff] [blame] | 93 | content::ContentTestLauncherDelegate launcher_delegate; |
Mostyn Bramley-Moore | d5588cf | 2017-07-01 12:57:18 | [diff] [blame] | 94 | return LaunchTests(&launcher_delegate, parallel_jobs, argc, argv); |
[email protected] | 76df8e36 | 2011-09-30 21:23:58 | [diff] [blame] | 95 | } |