blob: 14821a5fd1e243113ab3cd2149431e53f727da7f [file] [log] [blame]
Francois Doray6d3c649692017-06-16 19:20:251// 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 Charette44db1422018-08-06 11:19:3310#include "base/task/task_scheduler/task_scheduler.h"
Francois Doray6d3c649692017-06-16 19:20:2511#include "base/test/scoped_command_line.h"
Gabriel Charette8eb4dff2018-03-27 14:22:5412#include "content/browser/browser_thread_impl.h"
Alex Clarke7dc412d2018-09-14 10:02:3113#include "content/browser/scheduler/browser_task_executor.h"
Gabriel Charette790754c2018-03-16 21:32:5914#include "content/public/browser/browser_thread.h"
Francois Doray6d3c649692017-06-16 19:20:2515#include "content/public/common/content_switches.h"
16#include "content/public/common/main_function_params.h"
17#include "testing/gtest/include/gtest/gtest.h"
18
19namespace content {
20
21// Verify that a single-process browser process has at least as many threads as
22// the number of cores in its foreground pool.
23TEST(BrowserMainLoopTest, CreateThreadsInSingleProcess) {
24 {
Xi Hanf19a89e82018-06-14 13:26:3025 base::TaskScheduler::Create("Browser");
Alex Clarke7dc412d2018-09-14 10:02:3126 BrowserTaskExecutor::Create();
Francois Doray6d3c649692017-06-16 19:20:2527 base::test::ScopedCommandLine scoped_command_line;
28 scoped_command_line.GetProcessCommandLine()->AppendSwitch(
29 switches::kSingleProcess);
30 MainFunctionParams main_function_params(
31 *scoped_command_line.GetProcessCommandLine());
32 BrowserMainLoop browser_main_loop(main_function_params);
33 browser_main_loop.MainMessageLoopStart();
Xi Han4090dcc2018-07-11 03:15:2034 browser_main_loop.Init();
Francois Doray6d3c649692017-06-16 19:20:2535 browser_main_loop.CreateThreads();
36 EXPECT_GE(base::TaskScheduler::GetInstance()
Jeffrey Hed628419b2017-08-23 18:51:5137 ->GetMaxConcurrentNonBlockedTasksWithTraitsDeprecated(
Francois Doray6d3c649692017-06-16 19:20:2538 {base::TaskPriority::USER_VISIBLE}),
Gabriel Charettef61636f2018-02-05 17:50:1639 base::SysInfo::NumberOfProcessors() - 1);
Francois Doray6d3c649692017-06-16 19:20:2540 browser_main_loop.ShutdownThreadsAndCleanUp();
41 }
Eric Secklere105c2d2018-09-17 21:27:0742 BrowserTaskExecutor::ResetForTesting();
Scott Graham80cb2722017-08-31 02:12:4843 for (int id = BrowserThread::UI; id < BrowserThread::ID_COUNT; ++id) {
44 BrowserThreadImpl::ResetGlobalsForTesting(
45 static_cast<BrowserThread::ID>(id));
46 }
Francois Doray6d3c649692017-06-16 19:20:2547 base::TaskScheduler::GetInstance()->JoinForTesting();
48 base::TaskScheduler::SetInstance(nullptr);
49}
50
51} // namespace content