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" |
| 10 | #include "base/task_scheduler/task_scheduler.h" |
| 11 | #include "base/test/scoped_command_line.h" |
| 12 | #include "content/public/common/content_switches.h" |
| 13 | #include "content/public/common/main_function_params.h" |
| 14 | #include "testing/gtest/include/gtest/gtest.h" |
| 15 | |
| 16 | namespace content { |
| 17 | |
| 18 | // Verify that a single-process browser process has at least as many threads as |
| 19 | // the number of cores in its foreground pool. |
| 20 | TEST(BrowserMainLoopTest, CreateThreadsInSingleProcess) { |
| 21 | { |
| 22 | base::MessageLoop message_loop; |
| 23 | base::test::ScopedCommandLine scoped_command_line; |
| 24 | scoped_command_line.GetProcessCommandLine()->AppendSwitch( |
| 25 | switches::kSingleProcess); |
| 26 | MainFunctionParams main_function_params( |
| 27 | *scoped_command_line.GetProcessCommandLine()); |
| 28 | BrowserMainLoop browser_main_loop(main_function_params); |
| 29 | browser_main_loop.MainMessageLoopStart(); |
| 30 | browser_main_loop.CreateThreads(); |
| 31 | EXPECT_GE(base::TaskScheduler::GetInstance() |
Jeffrey He | d628419b | 2017-08-23 18:51:51 | [diff] [blame] | 32 | ->GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated( |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 33 | {base::TaskPriority::USER_VISIBLE}), |
Gabriel Charette | f61636f | 2018-02-05 17:50:16 | [diff] [blame^] | 34 | base::SysInfo::NumberOfProcessors() - 1); |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 35 | browser_main_loop.ShutdownThreadsAndCleanUp(); |
| 36 | } |
Scott Graham | 80cb272 | 2017-08-31 02:12:48 | [diff] [blame] | 37 | for (int id = BrowserThread::UI; id < BrowserThread::ID_COUNT; ++id) { |
| 38 | BrowserThreadImpl::ResetGlobalsForTesting( |
| 39 | static_cast<BrowserThread::ID>(id)); |
| 40 | } |
Francois Doray | 6d3c64969 | 2017-06-16 19:20:25 | [diff] [blame] | 41 | base::TaskScheduler::GetInstance()->JoinForTesting(); |
| 42 | base::TaskScheduler::SetInstance(nullptr); |
| 43 | } |
| 44 | |
| 45 | } // namespace content |