Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 1 | // Copyright 2017 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 | |
| 5 | #include "content/browser/browser_main_loop.h" |
| 6 | |
| 7 | #include "base/command_line.h" |
| 8 | #include "base/message_loop/message_loop.h" |
| 9 | #include "base/sys_info.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 10 | #include "base/task/task_scheduler/task_scheduler.h" |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 11 | #include "base/test/scoped_command_line.h" |
Gabriel Charette | 8eb4dff | 2018-03-27 14:22:54 | [diff] [blame] | 12 | #include "content/browser/browser_thread_impl.h" |
Alex Clarke | 7dc412d | 2018-09-14 10:02:31 | [diff] [blame] | 13 | #include "content/browser/scheduler/browser_task_executor.h" |
Xi Han | 8012e46 | 2018-10-05 19:52:30 | [diff] [blame] | 14 | #include "content/browser/startup_helper.h" |
Gabriel Charette | 790754c | 2018-03-16 21:32:59 | [diff] [blame] | 15 | #include "content/public/browser/browser_thread.h" |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 16 | #include "content/public/common/content_switches.h" |
| 17 | #include "content/public/common/main_function_params.h" |
| 18 | #include "testing/gtest/include/gtest/gtest.h" |
| 19 | |
| 20 | namespace content { |
| 21 | |
| 22 | // Verify that a single-process browser process has at least as many threads as |
| 23 | // the number of cores in its foreground pool. |
| 24 | TEST(BrowserMainLoopTest, CreateThreadsInSingleProcess) { |
| 25 | { |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 26 | base::test::ScopedCommandLine scoped_command_line; |
| 27 | scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 28 | switches::kSingleProcess); |
Xi Han | 8012e46 | 2018-10-05 19:52:30 | [diff] [blame] | 29 | base::TaskScheduler::Create("Browser"); |
| 30 | StartBrowserTaskScheduler(); |
| 31 | BrowserTaskExecutor::Create(); |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 32 | MainFunctionParams main_function_params( |
| 33 | *scoped_command_line.GetProcessCommandLine()); |
Xi Han | 8012e46 | 2018-10-05 19:52:30 | [diff] [blame] | 34 | BrowserMainLoop browser_main_loop( |
| 35 | main_function_params, |
| 36 | std::make_unique<base::TaskScheduler::ScopedExecutionFence>()); |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 37 | browser_main_loop.MainMessageLoopStart(); |
Xi Han | 4090dcc | 2018-07-11 03:15:20 | [diff] [blame] | 38 | browser_main_loop.Init(); |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 39 | browser_main_loop.CreateThreads(); |
| 40 | EXPECT_GE(base::TaskScheduler::GetInstance() |
Jeffrey He | d628419b | 2017-08-23 18:51:51 | [diff] [blame] | 41 | ->GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated( |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 42 | {base::TaskPriority::USER_VISIBLE}), |
Gabriel Charette | f61636f | 2018-02-05 17:50:16 | [diff] [blame] | 43 | base::SysInfo::NumberOfProcessors() - 1); |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 44 | browser_main_loop.ShutdownThreadsAndCleanUp(); |
| 45 | } |
Eric Seckler | e105c2d | 2018-09-17 21:27:07 | [diff] [blame] | 46 | BrowserTaskExecutor::ResetForTesting(); |
Scott Graham | 80cb272 | 2017-08-31 02:12:48 | [diff] [blame] | 47 | for (int id = BrowserThread::UI; id < BrowserThread::ID_COUNT; ++id) { |
| 48 | BrowserThreadImpl::ResetGlobalsForTesting( |
| 49 | static_cast<BrowserThread::ID>(id)); |
| 50 | } |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 51 | base::TaskScheduler::GetInstance()->JoinForTesting(); |
| 52 | base::TaskScheduler::SetInstance(nullptr); |
| 53 | } |
| 54 | |
| 55 | } // namespace content |